← Back to Pull requests

fix: preserve remote resource IDs on stale status conflicts #3654

Closed
unknown closed this pull request without merging on Oct 23, 2026 15:00 UTC
View on GitHub
unknown unknown commented on Oct 23, 2026 11:38 UTC
Author

What does this PR do?

Preserve a newly persisted remote resource ID when an ID-less status write conflicts in DatadogMonitor or DatadogGenericResource. The retry keeps the entire newer status instead of replacing it with stale error status.

Motivation

A reconcile can read cached status without an ID after a successful create has already persisted one. A duplicate-create 400 followed by a Kubernetes 409 could then overwrite the stored ID, breaking subsequent updates and deletion.

Additional Notes

  • Recreation still works: an existing CR references monitor 12345, which is deleted through the Datadog UI. The operator detects the missing monitor and recreates it; the new ID is persisted. If an update-time 404 first requires clearing the old ID, that reset remains allowed when the fetched ID matches the ID the reconcile originally observed. The guard does not block successful writes containing the new ID.

  • Cached reads are retained with no additional API requests. This fix does not address other existing retry limitations or prevent the preceding stale create attempt.
  • Minimum Agent Versions

    Agent: N/A
    Cluster Agent: N/A

    Describe your test plan

    Manual QA steps (executed on kind cluster local-k8s with the PR image; backend verification/deletion used the Datadog HTTP API):

    1. Deploy with valid Datadog credentials, DD_MONITOR_CONTROLLER_ENABLED=true, DD_GENERIC_RESOURCE_CONTROLLER_ENABLED=true, and DD_MONITOR_MAX_CONCURRENT_RECONCILES=3.
    2. Create a uniquely named monitor using examples/datadogmonitor/metric-monitor-test.yaml in a watched namespace:

       kubectl apply -f <monitor-manifest>
       kubectl get datadogmonitor <name> -n <namespace> -o yaml
       

    Verify status.id is nonzero, status.primary is true, and the monitor exists in the Datadog UI. Record its ID.
    3. Change spec.message and reapply. Verify the message changes on the same monitor and status.id remains unchanged; no second monitor is created.
    4. Delete that monitor through the Datadog UI or DELETE /api/v1/monitor/{id} while keeping the CR. Change spec.message again and reapply to trigger reconciliation. Verify the operator recreates the monitor, persists a new nonzero ID, and later reconciles retain it. Change the message once more and confirm the recreated monitor is updated with the same new ID.
    5. Delete the CR:
       kubectl delete datadogmonitor <name> -n <namespace>
       

    Verify the CR is removed without a stuck finalizer and the recreated monitor disappears from Datadog.
    6. (Optional) Repeat creation, message update, backend deletion/recreation, and CR deletion with examples/datadoggenericresource/monitor-sample.yaml (substitute valid constituent monitor IDs in its composite query and choose a unique monitor name). Verify status.id is populated, status.syncStatus becomes OK, updates retain the ID, recreation persists a new ID, and CR deletion removes the remote monitor.

    Live race checks completed:

  • Controlled replay of saved ID-less snapshots through each reconciler, with the deployed manager paused: real Datadog duplicate-create 400 followed by real Kubernetes status-update 409. Both controllers preserved the complete newer status and ID without another write.

  • Controlled monitor update-time 404 plus a real status conflict: the intentional reset to ID 0 was persisted; restarting the deployed operator recreated the monitor and persisted a new ID.

  • Five small batches (1, 3, 5, 3, 1 monitors) with three workers: no observed ID loss or spontaneous duplicate-create error. To retry the timing-dependent case, repeat these batches with fresh names and distinct queries while watching IDs and logs; absence of failure is inconclusive.

  • All 17 QA CRs and all 20 associated remote monitors were removed and their absence verified through Kubernetes and the Datadog API.
  • 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

    Diff: 536 lines (+402 / -134) across 6 files Reviewer: gabedos Review duration: 202m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 536 lines diff across 6 files
    0.48
    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.376
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3654"
    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.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    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.9% · Safe to merge
    18.9%