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

Logs improvements part2 #957

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Logs improvements part2 #957

wants to merge 4 commits into from

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented Jan 19, 2025

what

Fixed error message consistency for invalid log level validation
Updated test cases

Evidence:
CleanShot 2025-01-19 at 18 43 44

wrong/invalid flag passed:
CleanShot 2025-01-19 at 17 33 37

Env variable invalid:
CleanShot 2025-01-19 at 17 31 02

why

Improved error messages
Better output clarity when theres an issue on the ATMOS_LOGS_LEVEL as env variable or when it's passed as a flag

references

Summary by CodeRabbit

  • New Features

    • Added log level configuration for version command
    • Enhanced debug logging for version checking process
    • Improved logging context for GitHub release checks
  • Bug Fixes

    • Improved error handling for log level configuration
    • Updated error messages for invalid log levels
  • Documentation

    • Clarified error messages when checking Atmos version and log levels
  • Chores

    • Refined logging and error reporting mechanisms across multiple commands
    • Enhanced clarity of debug logs with explicit log level indicators

@Cerebrovinny Cerebrovinny requested a review from osterman January 19, 2025 17:55
@Cerebrovinny Cerebrovinny marked this pull request as ready for review January 19, 2025 17:55
@Cerebrovinny Cerebrovinny requested a review from a team as a code owner January 19, 2025 17:55
@mergify mergify bot added the triage Needs triage label Jan 19, 2025
Copy link
Contributor

coderabbitai bot commented Jan 19, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhancements to version checking, logging, and error handling across multiple files in the Atmos CLI. The changes focus on improving debug logging, error message clarity, and configuration initialization, particularly around version checks and log level processing. The modifications provide more granular feedback and more informative error messages without fundamentally altering the core functionality of the affected components.

Changes

File Change Summary
cmd/cmd_utils.go Added debug logging for version checking process, including logs for disabled checks and up-to-date status. Modified warning message for cache loading failure.
cmd/root.go Modified error handling to suppress certain error messages during help command invocations.
cmd/version.go Added log level flag retrieval, enhanced error handling, and debug logging for version checks. Updated method signature to include log level context.
pkg/config/utils.go Updated error messages for invalid log levels to provide clearer guidance.
pkg/utils/github_utils.go Updated function signature to include atmosConfig and simplified logic for fetching the latest GitHub release. Enhanced logging and error handling.
pkg/utils/log_utils.go Modified LogDebug function to prepend "[DEBUG] " to debug messages for clarity.
tests/test-cases/log-level-validation.yaml Updated expected error message for invalid log level to include context about the environment variable.

Possibly related issues

  • DEV-2693: This PR addresses error handling for invalid log levels, aligning with the objective to validate Atmos log levels.

Possibly related PRs

  • Added Support for Automatic Templated File Search for Atmos Imports #795: The changes in the main PR involve modifications to the CheckForAtmosUpdateAndPrintMessage function in cmd/cmd_utils.go, which is related to version checking and logging, similar to the enhancements made in the versionCmd command in cmd/version.go that also involves logging and version checks.
  • Validate Atmos Log Levels #930: This PR focuses on validating log levels, which is relevant to the logging enhancements made in the main PR, particularly in the context of logging during version checks.
  • Logs validation on root level #946: The changes in this PR enhance logging configuration handling in cmd/root.go, which relates to the logging improvements introduced in the main PR.

Suggested labels

minor

Suggested reviewers

  • osterman
  • aknysh
  • Gowiem

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
cmd/cmd_utils.go (1)

498-512: Fix typo in error message while maintaining good debug logging.

The added debug logging enhances observability, but there's a grammatical error in the error message.

Fix the typo in the error message:

-u.LogWarning(atmosConfig, fmt.Sprintf("Unable not load cache: %s", err))
+u.LogWarning(atmosConfig, fmt.Sprintf("Unable to load cache: %s", err))
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8f480f and fc3adfa.

📒 Files selected for processing (4)
  • cmd/cmd_utils.go (2 hunks)
  • cmd/root.go (1 hunks)
  • cmd/version.go (3 hunks)
  • pkg/config/utils.go (2 hunks)
🧰 Additional context used
📓 Learnings (1)
cmd/cmd_utils.go (1)
Learnt from: Listener430
PR: cloudposse/atmos#844
File: cmd/version.go:34-44
Timestamp: 2024-12-13T15:28:13.630Z
Learning: In `cmd/version.go`, when handling the `--check` flag in the `versionCmd`, avoid using `CheckForAtmosUpdateAndPrintMessage(cliConfig)` as it updates the cache timestamp, which may not be desired in this context.
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: [mock-macos] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-macos] examples/demo-vendoring
  • GitHub Check: [mock-macos] examples/demo-context
  • GitHub Check: [mock-macos] examples/demo-component-versions
  • GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-windows] examples/demo-vendoring
  • GitHub Check: [mock-windows] examples/demo-context
  • GitHub Check: [mock-windows] examples/demo-component-versions
  • GitHub Check: [mock-windows] examples/demo-atlantis
  • GitHub Check: [mock-linux] tests/fixtures/scenarios/complete
  • GitHub Check: [mock-linux] examples/demo-vendoring
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: [mock-linux] examples/demo-context
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: [lint] quick-start-advanced
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Docker Lint
  • GitHub Check: [k3s] demo-helmfile
  • GitHub Check: Summary
