Skip to content

[logger] Export dropped-entry count and route raw stderr through the async writer - #1482

Merged
manugarg merged 4 commits into
mainfrom
logger-drop-metrics
Sep 12, 2026
Merged

manugarg merged 4 commits into
mainfrom
logger-drop-metrics

Conversation

@manugarg

Copy link
Copy Markdown
Contributor

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 metric dropped_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_output set, the external and command probes wrote a process's stderr lines straight to os.Stderr. A stalled stderr blocked that relay goroutine, which then blocked the probe's child process once its stderr pipe filled up. In command.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 -race passes for the logger, sysvars, external and command packages, and the full suite passes. The sysvars counter test now asserts the new metric.

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.
@manugarg
manugarg merged commit d1fbb31 into main Sep 12, 2026
13 checks passed
@manugarg
manugarg deleted the logger-drop-metrics branch September 12, 2026 00:48
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.

1 participant