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

feat: add spinner during atmos validate stacks operations #1005

Merged
merged 7 commits into from
Feb 4, 2025

Conversation

RoseSecurity
Copy link
Contributor

@RoseSecurity RoseSecurity commented Feb 3, 2025

why

atmos_validate

  • It can be difficult to tell whether the command is hanging or actively running in the background. Here’s the current output:
. [infra] (HOST) workspace ⨠ atmos validate stacks

Then:

. [infra] (HOST) workspace ⨠ atmos validate stacks
all stacks validated successfully

what

references

Summary by CodeRabbit

  • New Features
    • Introduced a spinner indicator that provides live visual feedback during the Atmos Stacks validation process. This enhancement gracefully adapts to both interactive and non-interactive terminal sessions, offering a fallback message when needed, and stops promptly if errors occur.
    • Added output messages indicating the start and successful completion of the Atmos Stacks validation.

@RoseSecurity RoseSecurity requested a review from a team as a code owner February 3, 2025 18:52
@mergify mergify bot added the triage Needs triage label Feb 3, 2025
Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

📝 Walkthrough

Walkthrough

The pull request integrates a spinner UI element into the ExecuteValidateStacksCmd function in the internal/exec/validate_stacks.go file. The spinner is initialized with a custom message and conditionally configured based on TTY support. It runs concurrently during the stack validation process and is stopped appropriately on errors or upon completion. Additionally, the error-handling flow is updated to ensure the spinner always reflects the command's state.

Changes

File Change Summary
internal/exec/validate_stacks.go Added spinner UI integration with concurrent execution, TTY check adjustments, updated error handling to ensure spinner stops on errors/completion, and added new spinner-related imports.
tests/snapshots/TestCLICommands_atmos_validate_stacks_with_metadata.stdout.golden Introduced new output messages indicating the start and successful completion of the Atmos Stacks validation process.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant Cmd as ExecuteValidateStacksCmd
    participant Spinner as Spinner Goroutine
    participant Validate as ValidateStacks

    User->>Cmd: Invoke "atmos validate stacks"
    Cmd->>Spinner: Initialize and start spinner concurrently
    Cmd->>Validate: Process arguments and validate stacks
    Validate-->>Cmd: Return result or error
    Cmd->>Spinner: Stop spinner based on execution outcome
    Cmd-->>User: Return output with validation status
Loading

Assessment against linked issues

Objective Addressed Explanation
Add spinner to atmos validate stacks operation (#1003)

Suggested labels

minor

✨ 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 (2)
internal/exec/validate_stacks.go (2)

33-44: Consider enhancing the fallback message for non-TTY environments.

The non-TTY fallback is well-implemented, but the trace message could be more informative.

-		u.LogTrace("No TTY detected. Falling back to basic output. This can happen when no terminal is attached or when commands are pipelined.")
+		u.LogTrace("No TTY detected. Using basic output mode. Common scenarios: CI/CD pipelines, redirected output, or non-interactive terminals.")

91-97: Consider adding a success message after validation.

The validation completion could be more user-friendly by providing explicit feedback.

 	err = ValidateStacks(atmosConfig)
 
 	// Ensure spinner is stopped before returning
 	p.Quit()
 	<-spinnerDone
 
+	if err == nil {
+		fmt.Println("Stack validation completed successfully!")
+	}
+
 	return 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 a6fb9e6 and 5a96b3d.

📒 Files selected for processing (1)
  • internal/exec/validate_stacks.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (3)
internal/exec/validate_stacks.go (3)

14-16: LGTM! Clean import organization.

The new imports for the spinner UI components are well-organized and properly scoped.

Also applies to: 22-22


64-98: LGTM! Robust error handling with proper cleanup.

The error handling is thorough, ensuring the spinner is properly stopped in all error cases and the error channel is drained.


46-62: Ensure spinner errors don't block command execution.

The spinner error handling is good, but we should ensure the error channel is always drained to prevent goroutine leaks.

✅ Verification successful

I'll dive a bit deeper into this by examining the context around how the spinnerDone channel is used within the file. Let's pull the lines around the spinner error handling code in internal/exec/validate_stacks.go to get a better picture.


Spinner error handling is properly managed.

The code correctly employs a buffered error channel (with capacity 1), ensuring the spinner error is sent without risking a block. Additionally, in the case of an error from processing CLI arguments, the code calls p.Quit() and then drains spinnerDone (<-spinnerDone), which avoids any goroutine leak. This pattern ensures that spinner errors do not block command execution.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other goroutine usages to verify consistent error handling patterns
ast-grep --pattern 'go func() {
  $$$
  spinnerDone <- err
  $$$
}'

Length of output: 69


Script:

#!/bin/bash
# Extract lines 40-70 from the file to inspect spinnerDone usage in context.
sed -n '40,70p' internal/exec/validate_stacks.go

Length of output: 826

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 3, 2025
@mergify mergify bot removed the triage Needs triage label Feb 3, 2025
@mergify mergify bot removed the triage Needs triage label Feb 3, 2025
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/validate_stacks.go (1)

33-44: Consider enhancing the spinner message.

The spinner implementation looks good, but we could make the message more informative.

-	message := "Validating Atmos Stacks..."
+	message := "Validating Atmos Stacks (this may take a few moments)..."
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 75617db and c309f55.

📒 Files selected for processing (1)
  • internal/exec/validate_stacks.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (3)
internal/exec/validate_stacks.go (3)

14-16: LGTM! Good choice of dependencies.

The selection of charmbracelet/bubbles and bubbletea for the spinner implementation is solid. These are well-maintained libraries with good community support.

Also applies to: 22-22


46-62: LGTM! Robust spinner implementation.

The spinner implementation is well-structured with:

  • Proper error handling
  • Non-blocking execution using goroutine
  • Clean error propagation through channel

64-98: LGTM! Thorough error handling and cleanup.

The error handling is comprehensive with proper cleanup of spinner resources in all code paths:

  • Command line args processing errors
  • Config initialization errors
  • Stack validation errors

Copy link
Member

@osterman osterman left a comment

Choose a reason for hiding this comment

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

LGTM

@osterman osterman added the no-release Do not create a new release (wait for additional code changes) label Feb 3, 2025
@osterman
Copy link
Member

osterman commented Feb 3, 2025

We'll release this alongside some other things going out this week.

@RoseSecurity
Copy link
Contributor Author

Awesome, thank you!

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 @RoseSecurity

@osterman osterman merged commit 59a666a into main Feb 4, 2025
44 checks passed
@osterman osterman deleted the add-spinner-during-validate-stacks-operations branch February 4, 2025 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a spinner during atmos validate stacks operations
3 participants