[CONTP-2223] Skip monitor force-sync updates while the remote definition is unchanged #3743
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3743"
general
weight: 0.35
levan-m
What does this PR do?
Skips the periodic force-sync update of a monitor when nobody changed it in Datadog since the Operator last wrote it. Applies to
DatadogMonitorandDatadogGenericResource(monitor).status.remoteDefinitionHash.name,type,query,message,tags,options,priority,restricted_roles,draft_status, plusassetsfor DDGR. State, timestamps and other server-managed fields are excluded. The set-like liststags,restricted_roles,options.notify_byandoptions.renotify_statusesare sorted before hashing.lastForceSyncTimeadvances. Otherwise the existing update path runs and stores the new hash.status.currentHash. The stored hash is cleared before every update attempt, so a failed update never leaves a hash that would skip the retry.remoteDefinitionHasherinterface. Its force-sync GET addswith_assets=true. It also hashes every top-leveljsonSpeckey. If one of them is missing from the response, no hash is stored and the monitor updates on every force sync. Specs that setrestriction_policykeep updating on every force sync, since the policy is not part of the monitor definition. Other resource types are unchanged.Motivation
CONTP-2223: unchanged monitors receive a GET + validate + PUT every force sync (hourly by default).
| Controller | Unchanged monitor, before | After |
| --- | --- | --- |
| DatadogMonitor | 1 GET + 1 validate POST + 1 PUT | 1 GET |
| DDGR monitor | 1 GET + 1 PUT | 1 GET |
Additional Notes
This is an alternative to the force-sync part of #3667 and to #3731, which compare the spec's fields with the remote monitor instead of tracking whether the remote monitor changed. Main differences:
| | #3667 / #3731 (field comparison) | This PR (remote hash) |
| --- | --- | --- |
| Question asked | Do the fields set in the spec match the remote monitor? | Did the remote monitor change since the Operator last wrote it? |
| Out-of-band edits to fields the spec does not set (e.g.
optionssub-fields) | Not reverted unless another field drifts | Reverted, as today || New fields or defaults returned by Datadog | Ignored | One update per monitor, then a new hash |
| A field that differs between write responses and reads | n/a | Updates on every force sync (no drift, only lost savings) |
| First force sync after upgrade | Skipped if matching | One update, then skipped |
| State and API changes | None (#3667);
int64priority andomitzeroset fields (#3731) | Additive status field || DDGR
restriction_policy| Compared (#3731) | Always updates |Behavior: what a force sync reverts is unchanged.
optionsis replaced as a whole by an update, so edits to its sub-fields are reverted as before. Top-level fields the update does not send are kept as before; editing one costs one update, after which it becomes part of the stored hash.Found during live testing:
monitor_idin each asset while reads do not. It is excluded from the hash.restricted_rolesin the order sent, while reads return them in another order. Sorting the set-like lists keeps the hash recorded at creation equal to the next read.tags,notify_byandrenotify_statuseskept the sent order in all responses and reads, and are sorted for consistency.DatadogMonitorcreate requests now includespec.restrictedRoles. Previously they were omitted and applied by the first force-sync update about a minute after creation; with that update skipped they would never be applied. An empty list is not sent, since the API rejects it.For DDGR, response-only fields left in
jsonSpec(such asoverall_stateormodified) change the hash without an edit and cause updates, at most once per force sync as today; the docs ask to keep them out ofjsonSpec. Numbers in fields the SDK does not know are hashed exactly rather than rounded tofloat64.The new status field is optional. Existing resources need no migration; each gets one update on its first force sync after upgrade.
Minimum Agent Versions
Not applicable; this only changes the Operator's Datadog API usage.
Agent: N/A
Describe your test plan
Unit tests:
MonitorDefinitionHash: state,modifiedand the order of tags, restricted roles,notify_byandrenotify_statusesdo not change the hash; message,optionssub-fields, priority, restricted roles, draft status, tags and assets do;monitor_idin assets is ignored.restriction_policyalways updates. Forcing the skip condition to false makes these tests fail.jsonSpecfield unknown to the SDK is repaired with one update; ajsonSpecfield missing from the response disables the skip; large integers keep distinct hashes.buildMonitorbuilds, and everyDatadogMonitorSpecfield must map to a hashed field.go test -race ./internal/controller/... ./pkg/controller/... ./api/...andmake lintpass.Live test on kind against the real Datadog API, with 1-minute force syncs, two
DatadogMonitors and one DDGR monitor with an asset:modifiedtimestamp did not change.The kind run covered the changes up to the asset fix. The later changes (sorted set-like lists, restricted roles on create, DDGR
jsonSpecfields, guard tests) are covered by unit tests; the first two were also checked with the API directly.List ordering, checked with the API directly: four monitors with 30 shuffled tags, 3 restricted roles, 6
notify_bykeys and 3renotify_statuses, each read 12 times over 4 minutes and then updated with every list reshuffled. Onlyrestricted_rolescame back in a different order from the create response; reads were consistent with the update response.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
[CONTP-2223]: https://datadoghq.atlassian.net/browse/CONTP-2223?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