← Back to Pull requests

datadog_cluster_agent: compute count deltas in the check to survive leader elections #26123

Open
unknown opened this pull request with 348 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 19, 2026 21:25 UTC
Author

What does this PR do?

Computes count deltas in the check instead of in the Agent. Each monotonic_count submission (counters and histogram/summary .count/.sum) is diffed against the series' last value under a key that ignores is_leader, then sent as a count with the current is_leader tag.

Motivation

The check joins is_leader onto every metric. On a leader election every count gets a new tag set. The Agent keys counter state on the full tag set, so it sees a new context and, after the first scrape, flushes its first value, i.e. the counter's lifetime total, as one delta.

Pros

  • is_leader stays on counts; existing queries, monitors and the dashboard keep working.

  • No spike and no lost interval on flips in either direction, including a leader demoted while running.
  • Cons

  • Duplicates the Agent's monotonic-count logic in this check; the two can drift.

  • The check holds state: one entry per count series, dropped after 25h unseen (the Agent's default expiry).
  • Regression risks

  • Wrong deltas if the logic is off. A bug here under- or over-counts every count from the cluster agent. A drop is treated as a reset, as the Agent does once flush_first_value is on.

  • Submission type changes from monotonic_count to count. Backend type is count either way, so queries don't change; anything asserting monotonic submissions (tests, subclasses) does.

  • The upgrade behaves like a check restart. The first scrape after it is a baseline, so about one interval of counts is missing.

  • Not covered: with send_distribution_buckets: true, histograms skip the monotonic_count override, so they keep is_leader but still spike on a flip: admission_webhooks.response_duration, admission_webhooks.cws_response_duration, autodiscovery.poll_duration, autoscaling.workload.queue_latency, autoscaling.workload.queue_work_duration, external_metrics.api_elapsed. In default mode they're covered.
  • Alternatives considered

  • Drop is_leader from counts (first version of this PR). Counts can't be split by leader.

  • Disable flush_first_value. Loses new series' first values; a demoted leader still spikes.
  • Checklist before requesting review

  • I self-reviewed the full diff, and this description matches the final change

  • Tests cover the change, or this description explains why none are needed

  • Automated review comments, including Codex review, were addressed or answered

  • I, the human author, understand this change, can explain it to reviewers, and believe it meets the repository standards
  • 🤖 Generated with Claude Code

    Diff: 348 lines (+261 / -87) across 4 files Reviewer: gabedos Review duration: 4205m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 348 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.350
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #26123"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.4% (MEDIUM) · Higher = larger blast radius
    42.4%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.6% · Safe to merge
    22.6%