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

chore: prevent revision check from retrying unnecessary #1315

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

arealmaas
Copy link
Collaborator

@arealmaas arealmaas commented Oct 17, 2024

Description

The revision check kept on retrying even though the revision had failed

Related Issue(s)

  • #{issue number}

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of exit codes during container app revision verification, enhancing clarity and control flow.
    • Adjusted output messages for better user understanding based on revision state.
  • Refactor

    • Streamlined the verification process to improve readability and maintainability of the script.

@arealmaas arealmaas requested review from a team as code owners October 17, 2024 11:06
Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the revisionVerifier.sh script, focusing on enhancing exit code handling and control flow during container app revision verification. It defines three new exit codes and updates the verify_revision function to return these codes based on the revision's health and state. The status-checking loop is refactored to use a case statement for clearer outcome handling, improving the script's readability and maintainability.

Changes

File Change Summary
.github/tools/revisionVerifier.sh Enhanced exit code handling by defining constants EXIT_SUCCESS, EXIT_NOT_READY, EXIT_FAILED. Updated verify_revision function to return these constants. Refactored status-checking loop to use a case statement for improved control flow and output clarity.

Possibly related PRs

Suggested reviewers

  • oskogstad
  • knuhau

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 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 to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai 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

sonarcloud bot commented Oct 17, 2024

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

🧹 Outside diff range and nitpick comments (3)
.github/tools/revisionVerifier.sh (3)

41-45: LGTM: Improved error handling and consistent use of exit codes.

The addition of a specific check for the "Failed" state enhances error handling, and the use of exit code constants improves consistency and readability.

Consider adding a comment explaining the conditions for EXIT_NOT_READY to improve clarity:

  if [[ $health_state == "Healthy" && ($running_state == "Running" || $running_state == "RunningAtMaxScale") ]]; then
    return $EXIT_SUCCESS
  else
+   # Return EXIT_NOT_READY if the revision is not healthy or not in a running state
    return $EXIT_NOT_READY
  fi

Also applies to: 49-51


57-76: LGTM: Improved control flow with case statement.

The refactoring of the main loop to use a case statement significantly improves the readability and maintainability of the script. The logic for handling different states is clear and well-structured.

To address the static analysis warnings and improve robustness, consider quoting the variables in the case patterns:

  case $result in
-   $EXIT_SUCCESS)
+   "$EXIT_SUCCESS")
      echo "Revision $revision_name is healthy and running"
      exit $EXIT_SUCCESS
      ;;
-   $EXIT_FAILED)
+   "$EXIT_FAILED")
      echo "Revision $revision_name has failed. Exiting."
      exit $EXIT_FAILED
      ;;
-   $EXIT_NOT_READY)
+   "$EXIT_NOT_READY")
      echo "Attempt $attempt: Waiting for revision $revision_name ..."
      sleep 10 # Sleep for 10 seconds
      attempt=$((attempt+1))
      ;;
  esac

This change will prevent potential issues if the variables contain special characters or spaces.

🧰 Tools
🪛 Shellcheck

[warning] 63-63: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)


[warning] 67-67: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)


[warning] 71-71: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)


Line range hint 21-76: Overall improvements enhance script robustness and maintainability.

The changes made to this script align well with the PR objectives of preventing unnecessary retries for failed revisions. The introduction of clear exit codes, improved error handling, and the refactored main loop using a case statement all contribute to a more robust and maintainable script.

These modifications should effectively address the issue of continuous retrying after a revision has failed, improving the efficiency of the revision checking process.

To further improve the script's robustness, consider adding logging functionality. This could help with debugging and monitoring the script's behavior in production. For example:

log_message() {
  echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" >> /path/to/logfile.log
}

# Then use it in the script:
log_message "Attempt $attempt: Waiting for revision $revision_name ..."

This would provide valuable insights into the script's execution over time.

🧰 Tools
🪛 Shellcheck

[warning] 63-63: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)


[warning] 67-67: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)


[warning] 71-71: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0072488 and c1e0a56.

📒 Files selected for processing (1)
  • .github/tools/revisionVerifier.sh (2 hunks)
🧰 Additional context used
🪛 Shellcheck
.github/tools/revisionVerifier.sh

[warning] 63-63: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)


[warning] 67-67: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)


[warning] 71-71: Quote expansions in case patterns to match literally rather than as a glob.

(SC2254)

🔇 Additional comments (1)
.github/tools/revisionVerifier.sh (1)

21-24: LGTM: Well-defined exit codes improve script clarity.

The introduction of these exit code constants enhances the script's readability and maintainability. The use of readonly is a good practice to prevent accidental modifications.

@arealmaas arealmaas merged commit c3e8e8c into main Oct 17, 2024
24 checks passed
@arealmaas arealmaas deleted the chore/prevent-revision-check-from-retrying branch October 17, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants