fix(log): drain loki hook channel on shutdown - #6233
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
lokiHook.Listen's ctx.Done path pushed only entries already copied into its buffer and skipped anything still queued in the channel, so a shutdown could lose a tail of --out loki logs. Drain the channel before the final push, matching the file hook's shutdown behavior. Co-authored-by: Inanc Gumus <github@inanc.io>
|
|
1 similar comment
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
Drain
lokiHook's buffered channel onctxcancel before the final push, so--out lokidoes not lose a tail of logs thatFirealready accepted.Extracts the per-entry buffering into an
appendEntryhelper (same logic as before) and reuses it from a non-blockingdrainQueuedon the shutdown path — matching how the file log hook already drains.Why?
Listen'sctx.Done()branch pushed only entries already copied into itsmsgsbuffer. Anything still sitting inh.chwas dropped.Trigger: queue log entries into the hook channel, then cancel the listen context before the run loop drains them (common at test end when many lines are still buffered).
Impact: silent loss of the final batch of
--out lokilogs.TestLokiHookDrainsQueuedEntriesOnShutdownfails on unpatched code (all 100 pre-queued messages missing) and passes with this drain.Checklist
make check) and all pass.Checklist: Documentation (only for k6 maintainers and if relevant)
Related PR(s)/Issue(s)
--out lokiportion now; Fix loki shutdown log loss and surface dropped cloud logs #6232 can keep the cloud dropped-log notice that depends on Stream --local-execution logs to Grafana Cloud #6171'sDrain()path.Validation
go test ./internal/log/ -count=1passes