refactor: add Context parameter to Backoff.Wait method#50428
refactor: add Context parameter to Backoff.Wait method#50428andrzej-stencel wants to merge 13 commits intoelastic:mainfrom
Context parameter to Backoff.Wait method#50428Conversation
Removes `done` channel from backoff constructor functions. Uses the `Context` instance passed as parameter to `Backoff.Wait` method.
Moves retryBackoff instantiation to `MakeOtelConsumer`. Each `Backoff.Wait` method now uses the context from the current `Publish` call, removing confusion.
The call to `Backoff.Wait` gets the `f.readerCtx` which is functionally equivalent to the `canceler.Done()` channel used previously.
To create an instance of `context.Context` from `input.Context` (v1), I applied the same approach that exists for `input.Context` (v2) in `filebeat/input/kafka/input.go`.
Note that in `makeESClient`, the `connectDelay` previously used `context.Background`. This change uses the context passed to the `makeESClient` function.
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
🤖 GitHub commentsJust comment with:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe backoff API was changed to make waits cancelable via contexts: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
This comment has been minimized.
This comment has been minimized.
For the forbidigo errors forbidding usage of global logger, I just added nolint directives to minimize the amount of unrelated changes in this PR. In my view, the loggers issue should be fixed separately and globally (not only in the files touched by this PR).
This comment has been minimized.
This comment has been minimized.
TL;DRBoth failed Buildkite jobs are failing on the same Filebeat integration test ( Remediation
Investigation detailsRoot CauseThe two failing jobs report the identical failure:
This PR commit ( Evidence
Verification
Follow-upIf you want, I can narrow this further to a concrete replacement assertion that validates single-harvester semantics without depending on debug log timing. Note 🔒 Integrity filter blocked 2 itemsThe following items were blocked because they don't meet the GitHub integrity level.
To allow these resources, lower tools:
github:
min-integrity: approved # merged | approved | unapproved | noneWhat is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
| startedAt := time.Now() | ||
| assert.True(t, WaitOnError(b, errors.New("bad bad"))) | ||
| assert.GreaterOrEqual(t, time.Now().Sub(startedAt), init) | ||
| assert.True(t, WaitOnError(context.Background(), b, errors.New("bad bad"))) |
There was a problem hiding this comment.
| assert.True(t, WaitOnError(context.Background(), b, errors.New("bad bad"))) | |
| assert.True(t, WaitOnError(t.Context(), b, errors.New("bad bad"))) |
| b := f(c) | ||
| close(c) | ||
| assert.False(t, b.Wait()) | ||
| ctx, cancel := context.WithCancel(context.Background()) |
mauri870
left a comment
There was a problem hiding this comment.
Codewise looks good, pending the CI issues.
Proposed commit message
Changes the API of the
Backoffinterface, addingcontext.Contextto itsWaitmethod.Previously, the
Waitmethod used a context (or more specifically, adonechannel) that was passed during creation of aBackoffinstance, specifically inNewExpBackoffandNewEqualJitterBackofffunctions.This was not a correct design, as the proper context might not be available during creation of the Backoff instance. This led to confusion, see for example this discussion.
The changes are split into separate commits for each affected package. See the individual commit messages for details.
I had the changes planned and executed by Claude. I then went through each package one by one, scrutinizing each change and modifying where needed.
Checklist
[ ] I have commented my code, particularly in hard-to-understand areas[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files[ ] I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used thestresstest.shscript to run them under stress conditions and race detector to verify their stability.[ ] I have added an entry in./changelog/fragmentsusing the changelog tool.Disruptive User Impact
None expected, this is an internal API change.
The only theoretically functional change is in the Kafka input implementation, where the
connectDelaynow uses current available context, but previously it usedcontext.Background().How to test this PR locally
I ran unit tests for each modified package.