Skip to content

fix(metrics): prevent negative gauge values for buffer metrics - #5467

Open
VedantMadane wants to merge 1 commit into
fluent:masterfrom
VedantMadane:fix/buffer-metrics-non-negative-5303
Open

fix(metrics): prevent negative gauge values for buffer metrics#5467
VedantMadane wants to merge 1 commit into
fluent:masterfrom
VedantMadane:fix/buffer-metrics-non-negative-5303

Conversation

@VedantMadane

@VedantMadane VedantMadane commented Aug 9, 2026

Copy link
Copy Markdown

Which issue(s) this PR fixes:
Fixes #5303

What this PR does / why we need it:
Buffer size gauges (stage_byte_size, queue_byte_size, and derived total_queued_size) can go negative when Fluentd core under/over-subtracts during concurrent stage/queue transitions. Those values are mirrored by the Prometheus plugin as fluentd_output_status_buffer_total_bytes / fluentd_output_status_buffer_stage_byte_size, which is what #5303 reports.

@Watson1978 noted on the issue that the Prometheus plugin only mirrors Fluentd core counters; the drift lives in core (related to the class of races addressed in #2712 / #2734).

This PR:

  1. Clamps LocalMetrics gauge sub/dec at zero so gauges never go negative under local metrics (the default).
  2. Clamps stage/queue sizes when exporting buffer statistics so exporters never publish negative sizes even if an alternate metrics backend returns a negative intermediate value.
  3. Adds unit tests for non-negative gauge sub/dec.

This does not attempt a full re-audit of every buffer lock path; it stops the user-visible bad export and prevents counter corruption from cascading.

Docs Changes:
N/A

Release Note:

  • Fix negative buffer size metrics (stage_byte_size / queue_byte_size / total_queued_size) under concurrent buffer operations

LocalMetrics sub/dec could drive buffer size gauges below zero when
racey buffer accounting under/over-subtracted (issues fluent#5303, fluent#2712).
That produced negative Prometheus series such as
fluentd_output_status_buffer_total_bytes.

Clamp gauge sub/dec at zero in LocalMetrics, and clamp stage/queue
sizes when exporting buffer statistics.

Fixes fluent#5303

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
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.

Buffer size metrics showing negative values

1 participant