← Back to Pull requests

fix(metrics): export-only clamp for buffer statistics #5467

Closed
unknown closed this pull request without merging on Aug 31, 2026 08:46 UTC
View on GitHub
unknown unknown commented on Aug 09, 2026 12:15 UTC
Author

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 transiently negative when Fluentd core under/over-subtracts during concurrent stage/queue transitions (the deferred @stage_size_metrics.add after chunk unlock vs enqueue_chunk's sub — see #2712 / #2734). 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.

Clamping the gauge store on sub/dec is the wrong fix: it turns a self-correcting transient negative into a permanent over-count, so Buffer#storable? (which reads the raw gauge) eventually refuses every write. Thanks @Watson1978 for catching that.

This PR takes an export-only approach:

1. Leave LocalMetrics gauge sub/dec/set semantics unchanged (negatives still allowed so the deferred-add race can self-heal).
2. Clamp stage/queue sizes to >= 0 only when building statistics (the path Prometheus and the monitor agent consume).
3. Clamp available_buffer_space_ratios to [0, 100] when counters overshoot total_limit_size, and treat total_limit_size == 0 as 0% free without dividing (no NaN / no dead NaN guard).

Docs Changes:
None

Release Note:

  • buffer: clamp exported buffer size metrics to non-negative values
  • General Checklist:

  • I have read and followed CONTRIBUTING.md

  • tests pass (CI)

  • DCO signed-off
  • Tests:

  • test/plugin/test_buffer.rb #statistics: negative underlying gauges export as 0; overshoot clamps ratio to 0; total_limit_size == 0 does not raise and ratio stays finite.
  • Diff: 228 lines (+171 / -57) across 2 files Reviewer: VedantMadane Review duration: 31471m
    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
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.0% (MEDIUM) · Higher = larger blast radius
    37.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.6% · Safe to merge
    14.6%
    Repository