fix(metrics): export-only clamp for buffer statistics #5467
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 228 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.325
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5467"
general
weight: 0.35
VedantMadane
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 transiently negative when Fluentd core under/over-subtracts during concurrent stage/queue transitions (the deferred@stage_size_metrics.addafter chunk unlock vsenqueue_chunk'ssub— see #2712 / #2734). 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.Clamping the gauge store on
sub/decis the wrong fix: it turns a self-correcting transient negative into a permanent over-count, soBuffer#storable?(which reads the raw gauge) eventually refuses every write. Thanks @Watson1978 for catching that.This PR takes an export-only approach:
1. Leave
LocalMetricsgaugesub/dec/setsemantics unchanged (negatives still allowed so the deferred-add race can self-heal).2. Clamp stage/queue sizes to
>= 0only when buildingstatistics(the path Prometheus and the monitor agent consume).3. Clamp
available_buffer_space_ratiosto[0, 100]when counters overshoottotal_limit_size, and treattotal_limit_size == 0as 0% free without dividing (no NaN / no dead NaN guard).Docs Changes:
None
Release Note:
General Checklist:
Tests:
test/plugin/test_buffer.rb#statistics: negative underlying gauges export as 0; overshoot clamps ratio to 0;total_limit_size == 0does not raise and ratio stays finite.