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

Skipping disabled components on atmos describe afffected #942

Merged
merged 6 commits into from
Jan 21, 2025

Conversation

shirkevich
Copy link
Contributor

@shirkevich shirkevich commented Jan 16, 2025

what

  • Added filtering of disabled components in atmos describe affected command

why

  • Components marked with metadata.enabled: false should be excluded from the affected components list
  • Improves accuracy of the describe affected command by only showing components that would actually be processed

Summary by CodeRabbit

  • New Features

    • Added ability to skip disabled components during component processing
    • Improved error handling for Git reference checkout
  • Bug Fixes

    • Enhanced error messaging to suggest alternative flag when target reference is not found

@shirkevich shirkevich requested a review from a team as a code owner January 16, 2025 11:03
@mergify mergify bot added the triage Needs triage label Jan 16, 2025
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new utility function isComponentEnabled in the describe_affected_utils.go file to enhance component processing logic. The function checks the enabled status of components before further processing, allowing skipping of disabled components in both Terraform and Helmfile sections. Additionally, the error handling for Git reference checkout has been improved to provide more informative guidance to users when a specified reference is not found.

Changes

File Change Summary
internal/exec/describe_affected_utils.go - Added isComponentEnabled function to check component status
- Enhanced error messaging for Git reference checkout

Suggested Labels

minor

Suggested Reviewers

  • Gowiem
  • gberenice
✨ 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: 1

🧹 Nitpick comments (3)
pkg/describe/describe_affected_test.go (2)

104-106: Use t.Logf instead of t.Log(fmt.Sprintf()).

Replace the verbose logging with the more idiomatic Go testing approach.

-affectedYaml, err := u.ConvertToYAML(affected)
-assert.Nil(t, err)
-t.Log(fmt.Sprintf("\nAffected components and stacks:\n%v", affectedYaml))
+affectedYaml, err := u.ConvertToYAML(affected)
+assert.Nil(t, err)
+t.Logf("\nAffected components and stacks:\n%v", affectedYaml)
🧰 Tools
🪛 golangci-lint (1.62.2)

106-106: S1038: should use t.Logf(...) instead of t.Log(fmt.Sprintf(...))

(gosimple)


109-111: Enhance test coverage for component filtering.

The test only verifies that "disabled-component" is not in the affected list. Consider adding test cases for:

  1. Components that are explicitly enabled
  2. Components without the enabled flag
  3. Multiple disabled components
-for _, a := range affected {
-    assert.NotEqual(t, "disabled-component", a.Component, "Disabled component should not be included in affected list")
-}
+// Verify disabled components are filtered out
+for _, a := range affected {
+    assert.NotEqual(t, "disabled-component", a.Component, "Disabled component should not be included in affected list")
+    assert.NotEqual(t, "another-disabled-component", a.Component, "Another disabled component should not be included in affected list")
+}
+
+// Verify enabled components are included
+foundEnabledComponent := false
+for _, a := range affected {
+    if a.Component == "enabled-component" {
+        foundEnabledComponent = true
+        break
+    }
+}
+assert.True(t, foundEnabledComponent, "Enabled component should be included in affected list")
internal/exec/describe_affected_utils.go (1)

556-561: Consider explicit handling of missing enabled field.

Currently, components without an enabled field in their metadata are processed. Consider making this behavior explicit by documenting it or setting a default value.

 // Skip disabled components
 if enabled, ok := metadataSection["enabled"].(bool); ok {
     if !enabled {
         continue
     }
+} else {
+    // If enabled field is not present, component is considered enabled by default
+    u.LogTrace(atmosConfig, fmt.Sprintf("Component %s has no enabled field, treating as enabled by default", componentName))
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 20098bf and 2c28833.

📒 Files selected for processing (3)
  • internal/exec/describe_affected_utils.go (2 hunks)
  • pkg/describe/describe_affected_test.go (1 hunks)
  • tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/fixtures/scenarios/complete/stacks/orgs/cp/tenant1/ue2/test-1.yaml
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/describe/describe_affected_test.go

106-106: S1038: should use t.Logf(...) instead of t.Log(fmt.Sprintf(...))

(gosimple)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: [mock-linux] tests/fixtures/scenarios/complete
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Summary

internal/exec/describe_affected_utils.go Outdated Show resolved Hide resolved
@osterman osterman added patch A minor, backward compatible change bugfix Change that restores intended behavior and removed triage Needs triage labels Jan 16, 2025
@aknysh
Copy link
Member

aknysh commented Jan 17, 2025

@shirkevich can you please review and address the comments

@shirkevich
Copy link
Contributor Author

shirkevich commented Jan 20, 2025

@shirkevich can you please review and address the comments

Done, don't know how to create proper fixture and test to validate this on CI. Tested it locally with my env

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)
internal/exec/describe_affected_utils.go (1)

1524-1533: Enhance log message format for consistency.

The implementation follows the standardization guidelines well. Consider updating the log message format to match the exact format from the learnings.

-			u.LogTrace(atmosConfig, fmt.Sprintf("Skipping disabled component %s", componentName))
+			u.LogTrace(atmosConfig, fmt.Sprintf("Skipping disabled component '%s'", componentName))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2c28833 and 581e5c4.

📒 Files selected for processing (1)
  • internal/exec/describe_affected_utils.go (3 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: osterman
PR: cloudposse/atmos#942
File: internal/exec/describe_affected_utils.go:802-807
Timestamp: 2025-01-16T11:41:35.531Z
Learning: When checking if a component is enabled in Atmos, use standardized helper function that includes logging. The function should check the `enabled` field in the component's metadata section and log a trace message when skipping disabled components.
internal/exec/describe_affected_utils.go (1)
Learnt from: osterman
PR: cloudposse/atmos#942
File: internal/exec/describe_affected_utils.go:802-807
Timestamp: 2025-01-16T11:41:35.531Z
Learning: When checking if a component is enabled in Atmos, use standardized helper function that includes logging. The function should check the `enabled` field in the component's metadata section and log a trace message when skipping disabled components.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (2)
internal/exec/describe_affected_utils.go (2)

556-559: LGTM! Clean refactoring to use the helper function.

The extraction of the component enabled check into a helper function improves code maintainability and follows DRY principles.


800-803: LGTM! Consistent implementation across sections.

The helper function is consistently used in both Terraform and Helmfile sections, effectively reducing code duplication.

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @shirkevich

@aknysh aknysh merged commit e645a03 into cloudposse:main Jan 21, 2025
43 checks passed
Copy link

These changes were released in v1.153.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Change that restores intended behavior patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants