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

add check context cancel #2596

Merged
merged 10 commits into from
Sep 12, 2024
Merged

Conversation

kmrmt
Copy link
Contributor

@kmrmt kmrmt commented Sep 5, 2024

Description

Fix unstable unit test result.

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.23.0
  • Rust Version: v1.80.0
  • Docker Version: v27.1.1
  • Kubernetes Version: v1.30.3
  • Helm Version: v3.15.3
  • NGT Version: v2.2.4
  • Faiss Version: v1.8.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • New Features

    • Improved handling of context cancellation and deadline expiration in the application.
    • Enhanced error logging for better clarity on timeout and cancellation scenarios.
  • Bug Fixes

    • Resolved issues related to error handling when context is done, providing clearer feedback on failures.
  • Chores

    • Updated the version from 1.23.0 to 1.23.1, indicating minor improvements.

Signed-off-by: Kosuke Morimoto <[email protected]>
Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Walkthrough

Walkthrough

The changes introduce a select statement in the Do method of the backoff struct within the internal/backoff/backoff.go file. This modification enhances the method's ability to handle context cancellation and deadline expiration, allowing it to log appropriate messages and return relevant errors based on the context's state. Additionally, the versions/GO_VERSION file has been updated from 1.23.0 to 1.23.1, indicating a minor version increment.

Changes

Files Change Summary
internal/backoff/backoff.go Modified the Do method to include a select statement for context cancellation handling, logging specific messages, and returning appropriate errors based on context state.
versions/GO_VERSION Updated version number from 1.23.0 to 1.23.1, indicating a minor version increment.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Backoff
    participant Context

    Caller->>Backoff: Call Do()
    Backoff->>Context: Wait for completion
    alt Context Done
        Context-->>Backoff: Context Done
        Backoff->>Backoff: Check dctx.Err()
        alt Deadline Exceeded
            Backoff-->>Caller: Return timeout error
        else Context Canceled
            Backoff-->>Caller: Return original error
        else Other Error
            Backoff-->>Caller: Return combined error
        end
    else Continue Execution
        Backoff-->>Caller: Continue processing
    end
Loading

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.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Sep 5, 2024

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.

Project coverage is 24.35%. Comparing base (c3c5765) to head (edcfbe2).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
internal/backoff/backoff.go 61.53% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2596      +/-   ##
==========================================
- Coverage   24.36%   24.35%   -0.02%     
==========================================
  Files         531      531              
  Lines       45867    45880      +13     
==========================================
- Hits        11177    11173       -4     
- Misses      33939    33958      +19     
+ Partials      751      749       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b17cc73 and e8bcb40.

Files selected for processing (1)
  • internal/backoff/backoff.go (1 hunks)

internal/backoff/backoff.go Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b17cc73 and e8bcb40.

Files selected for processing (1)
  • internal/backoff/backoff.go (1 hunks)
Additional context used
GitHub Check: codecov/patch
internal/backoff/backoff.go

[warning] 196-198: internal/backoff/backoff.go#L196-L198
Added lines #L196 - L198 were not covered by tests


[warning] 202-203: internal/backoff/backoff.go#L202-L203
Added lines #L202 - L203 were not covered by tests

Additional comments not posted (1)
internal/backoff/backoff.go (1)

194-203: Context error handling is robust and well-implemented.

The handling of different context errors (context.DeadlineExceeded and context.Canceled) within the select statement is appropriately managed. The use of errors.Join for other errors is a good practice as it preserves the context of the original error, which is crucial for debugging and error resolution.

Tools
GitHub Check: codecov/patch

[warning] 196-198: internal/backoff/backoff.go#L196-L198
Added lines #L196 - L198 were not covered by tests


[warning] 202-203: internal/backoff/backoff.go#L202-L203
Added lines #L202 - L203 were not covered by tests

internal/backoff/backoff.go Outdated Show resolved Hide resolved
@kmrmt kmrmt marked this pull request as ready for review September 6, 2024 02:07
@kmrmt kmrmt requested review from a team, kpango and datelier and removed request for a team September 6, 2024 02:08
Signed-off-by: Kosuke Morimoto <[email protected]>
Copy link

cloudflare-workers-and-pages bot commented Sep 6, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: edcfbe2
Status: ✅  Deploy successful!
Preview URL: https://f39c7e40.vald.pages.dev
Branch Preview URL: https://bugfix-test-backoff-do-unsta.vald.pages.dev

View logs

Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e8bcb40 and b1c53f4.

Files selected for processing (1)
  • internal/backoff/backoff.go (1 hunks)
Additional context used
GitHub Check: codecov/patch
internal/backoff/backoff.go

[warning] 189-198: internal/backoff/backoff.go#L189-L198
Added lines #L189 - L198 were not covered by tests

internal/backoff/backoff.go Show resolved Hide resolved
Signed-off-by: Kosuke Morimoto <[email protected]>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b1c53f4 and cdfdfc3.

Files selected for processing (1)
  • internal/backoff/backoff.go (1 hunks)
Additional comments not posted (1)
internal/backoff/backoff.go (1)

189-204: Confirm handling of context states and suggest enhancements.

The handling of context states using the select statement is robust and well-implemented. However, as previously suggested, consider enhancing the logging for the default case to aid in debugging when neither DeadlineExceeded nor Canceled errors occur.

Additionally, it is crucial to ensure that these new lines are covered by tests, especially given their importance in handling context cancellation and deadline expiration. The static analysis warning indicates that these lines are not currently covered by tests, which poses a risk to the reliability of this functionality.

Consider adding more detailed logging for the default case:

case <-dctx.Done():
    switch dctx.Err() {
    case context.DeadlineExceeded:
        log.Debugf("[backoff]\tfor: "+name+",\tDeadline Exceeded\terror: %v", err.Error())
        return nil, errors.ErrBackoffTimeout(err)
    case context.Canceled:
        log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error())
        return nil, err
    default:
        log.Debugf("[backoff]\tfor: "+name+",\tUnknown context error\terror: %v", err.Error())
        return nil, errors.Join(dctx.Err(), err)
    }

If you need assistance with generating the test cases to cover these scenarios, I can help.

Likely invalid or redundant comment.

Signed-off-by: Kosuke Morimoto <[email protected]>
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cdfdfc3 and a2fdc40.

Files selected for processing (1)
  • versions/GO_VERSION (1 hunks)
Files skipped from review due to trivial changes (1)
  • versions/GO_VERSION

@vankichi vankichi merged commit 0e12419 into main Sep 12, 2024
162 of 164 checks passed
@vankichi vankichi deleted the bugfix/test/backoff-do-unstable-result branch September 12, 2024 05:27
kmrmt added a commit that referenced this pull request Sep 12, 2024
* add check context cancel

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* fix

Signed-off-by: Kosuke Morimoto <[email protected]>

* update deps

Signed-off-by: Kosuke Morimoto <[email protected]>

---------

Signed-off-by: Kosuke Morimoto <[email protected]>
Co-authored-by: Yusuke Kato <[email protected]>
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.

5 participants