Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture all logs #17

Merged
merged 4 commits into from
Mar 8, 2024
Merged

Capture all logs #17

merged 4 commits into from
Mar 8, 2024

Conversation

efrecon
Copy link
Owner

@efrecon efrecon commented Mar 8, 2024

Rewire the logs from the sub-processes of runner.sh through its logging mechanism. This provides more information about the underlying podman daemon and might help for debugging.

Close #15

Summary by CodeRabbit

  • New Features
    • Enhanced container configuration options including network settings, logging, mounts, and runtime settings.
    • Introduced new logging functionalities and environment variables for better operational management.
    • Added a sublog function for improved log file handling and content routing.
  • Refactor
    • Updated the runner script for enhanced logging, including Docker and Podman operations, and introduced a dedicated directory for runner logs.

@efrecon efrecon self-assigned this Mar 8, 2024
Copy link
Contributor

coderabbitai bot commented Mar 8, 2024

Walkthrough

The recent updates enhance logging and configuration capabilities for container management tools, focusing on capturing all logs to facilitate debugging. These changes span across configuration files and scripts, introducing new logging functions, environment variables, and adjustments to logging processes and permissions, ensuring comprehensive logging coverage for background services like Podman.

Changes

Files Change Summary
.../containers/containers.conf Updated configurations for container engines, including annotations, cgroups, DNS, and more.
lib/common.sh Added sublog() for routing log file content.
runner/runner.sh Enhanced logging with new variables, functions, permissions, and adjustments for Docker/Podman.

Assessment against linked issues

