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

Maintenance mode: check if domain is updated via API #229

Conversation

zzaakiirr
Copy link
Contributor

@zzaakiirr zzaakiirr commented Aug 30, 2024

What does this PR do?

This PR replaces sleep with actual API request to check if workloadLink is changed for domain after update

Tests

Specs for maintenance command are passing - https://github.com/shakacode/control-plane-flow/actions/runs/10626502289/job/29458117242

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced the maintenance workload switching process with a dynamic retry mechanism for improved responsiveness.
    • Introduced error handling to ensure domain availability during workload switches.
  • Bug Fixes

    • Replaced static wait time with a more efficient verification approach to confirm the workload state.

Copy link

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes introduce a new step in the start_or_stop_maintenance_workload method that implements a retry mechanism for verifying the state of the domain workload after switching. This replaces the previous fixed wait time with a dynamic check, ensuring the domain workload matches the expected state. Additionally, an error handling mechanism has been added to raise an exception if the domain cannot be found after fetching.

Changes

Files Change Summary
lib/core/maintenance_mode.rb Updated start_or_stop_maintenance_workload to include a retry mechanism and dynamic state check; added error handling for domain fetch failures.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant System
    User->>System: Request to start/stop maintenance workload
    System->>System: Switch domain workload
    System->>System: Check domain workload state
    alt Domain workload matches expected state
        System->>User: Confirmation of action
    else Domain workload does not match
        System->>System: Retry (max 3 attempts)
        System->>User: Error if domain not found
    end
Loading

🐰 "In the meadow, bright and free,
A change has hopped, oh can't you see?
With retries and checks, we dance with glee,
Our workload now flows like a gentle stream!
No more waiting, just swift delight,
A happy rabbit in the moonlight!" 🌙


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 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 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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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.

@zzaakiirr
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Aug 30, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 02c8a17 and 8fe4f62.

Files selected for processing (1)
  • lib/core/maintenance_mode.rb (1 hunks)
Additional comments not posted (1)
lib/core/maintenance_mode.rb (1)

Line range hint 69-72: LGTM!

The code changes are approved.

lib/core/maintenance_mode.rb Outdated Show resolved Hide resolved
@zzaakiirr zzaakiirr force-pushed the 157-check-if-domain-was-updated-via-api-instead-of-sleeping branch from 8fe4f62 to 5ea8095 Compare August 30, 2024 03:46
@zzaakiirr zzaakiirr marked this pull request as ready for review August 30, 2024 04:12
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8fe4f62 and 5ea8095.

Files selected for processing (1)
  • lib/core/maintenance_mode.rb (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • lib/core/maintenance_mode.rb

@@ -84,9 +84,13 @@ def start_or_stop_maintenance_workload(action)
def switch_domain_workload(to:)
step("Switching workload for domain '#{domain_data['name']}' to '#{to}'") do
cp.set_domain_workload(domain_data, to)
end

step("Waiting for changes to take effect", retry_on_failure: true, wait: 10, max_retry_count: 3) do
Copy link
Member

Choose a reason for hiding this comment

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

@borela should we be using https://github.com/shakacode/uber_task?

@zzaakiirr is this ready to merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justin808 I left a question for @rafaelgomesxyz, I want to get his opinion on approach I took in this PR for checking if domain was updated.

If this is the right way and Rafael approves this PR then we can merge this


# Give it a bit of time for the domain to update
Kernel.sleep(30)
cp.domain_workload_matches?(refetched_domain_data, to)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rafaelgomesxyz Is this check enough to be sure that domain was updated?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The arbitrary sleep we had before wasn't really to check if the domain value was updated in the workload (after all, this should be true immediately when it first runs, no?).

The sleep was for waiting for DNS changes to take effect, which can sometimes take a bit. So we'd need a different method for checking it (we'd essentially need to check if the domain is working for the switched workload).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we'd need a different method for checking it

Do you have any ideas how can we check this? Maybe controlplane displays some message while workload change takes effect?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@zzaakiirr A way I can think of is to make a real request to the domain and see if it's displaying the regular page or the maintenance page.

I'm not sure if there's a better way to do it.


# Give it a bit of time for the domain to update
Kernel.sleep(30)
cp.domain_workload_matches?(refetched_domain_data, to)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The arbitrary sleep we had before wasn't really to check if the domain value was updated in the workload (after all, this should be true immediately when it first runs, no?).

The sleep was for waiting for DNS changes to take effect, which can sometimes take a bit. So we'd need a different method for checking it (we'd essentially need to check if the domain is working for the switched workload).

@zakir-dzhamaliddinov
Copy link

We'll need to find another way to check if domain is updated, see #229 (comment)

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

Successfully merging this pull request may close these issues.

4 participants