← Back to Pull requests

feat: improve Cosmos DB RU and operation diagnostics (ARO-29599) #6929

Closed
unknown closed this pull request without merging on Sep 15, 2026 02:58 UTC
View on GitHub
unknown unknown commented on Sep 12, 2026 15:08 UTC
Author

Jira: https://redhat.atlassian.net/browse/ARO-29599

Why

CI Cosmos platform metrics show throughput pressure, but not which controllers, informers, or calling services are responsible. Once an ephemeral test environment is gone, that missing attribution makes expensive reconciliation, relists, polling, and charged errors difficult to diagnose.

This adds client-side RU attribution and adds three targeted cost/throttling views to the existing gather-observability artifacts, on top of the three pre-existing Azure platform views (left untouched). It does not change controller reconciliation behavior or attempt to optimize the expensive controllers the charts reveal.

What

  • Record x-ms-request-charge once per HTTP attempt through a shared Azure SDK per-retry policy, including retries, charged failures, query pages, and changefeed responses, in cosmos_request_units_total.

  • Also record every attempt that received a response — regardless of charge — in a second counter, cosmos_requests_total. A 429 is typically rejected before Cosmos DB does any work and usually reports a zero or absent charge, so RU cost alone cannot answer "how often was this source throttled"; the count counter can.

  • Attribute requests to explicit informer context, otherwise existing controller context, otherwise unattributed. Preserve list/watch cancellation and deadlines and distinguish ActiveOperations from AllOperations.

  • Add three client Prometheus views to the existing "CosmosDB Metrics" panel: total RU/s per container; the top ten (source-kind, source) RU cost drivers per container across every operation/status combined; and the top ten (source-kind, source) 429-count drivers per container. Ranking spans controller/informer/unattributed together in one chart rather than splitting per kind, so the actual top contributor is visible without already knowing which kind dominates.

  • Rank each top-ten view with a topk whose lookback is resolved (in promql.go, via a __REPORT_RANGE__ placeholder) to the report's exact [start,end] duration in milliseconds, not a hardcoded window — so a spike anywhere in the report surfaces its source, without ever looking further back than the report's own start.

  • Deduplicate HA scrapes before summing pods and case-insensitive manifests-mc-* containers; give each container group its own chart and legend; always retain explicit calling_service labels, distinct from the actual Cosmos cosmosdb_container metric label.

  • Document both counters' accounting semantics, attribution precedence, and SDK background activity that cannot honestly be attributed.
  • Testing

    Passed locally:

    # internal/
    go test ./database/cosmosstorage/... ./database/informers/... -count=1
    
    # test/
    go test ./cmd/aro-hcp-tests/gather-observability -count=1
    

  • Regression coverage for retry accounting (including that cosmos_requests_total counts each throttled retry once even when cosmos_request_units_total reports ~0 for it), concurrent attribution, malformed/missing charges, response/error preservation, request classification, real informer pagination/relist/changefeed contexts, and the __REPORT_RANGE__ placeholder resolving to an exact millisecond-precision duration (not rounded up past the report's start).

  • TestLoadQueriesConfigEmbedded parses the real embedded queries.yaml and asserts structural invariants (unique/non-empty panel titles, non-empty query lists, no CosmosDB panel split) rather than pinning specific chart titles, so it doesn't need updating on every legitimate chart edit.

  • Formatting and whitespace checks passed.
  • Visual evidence

    Outstanding. The dashboard design changed substantially after the initial review pass (consolidated from eight per-source-kind views down to three unified ones; added the count counter and its throttling view; fixed the ranking window), and the Chromium/PNG capture done for the earlier eight-view design no longer reflects what's in this PR. Fresh screenshots of the current three views, plus the untouched three platform views, are needed before merge per the repo's screenshot requirement for dashboard/metrics changes.

    The PR is currently ready, not draft.

    Special notes for your reviewer

  • Raw metric container values retain their exact names/casing. Manifest grouping and calling_service naming are query/presentation behavior only.

  • Existing Azure platform charts remain per physical container; utilization percentages are not summed across manifest containers.

  • cosmos_request_units_total is charged cost, not request count, error rate, or provisioned throughput; cosmos_requests_total is a plain per-attempt count for when cost isn't the right lens (e.g. throttling). SDK background partition-range refreshes remain explicitly unattributed on both.

  • No resource/subscription/document/activity IDs are added as metric labels; no credential pipeline instrumentation.

  • Security self-review covered every changed file. No workflow, pipeline, Makefile, Dockerfile, dependency, or executable-script changes. The CI report template/query changes contain no new external downloads or executable commands.

  • Suggested reviewers after CI: @stevekuznetsov for storage/informer attribution and gather-observability, based on ownership history.
  • PR Checklist

  • PR is scoped to a single task (no mixed concerns)

  • Title follows Conventional Commits format

  • Summary explains the Why behind the change

  • Linked to relevant ticket/issue

  • Screenshots included (dashboards/UI changes)

  • Self-reviewed the diff

  • CI/CD checks are passing (ignore Tide)

  • Draft PR used while publication gates are outstanding (PR is currently ready)

  • Commit history is clean

  • Tricky code blocks are commented

  • Specific reviewer tagged as a suggestion; review request deferred until CI passes

  • All comment threads resolved before merge
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: stevekuznetsov Review duration: 3589m
    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
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #6929"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%
    Repository