Skip to content

Commit

Permalink
[PLAT-15132][PLAT-15153] Allow users to configure logging level for Y…
Browse files Browse the repository at this point in the history
…NP, also minor bug fixes

Summary:
Allow users to configure logging level for YNP
Minor bug fixes

Test Plan:
Provisioned node via YNP.
Verified universe deployment

Reviewers: anijhawan, nbhatia

Reviewed By: anijhawan

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37754
  • Loading branch information
Vars-07 committed Sep 4, 2024
1 parent 142c04a commit 315110f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
5 changes: 5 additions & 0 deletions managed/node-agent/resources/node-agent-provision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ yba:
volume_size: size
mount_points:
- /mnt/d1

logging:
level: INFO
directory: ./logs
file: app.log
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def _build_script(self, all_templates, phase):
with tempfile.NamedTemporaryFile(mode="w+", delete=False) as temp_file:
temp_file.write("#!/bin/bash\n\n")
temp_file.write("set -e\n")
key = next(iter(self.config), None)
if key is not None:
context = self.config[key]
loglevel = context.get('loglevel')
if loglevel == "DEBUG":
temp_file.write("set -x\n")
self.add_results_helper(temp_file)
self.populate_sudo_check(temp_file)
for key in all_templates:
Expand Down
6 changes: 4 additions & 2 deletions managed/node-agent/resources/ynp/configs/config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

[DEFAULT]
version = 1.0.0
loglevel = DEBUG
logfile = app.log
# Keep this as debug level for printing the shell file output.
loglevel = {{ logging.level }}
logdir = {{ logging.directory }}
logfile = {{ logging.file }}
is_airgap = {{ ynp.is_airgap }}
ynp_dir = {{ ynp_dir }}
execution_start_time = {{ start_time }}
Expand Down
9 changes: 8 additions & 1 deletion managed/node-agent/resources/ynp/configs/setup_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import os


def setup_logger(log_dir, log_file):
def setup_logger(config):
key = next(iter(config), None)
log_file = "app.log"
log_dir = "./logs"
if key is not None:
context = config[key]
log_file = context.get('logfile')
log_dir = context.get("logdir")

# Create log directory if it doesn't exist
# Ensure the log directory has the correct permissions (755)
Expand Down
11 changes: 5 additions & 6 deletions managed/node-agent/resources/ynp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def get_absolute_path(relative_path):
def parse_arguments():
parser = argparse.ArgumentParser(description="YNP: Yugabyte Node Provisioning Tool")
parser.add_argument('--command', default="provision", required=False, help='Command to execute')
parser.add_argument('--logging_dir', default="./logs", help='Logging directory')
parser.add_argument('--log_file', default="ynp.log", help='Log file name')
parser.add_argument('--config_file', default="./node-agent-provision.yaml",
help='Path to the ynp configuration file')
parser.add_argument('--preflight_check', action="store_true",
Expand All @@ -37,15 +35,16 @@ def log_installed_packages(logger):

def main():
args = parse_arguments()
setup_logger.setup_logger(args.logging_dir, args.log_file)
logger = logging.getLogger(__name__)

try:
with open(get_absolute_path(args.config_file)) as f:
ynp_config = yaml.safe_load(f)
except Exception as e:
logger.error("Parsing YAML failed with ", e)
print("Parsing YAML failed with ", e)
raise
conf = parse_config(ynp_config)
setup_logger.setup_logger(conf)

logger = logging.getLogger(__name__)
logger.debug("YNP config %s" % pprint.pformat(ynp_config))

conf = parse_config(ynp_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ for mount_point in "${mount_point_array[@]}"; do
add_result "$mount_point Free space check" "$result" "$message"
done

# Check if selinux module can be imported
python3 -c "import selinux" 2>/dev/null
if [ $? -eq 0 ]; then
echo "libselinux bindings are correctly working for the system's default Python."
add_result "python libselinux check" "PASS" ""
else
echo "libselinux bindings are NOT installed or working for the system's default Python."
add_result "python libselinux check" "FAIL" "cannot import selinux in system python3"
platform_id=$(grep -oP '(?<=^PLATFORM_ID=).+' /etc/os-release | tr -d '"')
if [[ "$platform_id" == "platform:el8" ]]; then
# Check if selinux module can be imported
python3 -c "import selinux" 2>/dev/null
if [ $? -eq 0 ]; then
echo "libselinux bindings are correctly working for the system's default Python."
add_result "python libselinux check" "PASS" ""
else
echo "libselinux bindings are NOT installed or working for the system's default Python."
add_result "python libselinux check" "FAIL" "cannot import selinux in system python3"
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ else
fi

# Set ownership and permissions
chown -R prometheus:prometheus /opt/prometheus
chown -R prometheus:prometheus /etc/prometheus
chown -R prometheus:prometheus /var/log/prometheus
chown -R prometheus:prometheus /var/run/prometheus
chown -R prometheus:{{ yb_user }} /opt/prometheus
chown -R prometheus:{{ yb_user }} /etc/prometheus
chown -R prometheus:{{ yb_user }} /var/log/prometheus
chown -R prometheus:{{ yb_user }} /var/run/prometheus
chown -R yugabyte:yugabyte /tmp/yugabyte/metrics
chmod -R 755 /tmp/yugabyte/metrics

Expand Down Expand Up @@ -64,7 +64,7 @@ Type=simple
Restart=on-failure

User=prometheus
Group=prometheus
Group={{ yb_user }}

ExecStart=/opt/prometheus/node_exporter-1.7.0.linux-amd64/node_exporter \
--web.listen-address=:9300 \
Expand Down

0 comments on commit 315110f

Please sign in to comment.