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 deadline instead of timeout #599

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mojtaba-esk
Copy link
Member

@mojtaba-esk mojtaba-esk commented Dec 19, 2024

Closes #367

Summary by CodeRabbit

  • New Features

    • Transitioned from a timeout-based to a deadline-based approach for resource management in the Knuu package.
    • Introduced a new Deadline option for configuration.
  • Bug Fixes

    • Updated test assertions to reflect the new naming convention for deadline handling.
  • Documentation

    • Updated comments to indicate the deprecation of the Timeout field in favor of the new Deadline field.

@mojtaba-esk mojtaba-esk requested a review from a team December 19, 2024 15:39
@mojtaba-esk mojtaba-esk self-assigned this Dec 19, 2024
Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request introduces a significant change in the knuu package, transitioning from a timeout-based mechanism to a deadline-based approach. The modifications span across multiple files, primarily updating the knuu.go file to replace the Timeout field with a new Deadline field in the Options struct. The changes involve renaming constants, updating method signatures, and modifying the internal logic for handling resource cleanup. The test files have been correspondingly updated to reflect these changes.

Changes

File Change Summary
e2e/sidecars/suite_setup_test.go Replaced Timeout option with Deadline in knuu.New() call
pkg/knuu/knuu.go - Deprecated Timeout field in Options struct
- Added new Deadline field
- Renamed handleTimeout to handleDeadline
- Updated constants and method logic
pkg/knuu/knuu_test.go Updated test assertion from timeoutHandlerName to deadlineHandlerName

Assessment against linked issues

Objective Addressed Explanation
Set expiration date in timeout-handler [#367]

Possibly related PRs

Suggested labels

knuu

Suggested reviewers

  • sysrex
  • smuu
  • tty47

Poem

🐰 Timeout's dance, now a deadline's embrace,
Knuu evolves with elegant grace.
From duration to moment precise,
A rabbit's code, cutting clean as a slice!
Time marches on, with newfound might! 🕒


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.

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.

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/knuu/knuu.go (3)

28-31: Consider making these constants private or grouping them.

They appear to be used only in the local package. If they are strictly internal constants, consider making them unexported (e.g., lowercase) or grouping them to make them easier to discover and maintain.


51-52: Mark deprecated fields clearly and remove them in future releases.

You have introduced a new Deadline field while keeping Timeout field for backward compatibility. Consider using Go’s official deprecation comment style (e.g. “// Deprecated: Use Deadline instead.”) to help IDEs and linters.


114-116: Double-check the immediate usage of time.Now() in cleanup.

You are calling handleDeadline with time.Now() as the deadline. This effectively triggers cleanup operations immediately. If the intent is to attempt graceful termination for a short interval, you may wish to add a small buffer.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83a1a24 and b5dfb72.

📒 Files selected for processing (3)
  • e2e/sidecars/suite_setup_test.go (1 hunks)
  • pkg/knuu/knuu.go (6 hunks)
  • pkg/knuu/knuu_test.go (1 hunks)
🔇 Additional comments (4)
pkg/knuu/knuu.go (3)

78-85: Ensure clarity around fallback logic for deadline vs. deprecated timeout.

When opts.Deadline is zero, the code logs a warning upon using Timeout but gracefully sets the Deadline if Timeout is present. This is a good approach, but ensure you remove the Timeout usage in a future major release to avoid confusion.


88-88: Confirm error handling for handleDeadline.

Currently, if handleDeadline returns an error, the constructor wraps it and returns. Confirm that the calling contexts handle (or log) this error sufficiently, since it potentially prevents the entire environment setup.


Line range hint 125-145: Validate that the command sequence will not block or fail silently.

handleDeadline builds a multi-step shell command to delete namespace resources. Consider logging each step to facilitate debugging in case of partial resource deletions. Also, verify that all potential errors raised by each chained command are handled.

e2e/sidecars/suite_setup_test.go (1)

37-38: Good adaptation to deadline-based approach.

Replacing Timeout with Deadline conforms with the new approach. Make sure to test and confirm that the new deadline-based behavior works as intended within the CI pipeline timelines.

@@ -74,7 +74,7 @@ func TestNew(t *testing.T) {
assert.NotNil(t, k.K8sClient)
assert.NotNil(t, k.ImageBuilder)
assert.NotEmpty(t, k.Scope)
assert.Equal(t, defaultTimeout, defaultTimeout, timeoutHandlerName)
assert.Equal(t, defaultTimeout, defaultTimeout, deadlineHandlerName)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Revisit the usage of assert.Equal here.

The current invocation, assert.Equal(t, defaultTimeout, defaultTimeout, deadlineHandlerName), compares defaultTimeout with itself and uses deadlineHandlerName as the message. This has no real assertion effect. Consider adjusting it if your goal was to test that the defaultTimeout is applied or to ensure that the correct handler name is used.

- assert.Equal(t, defaultTimeout, defaultTimeout, deadlineHandlerName)
+ // Example fix if validating actual usage of defaultTimeout and handler name
+ assert.Equal(t, defaultTimeout, someComputedTimeout, "defaultTimeout should match the expected fallback")
+ assert.Equal(t, "deadline-handler", deadlineHandlerName, "Invalid or missing handler name")

Committable suggestion skipped: line range outside the PR's diff.

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

Successfully merging this pull request may close these issues.

Set expiration date in the timeout-handler instead of an sleep
1 participant