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

Better handling of shutdown in BatchLogProcessor #2581

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas commented Jan 31, 2025

Another attempt at #2462
The key change/idea here is

  1. Do not perform any unnecessary check in hot path that unnecessarily punishes normal users
  2. Rely on alternative mechanisms to determine state.

Specifically, in this PR, BatchLogProcessor no longer keeps track of "is_shutdown" in the AtomicBool and check it in every hot path. (1 above).
Instead, it relies on the well known error from the Channel ("failed to send message to channel as no receiver exists") to determine that Shutdown is already performed (2 above).

No change in behavior, just avoid an unnecessary check in hot path. (the perf impact is minimal (couple of ns) but every ns counts)

If this is generally agreed, we need to replicate this idea everywhere.

@scottgerring Unfortunately this touches Log::Shutdown area (these changes were sitting in me for quite a while!!). I hope the changes here will allow you to return better, targeted Result as we agreed. Currently it sticks with LogError for everything. If it turns out to be merge nightmare, I am happy to abandon this one, and re-attempt it after you fix Result handling. (This has no public API change, so can be done later too)

@cijothomas cijothomas requested a review from a team as a code owner January 31, 2025 19:03
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 30.76923% with 54 lines in your changes missing coverage. Please review.

Project coverage is 79.5%. Comparing base (9dfcff1) to head (34bf126).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-sdk/src/logs/log_processor.rs 30.7% 54 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #2581     +/-   ##
=======================================
- Coverage   79.6%   79.5%   -0.1%     
=======================================
  Files        118     118             
  Lines      22486   22490      +4     
=======================================
- Hits       17906   17888     -18     
- Misses      4580    4602     +22     

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

// If the control message could not be sent, emit a warning.
otel_debug!(
name: "BatchLogProcessor.ForceFlush.ControlChannelFull",
message = "Control message to flush the worker thread could not be sent as the control channel is full. This can occur if user repeatedily calls force_flush without finishing the previous call."
Copy link
Member

@lalitb lalitb Jan 31, 2025

Choose a reason for hiding this comment

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

I think can also happen if user repeatedly calls the shutdown from different threads, and the first shutdown message is not yet processed, so channel is still intact :)

Copy link
Member Author

Choose a reason for hiding this comment

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

that is a good point. Let me modify error message to include that.

Copy link
Member Author

Choose a reason for hiding this comment

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

will do in separate PR to keep this merged asap.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM. Nicely done.

@cijothomas cijothomas merged commit a1860eb into open-telemetry:main Jan 31, 2025
20 of 21 checks passed
@cijothomas cijothomas deleted the cijothomas/blrp-shutdown branch January 31, 2025 19:36
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.

2 participants