← Back to Pull requests

Send ETags on monitor reads to skip unchanged responses #3842

Closed
unknown closed this pull request without merging on Nov 26, 2026 09:29 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 19:50 UTC
Author

What does this PR do?

CONTP-2344

DatadogMonitor and DatadogGenericResource (type: monitor) reads now send the ETag of the last read in If-None-Match. While a monitor, including its state, is unchanged, Datadog answers 304 Not Modified with no body.

  • Transport: a transport in pkg/datadogclient adds If-None-Match to GETs from the request context, because the generated API methods can't set headers.

  • status.etag: records the ETag of the last read whose definition still matched remoteDefinitionHash. A 304 therefore proves nobody edited the monitor since our last write. Writes, and reads that see a drifted definition, clear it.

  • On 304: force syncs skip the update, the spec-change existence check counts the monitor as existing, and state polls keep the current state.

  • State consistency:

  • - A 200 force-sync read also records the monitor's state, so a later 304 can't leave a stale or empty state.
    - State polls send no ETag until a state has been polled (empty or PollingDisabled).
  • DDGR monitor reads: all now request with_assets=true, so force syncs and state polls share one ETag.
  • Motivation

    Force syncs and state polls re-download every monitor on every cycle even when nothing changed. With ETags, unchanged monitors cost a bodyless 304.

    Additional Notes

  • Field name. The status field is Etag (JSON etag), not ETag: the OpenAPI names_match rule rejects the mismatch.

  • No ETag for some monitors. Monitors without a definition hash never store an ETag, so they're read in full every time as before. That covers DDGR monitors with restriction_policy or fields Datadog doesn't return.
  • Minimum Agent Versions

    N/A (operator-only change).

    Describe your test plan

    Unit tests. New fake Datadog APIs return body-derived ETags and honor If-None-Match. They cover:

  • 304 on force syncs and state polls

  • a state change producing a new ETag

  • reverting an out-of-band edit that a state poll observed

  • spec changes

  • the state-recording cases above
  • The tests fail when the hash check or the state handling is reverted. make lint is clean.

    Side-by-side on kind, traced with APM.

  • Setup: two clusters, one running this branch and one running v1.31.2 as the baseline.

  • - Both binaries were built with Orchestrion so Datadog API client calls are traced, and a DatadogAgent with APM ran in each cluster.
    - Each cluster ran 50 DatadogMonitor and 50 DDGR monitors, with force sync every 2 min and a 60s requeue.
  • Result: trace.http.request.hits{service:datadog-operator} by {env,http.status_code} for resource_name:get_/api/v1/monitor/_num over 30 minutes:
  • | | GET 304 | GET 200 |
    |---|---|---|
    | this branch | 2,898 | 3 |
    | v1.31.2 | 0 | 2,900 |

    The baseline also made 1,433 PUTs and 721 validates in that window, against 1 each for this branch. That gap comes from the force-sync skip already on main (remoteDefinitionHash), not from this PR.

    Against the real API:

  • GET /api/v1/monitor/<id> with the stored status.etag returned 304 with 0 bytes. Without it, 200 with 906 bytes. This held for both group_states=all (DatadogMonitor) and with_assets=true (DDGR).

  • After an out-of-band edit through the API, the next force sync got a 200 and reverted the edit; the following force sync was back to 304.
  • Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies

  • PR has a milestone or the qa/skip-qa label

  • All commits are signed (see: [signing commits][1])
  • [1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

    🤖 Generated with Claude Code

    Diff: 484 lines (+363 / -121) across 6 files Reviewer: tbavelier Review duration: 2258m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 484 lines diff across 6 files
    0.47
    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.370
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3842"
    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: 47.3% (MEDIUM) · Higher = larger blast radius
    47.3%
    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: 18.7% · Safe to merge
    18.7%