← Back to Pull requests

CASCL-1724: requeue DPA status write on conflict #55608

Closed
unknown closed this pull request without merging on Sep 03, 2026 16:54 UTC
View on GitHub
unknown unknown commented on Aug 28, 2026 17:53 UTC
Author

<!-- dd-meta {"pullId":"00000000-0000-0000-0000-000000000000","source":"chat","resourceId":"bec0c19f-5cc4-4b0a-9eac-ff0d2eef1a7f","workflowId":"98db4137-81d8-438f-9601-eeb142d96cc2","codeChangeId":"98db4137-81d8-438f-9601-eeb142d96cc2","sourceType":"chat"} -->

What does this PR do?

Makes the Cluster Agent DatadogPodAutoscaler (DPA) controller requeue the reconcile when a status write fails instead of silently dropping the update. updateAutoscalerStatusAndUpsert now returns an autoscaling.ProcessResult and sets Requeue when updatePodAutoscalerStatus returns an error (e.g. an HTTP 409 conflict from a stale cached resourceVersion). The two call sites propagate that result. The spec-write path already requeued on error, so no change was needed there.

Motivation

CASCL-1724. A customer reported a DPA that stopped honoring its configured metric and continuously scaled down, with a 409 conflict logged on the leader every ~5 minutes.

Root cause: the status write reuses the resourceVersion read from the informer cache (ObjectMeta: podAutoscaler.ObjectMeta); when that value is stale, UpdateStatus returns 409. In the normal scaling path the resulting error was returned but the reconcile result stayed NoRequeue, so the key was forgotten and only retried on the next informer event (the ~5-minute resync explains the cadence).

Fix approach (idiomatic controller pattern): on a status-write error, requeue and let the reconcile restart. The conflict is caused by a concurrent successful write to the object, which is itself delivered to the informer as a watch event, so a subsequent reconcile reads the up-to-date object from the cache and the write succeeds. Retries are bounded by the workqueue rate-limiter and Process()'s maxRetry. This avoids adding live API reads inside the write path.

Scope note validated during investigation: the 409 does not by itself cause the reported "CPU-only fallback". On a failed status write the controller still upserts the fresh recommendation into its internal store, and horizontal scaling runs before the status write, so the configured metric is still applied. The fallback is driven by main-recommendation staleness and is tracked separately; this PR fixes the conflict handling only.

Describe how you validated your changes

Added unit tests in controller_test.go driving updateAutoscalerStatusAndUpsert against a fake dynamic client:

  • TestUpdateAutoscalerStatusAndUpsertRequeuesOnConflict: a 409 on the status subresource makes the reconcile return Requeue and surface the error, and the fresh recommendation is still persisted to the store.

  • TestUpdateAutoscalerStatusAndUpsertNoConflict: a successful status write does not requeue (steady state preserved).
  • Ran the full pkg/clusteragent/autoscaling/workload package test suite (go test -tags 'test kubeapiserver') — all green — and gofmt.

    Additional Notes

  • Recovery relies on the informer cache being refreshed by the watch event from the write that caused the conflict; no extra API reads are added. A genuinely stale/frozen cache with no further writes would instead be recovered by the informer's own relist.

  • Supersedes the earlier retry.RetryOnConflict + live-read implementation on this branch, per review feedback.
  • ---

    PR by Bits - View session in Datadog

    Comment @datadog to request changes

    Diff: 434 lines (+325 / -109) across 5 files Reviewer: AlexanderYastrebov Review duration: 8581m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 434 lines diff across 5 files
    0.45
    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.363
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #55608"
    general weight: 0.35
    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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    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: 17.8% · Safe to merge
    17.8%