Repository navigation
[logger] Export dropped-entry count and route raw stderr through the async writer - #1482
Merged
Merged
Conversation
logger.DroppedEntries() exposes the counter from the async stderr writer added in #1481, and sysvars exports it as "dropped_log_entries". During the incident that motivated #1481, metrics kept flowing while the logs were dark, so this counter is what makes a stderr stall visible. Also adds logger.Stderr(), used by the next commit.
With raw_stderr_output set, the external and command probes relayed a process's stderr lines straight to os.Stderr. A stalled stderr blocked that relay goroutine, which in turn blocked the probe's child process once its stderr pipe filled up; in command.go, the probe run also waits for that goroutine. Use logger.Stderr() so these writes are queued like all others.
DroppedEntries() and WaitForStderr() went through asyncStderr(), so merely observing the writer created it and started its drain goroutine. Sysvars polls DroppedEntries() every export interval, which meant a process whose loggers all use WithWriter got a goroutine that would never write anything. stderrWriter is now an atomic.Pointer that these two only read: they report 0 and return immediately when nothing has logged to stderr yet. Stderr() and the logging path still create the writer on demand. Also adds tests for the observers and Stderr(), which the Sonar coverage gate flagged as uncovered.
Nothing covered RawStderrOutput, so the switch to logger.Stderr() shipped untested. The new test checks that the child's stderr lines still reach ProcessStderr and that Execute completes.
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.
Follow-up to #1481, which made writes to stderr non-blocking. Two loose ends from that PR.
Export the drop count
logger.DroppedEntries()exposes the counter from the async writer, and sysvars exports it as the cumulative metricdropped_log_entries.During the incident that motivated #1481, metrics kept flowing while the logs were dark. That makes this counter the signal that would have shown the stall: log entries are only dropped when stderr writes are blocked and the 4 MiB queue is full.
Raw process stderr
With
raw_stderr_outputset, the external and command probes wrote a process's stderr lines straight toos.Stderr. A stalled stderr blocked that relay goroutine, which then blocked the probe's child process once its stderr pipe filled up. Incommand.go, the probe run waits on that goroutine as well, so the stall reached the probe directly.Both sites now write to
logger.Stderr(), so these lines are queued like every other log write, and they no longer interleave mid-line with logger output.Testing
go test -racepasses for the logger, sysvars, external and command packages, and the full suite passes. The sysvars counter test now asserts the new metric.