Objective Addressed Explanation
Capture all logs (#15)

The code changes effectively address the objective of capturing all logs for background services like Podman, as outlined in issue #15. By enhancing logging functions, introducing new environment variables for configuration, and making adjustments to the logging process and permissions, the updates ensure that logs from various services can be captured and routed effectively, aiding in debugging processes.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between be55cdf and 545216b.
Files selected for processing (3)
  • base/root/etc/containers/containers.conf (1 hunks)
  • lib/common.sh (1 hunks)
  • runner/runner.sh (8 hunks)
Additional comments: 4
runner/runner.sh (2)
  • 95-102: The introduction of RUNNER_CONTAINERS_CONFDIR and RUNNER_LOGDIR as environment variables is a positive change for configurability and flexibility. However, consider the following:
  • Best Practices: Ensure that the default values for these directories ("/etc/containers" and "/var/log/runner") are appropriate for all deployment environments. It might be beneficial to document these defaults and their intended use cases.
  • Security: When creating directories or files, especially in global locations like /var/log, ensure that permissions are set correctly to prevent unauthorized access. The script should explicitly set permissions for RUNNER_LOGDIR after its creation.

Overall, these changes are a step in the right direction for enhancing the script's configurability and logging capabilities.

  • 284-298: The runner_log function is a significant addition for managing logging more effectively. It redirects the output of a command to a log file and simultaneously uses the sublog function for formatted logging. Here are some considerations:
  • Correctness: The function correctly handles background execution and PID tracking for both the main program and the sublog process. This is crucial for clean termination and avoiding orphaned processes.
  • Performance: Consider the implications of logging every output of the main program. For verbose or high-output commands, this could lead to performance issues or disk space concerns. Implementing log rotation or size limits might be necessary.
  • Maintainability: The function is well-structured and uses clear variable names. Adding comments to explain the purpose of each step and the expected format of the SUBLOG_NAME parameter would enhance maintainability.

This function is a valuable addition to the script, improving the logging mechanism's flexibility and robustness.

base/root/etc/containers/containers.conf (2)
  • 78-80: The addition of default_sysctls with net.ipv4.ping_group_range=0 0 is a useful configuration for allowing containers to adjust kernel parameters. However, it's important to ensure this change does not inadvertently introduce security vulnerabilities or conflict with other system settings.
  • Please verify the impact of this sysctl setting on system security and stability.
  • 504-504: Configuring events_logfile_path to "/var/log/podmand.log" and setting events_logger to "file" aligns with the PR's objective to enhance logging mechanisms. Ensure that appropriate log rotation and size limit configurations are in place to prevent issues with disk space usage.
  • Please verify the log rotation and size limit configurations to ensure efficient disk space usage.

Also applies to: 518-518

# `host` Share host Network Namespace with the container.
# `none` Containers do not use the network
#
netns = "host"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting netns to "host" means containers will share the host's network namespace by default. While this can simplify networking for certain use cases, it may introduce security risks by reducing isolation between containers and the host.

  • Consider the security implications of this setting and evaluate its necessity based on the application's security requirements.

lib/common.sh Outdated
Comment on lines +203 to +218
sublog() {
# Eagerly wait for the log file to exist
while ! [ -f "${1-0}" ]; do sleep 0.1; done
verbose "$1 now present on disk"

# Then reroute its content through our logging printf style
tail -n +0 -f "$1" | while IFS= read -r line; do
if [ -n "$line" ]; then
printf '[%s] [%s] %s\n' \
"${2:-}@${KRUNVM_RUNNER_BIN:-$(basename "$0")}" \
"$(date +'%Y%m%d-%H%M%S')" \
"$line" \
>&"$KRUNVM_RUNNER_LOG"
fi
done
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sublog() function introduces a mechanism to wait for a log file to exist and then continuously tail its contents, formatting each line before redirecting it to another log file. Here are some considerations and suggestions:

  • Correctness: The loop while ! [ -f "${1-0}" ]; do sleep 0.1; done uses "${1-0}" which seems to be a typo. It should likely be "${1:-}" to correctly handle the case where $1 is unset or null. The current default (0) does not make sense in the context of a file path.
  • Performance: Using sleep 0.1 in a loop can be CPU-intensive for a script that's expected to run as a background process. Consider increasing the sleep duration or implementing a more efficient waiting mechanism.
  • Maintainability: The function lacks comments explaining its parameters, expected behavior, and the format it uses for logging. Adding detailed comments would improve maintainability and understandability for future contributors.
  • Best Practices: The use of tail -n +0 -f is appropriate for following the log file from the beginning. However, consider handling the case where the log file grows very large, as this could potentially consume a lot of memory or processing power over time.
- while ! [ -f "${1-0}" ]; do sleep 0.1; done
+ while ! [ -f "${1:-}" ]; do sleep 0.1; done

Consider adding error handling for when the log file does not exist within a reasonable timeout and documenting the function's usage and parameters for clarity.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
sublog() {
# Eagerly wait for the log file to exist
while ! [ -f "${1-0}" ]; do sleep 0.1; done
verbose "$1 now present on disk"
# Then reroute its content through our logging printf style
tail -n +0 -f "$1" | while IFS= read -r line; do
if [ -n "$line" ]; then
printf '[%s] [%s] %s\n' \
"${2:-}@${KRUNVM_RUNNER_BIN:-$(basename "$0")}" \
"$(date +'%Y%m%d-%H%M%S')" \
"$line" \
>&"$KRUNVM_RUNNER_LOG"
fi
done
}
sublog() {
# Eagerly wait for the log file to exist
while ! [ -f "${1:-}" ]; do sleep 0.1; done
verbose "$1 now present on disk"
# Then reroute its content through our logging printf style
tail -n +0 -f "$1" | while IFS= read -r line; do
if [ -n "$line" ]; then
printf '[%s] [%s] %s\n' \
"${2:-}@${KRUNVM_RUNNER_BIN:-$(basename "$0")}" \
"$(date +'%Y%m%d-%H%M%S')" \
"$line" \
>&"$KRUNVM_RUNNER_LOG"
fi
done
}

runner/runner.sh Outdated
Comment on lines +437 to +441
# Make directory for logging
mkdir -p "$RUNNER_LOGDIR"
chown "$RUNNER_USER" "$RUNNER_LOGDIR"
chmod g+rw "$RUNNER_LOGDIR"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a dedicated directory for runner logs ($RUNNER_LOGDIR) and setting appropriate permissions is a good practice for managing application logs. However, ensure the following:

  • Security: The script sets the owner of the log directory to $RUNNER_USER and grants read/write permissions to the group. Verify that this does not inadvertently expose sensitive information to unauthorized users, especially in a shared environment.
  • Error Handling: Consider adding error handling for the mkdir, chown, and chmod commands to ensure the script can gracefully handle failures in directory creation or permission setting.

These precautions will help maintain the security and reliability of the logging mechanism.

@efrecon efrecon merged commit 721ab8a into main Mar 8, 2024
4 of 5 checks passed
@efrecon efrecon deleted the feature/capture-all-logs branch March 8, 2024 21:27
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 545216b and 28ca794.
Files selected for processing (1)
  • runner/runner.sh (8 hunks)
Files skipped from review as they are similar to previous changes (1)
  • runner/runner.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capture all logs
1 participant