fix(metrics): prevent negative gauge values for buffer metrics - #5467
Open
VedantMadane wants to merge 1 commit into
Open
fix(metrics): prevent negative gauge values for buffer metrics#5467VedantMadane wants to merge 1 commit into
VedantMadane wants to merge 1 commit into
Conversation
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>
VedantMadane
force-pushed
the
fix/buffer-metrics-non-negative-5303
branch
from
August 9, 2026 12:25
a9e5a03 to
50918f2
Compare
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.
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 derivedtotal_queued_size) can go negative when Fluentd core under/over-subtracts during concurrent stage/queue transitions. Those values are mirrored by the Prometheus plugin asfluentd_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:
LocalMetricsgaugesub/decat zero so gauges never go negative under local metrics (the default).statisticsso exporters never publish negative sizes even if an alternate metrics backend returns a negative intermediate value.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:
stage_byte_size/queue_byte_size/total_queued_size) under concurrent buffer operations