[chore][pkg/stanza] Fix the bug that the log emitter might hang when the receiver retry indefinitely #37159
+17
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I was exploring options for backpressure the pipeline when the exporter fails. Inspired by #29410 (comment), I realized that I could enable the
retry_on_failure
on the receiver side, and have it retry indefinitely by settingmax_elapsed_time
to 0.With this config, the consumer will be blocked at the
ConsumeLogs
func inconsumerretry
when the exporter fails to consume the logs:opentelemetry-collector-contrib/internal/coreinternal/consumerretry/logs.go
Line 35 in 12551d3
The func
flusher()
from theLogEmitter
starts a loop and call theconsumerFunc
withcontext.Background()
. When theConsumeLogs
is blocked by the retry, there is no way to cancel the retry, thus theLogEmitter
will hang when I try to shut down the collector.In this PR, I created a ctx in the
Start
func, which will be cancelled later in theShutdown
func. The ctx is passed to the flusher and used for the flush in everyflushInterval
. However, I have to swap it with another ctx with timeout during shutdown to flush the remaining batch out one last time. That's the best approach I can think of for now, and I'm open to other suggestions.