[wip]: optimize blackhole sink performance#5042
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Code Review
This pull request replaces the standard Go channel in the blackhole sink with an UnlimitedChannel and updates the BatchCount method to return the actual channel length. A critical issue was identified in the Run loop where the use of a blocking Get() call within a default block could prevent the sink from responding to context cancellation, hindering graceful shutdowns. It is recommended to use GetWithContext(ctx) instead.
| select { | ||
| case <-ctx.Done(): | ||
| return nil | ||
| case event := <-s.eventCh: | ||
| default: | ||
| event, ok := s.eventCh.Get() | ||
| if !ok { | ||
| log.Info("blackhole sink event channel closed") | ||
| return nil | ||
| } | ||
| event.PostFlush() | ||
| } |
There was a problem hiding this comment.
The current implementation of the Run loop has a cancellation issue. The select statement with a default block will immediately call s.eventCh.Get(), which is a blocking call. If the context is cancelled while Get() is waiting for an event, the loop will not exit until an event is received or the channel is closed. This prevents the sink from shutting down gracefully when idle. Using GetWithContext(ctx) allows the loop to respond to context cancellation while waiting for events.
event, ok, err := s.eventCh.GetWithContext(ctx)
if err != nil {
return nil
}
if !ok {
log.Info("blackhole sink event channel closed")
return nil
}
event.PostFlush()Signed-off-by: wk989898 <nhsmwk@gmail.com>
|
[FORMAT CHECKER NOTIFICATION] Notice: To remove the 📖 For more info, you can check the "Contribute Code" section in the development guide. |
What problem does this PR solve?
Issue Number: close #xxx
What is changed and how it works?
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?
Release note