Send ETags on monitor reads to skip unchanged responses #3842
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
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.370
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3842"
general
weight: 0.35
tbavelier
What does this PR do?
CONTP-2344
DatadogMonitorandDatadogGenericResource(type: monitor) reads now send the ETag of the last read inIf-None-Match. While a monitor, including its state, is unchanged, Datadog answers304 Not Modifiedwith no body.pkg/datadogclientaddsIf-None-Matchto 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 matchedremoteDefinitionHash. A 304 therefore proves nobody edited the monitor since our last write. Writes, and reads that see a drifted definition, clear it.- 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).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
Etag(JSONetag), notETag: the OpenAPInames_matchrule rejects the mismatch.restriction_policyor 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:The tests fail when the hash check or the state handling is reverted.
make lintis clean.Side-by-side on kind, traced with APM.
v1.31.2as 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
DatadogMonitorand 50 DDGR monitors, with force sync every 2 min and a 60s requeue.trace.http.request.hits{service:datadog-operator} by {env,http.status_code}forresource_name:get_/api/v1/monitor/_numover 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 storedstatus.etagreturned304with 0 bytes. Without it,200with 906 bytes. This held for bothgroup_states=all(DatadogMonitor) andwith_assets=true(DDGR).Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel[1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
🤖 Generated with Claude Code