🔇 Additional comments (7)
cmd/version.go (3)

26-40: Well-structured initialization of log level configuration!

The code properly validates the log level from command line flags before initializing the configuration, following good error handling practices.


54-75: Consider the impact of cache updates during version checks.

While the added debug logging improves observability, be cautious about using CheckForAtmosUpdateAndPrintMessage in this context as it updates the cache timestamp, which might not be desired here.

Consider separating the version check logic from cache updates to maintain better control over when the cache is modified.


81-82: Good addition of debug logging!

The debug message clearly indicates that updates are being checked from the cache, improving observability.

cmd/root.go (1)

65-70: Excellent improvement to error handling!

The code now intelligently suppresses unnecessary warnings during help requests while maintaining proper error handling for other scenarios. This enhances the user experience.

cmd/cmd_utils.go (1)

535-536: Good addition of status logging!

The debug message clearly indicates when Atmos is up to date, improving observability.

pkg/config/utils.go (2)

364-364: Excellent improvement to error messaging!

The error message now clearly indicates both the invalid value and the valid options, making it easier for users to correct their input.


489-489: Great consistency in error messaging!

The error message for command line flags matches the style used for environment variables, maintaining a consistent user experience.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 19, 2025
@mergify mergify bot removed the triage Needs triage label Jan 19, 2025
@mergify mergify bot added the triage Needs triage label Jan 19, 2025
@Cerebrovinny Cerebrovinny force-pushed the logs-improvements-part2 branch from 6c00f9d to 59b899d Compare January 19, 2025 18:45
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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
pkg/utils/github_utils.go (1)

34-35: Consider using authenticated client for better rate limits.

The change to use an unauthenticated client might lead to GitHub API rate limiting. Consider using the existing newGitHubClient function which handles authentication.

-client := github.NewClient(nil)
+client := newGitHubClient(context.Background())
cmd/version.go (1)

56-65: Simplify error handling logic.

The error handling contains redundant checks and could be simplified.

-			latestReleaseTag, err := u.GetLatestGitHubRepoRelease(atmosConfig, "cloudposse", "atmos")
-			if err == nil && latestReleaseTag != "" {
-				if err != nil {
-					u.LogWarning(atmosConfig, fmt.Sprintf("Failed to check for updates: %v", err))
-					return
-				}
-				if latestReleaseTag == "" {
-					u.LogWarning(atmosConfig, "No release information available")
-					return
-				}
+			latestReleaseTag, err := u.GetLatestGitHubRepoRelease(atmosConfig, "cloudposse", "atmos")
+			if err != nil {
+				u.LogWarning(atmosConfig, fmt.Sprintf("Failed to check for updates: %v", err))
+				return
+			}
+			if latestReleaseTag == "" {
+				u.LogWarning(atmosConfig, "No release information available")
+				return
+			}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc3adfa and 59b899d.

📒 Files selected for processing (7)
  • cmd/cmd_utils.go (2 hunks)
  • cmd/root.go (1 hunks)
  • cmd/version.go (4 hunks)
  • pkg/config/utils.go (2 hunks)
  • pkg/utils/github_utils.go (2 hunks)
  • pkg/utils/log_utils.go (1 hunks)
  • tests/test-cases/log-level-validation.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • cmd/root.go
  • cmd/cmd_utils.go
  • pkg/config/utils.go
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: Summary
🔇 Additional comments (5)
pkg/utils/log_utils.go (1)

82-82: LGTM! Improved debug message clarity.

Adding the "[DEBUG]" prefix makes it easier to identify debug level messages in logs.

tests/test-cases/log-level-validation.yaml (1)

34-34: LGTM! Test case updated to match new error message format.

The test case now properly validates the improved error message that includes the environment variable context.

cmd/version.go (3)

26-40: LGTM! Proper initialization of logging configuration.

The initialization of atmosConfig with log level from flags is well-structured and includes proper error handling.


69-71: LGTM! Clear debug logging.

The debug logging statements provide good visibility into the version comparison process.


82-83: LGTM! Added debug logging for cache check.

Good addition of debug logging before checking for updates from cache.

@mergify mergify bot removed the triage Needs triage label Jan 19, 2025
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.

2 participants