← Back to Pull requests

fix(exporter): back off cluster discovery retries and surface discovery health #7693

Closed
unknown closed this pull request without merging on Nov 12, 2026 11:09 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 16:11 UTC
Author

JIRA


ARO-29203

Why

The aro-hcp-exporter can stop publishing every metric it owns while still serving HTTP 200 on /metrics and passing its liveness probe. Nothing alerts on this state, because the exporter's own output is what disappears.

ClusterDiscoveryPoller.Poll returned before its trailing sleep whenever the Azure Resource Graph discovery query failed. Callers drive it from a bare for { Poll(ctx) } loop, so a single transient failure became an unthrottled retry loop against a quota-limited API — which sustains the very failure it is retrying. GetDiscoverResult blocks until the first successful poll, so in that state every collector stays blocked indefinitely. Collectors serve cached const-metrics, and a collector that emits nothing contributes no output at all, not even # HELP/# TYPE lines. A wedged exporter is therefore byte-for-byte indistinguishable from a healthy one that happens to have nothing to report.

The visible symptom is the dev e2e case "Engineering should be able to retrieve expected metrics from the /metrics endpoint" consuming its full 30-minute budget and failing with Expected <bool>: ... to be true — no indication of which metric was missing or why.

What changes

Retry backoff (cluster_discovery_poller.go). The query body moves into discoverOnce, and Poll now always waits before returning, short of shutdown. The delay has two regimes:

  • Before the first successful discovery — flat at one poll interval. Nothing is published in this state (every collector is parked in GetDiscoverResult), so there is no cached data a longer delay would protect, and escalating only widens the window in which a recovered Resource Graph goes unnoticed. Waiting one full interval already removes the retry storm this backoff exists to prevent.

  • After the first success — doubles per consecutive error, capped at 10 minutes. Here there is cached data to keep serving, so trading freshness for reduced load on a failing API is the right call.
  • Both regimes carry 20% jitter so per-region exporters do not retry in lockstep against shared tenant quota. A zero poll interval stays zero.

    Two overflow paths are guarded, since either one collapses the backoff into the hot loop it exists to prevent. The exponent is bounded by maxBase / sleepTime rather than a fixed constant, because sleepTime << shift can wrap int64 onto a small positive value that passes both the ceiling and the <= 0 check. And wait.Jitter adds rand factor float64(d), which wraps negative near the int64 ceiling, so jitter falls back to the un-jittered base whenever the result lands below it. --collection-interval, previously unvalidated, must now be positive and at most 24h — a non-positive value separately makes collectLoop skip its sleep and spin.

    A query cancelled by shutdown is no longer counted as a discovery failure. Doing so added a synthetic error to exporter_cluster_discovery_errors_total on every rollout and logged an ERROR line on routine graceful shutdown.

    Discovery health signal. The poller owns three plain (non-cached) collectors, registered alongside the existing ones:

    | Metric | Meaning |
    | --- | --- |
    | exporter_cluster_discovery_last_success_timestamp_seconds | Unix time of last successful discovery; stays 0 until the first success |
    | exporter_cluster_discovery_errors_total | Failed discovery queries |
    | exporter_cluster_discovery_clusters | Clusters returned by the most recent success |

    These are deliberately gauges/counters rather than cached const-metrics so they are emitted from process start. last_success == 0 now means "discovery has never succeeded and every collector is blocked behind it", which is the distinction the exporter previously could not express.

    Test diagnostics (test/e2e/exporter_metrics.go). The Eventually returns an error naming the missing metric(s) and inlining the health metrics above, instead of a bare bool — previously a failure said only Expected <bool>: ... to be true after burning its full budget.

    The wait is also split in two, because the two groups of metrics have very different arrival times:

    | Phase | Metrics | Budget |
    | --- | --- | --- |
    | Health | the three exporter_cluster_discovery_ | 5m |
    | Collector | public_ip_count_by_region_service_tag, kusto_logs_age_in_seconds | 30m |

    The health metrics are emitted from process start, so requiring them turns a dropped registration into a failure within minutes rather than at the end of a long timeout. The collector metrics keep the original 30m deliberately: kusto_logs_age_in_seconds is cached only once a Kusto query returns rows, and on a freshly built environment that waits on log ingestion catching up — outside this repo's control, and capable of running well past the collector's own 5m self-throttle. Tightening that budget would trade a real failure mode for CI minutes.

    Port-forward teardown is consolidated into one disconnect() closure, removing a latent double-close of stopChan.

    Operational contract

    The three discovery metrics are a stable surface suitable for alerting. The intended signal is time() - exporter_cluster_discovery_last_success_timestamp_seconds exceeding a few poll intervals, or the metric sitting at 0 well after startup.

    No alerting rule is added here, and that leaves a real gap. The two existing exporter alerts are thresholds on kusto_logs_age_in_seconds and public_ip_count_by_region_service_tag, and both of those metrics disappear completely when discovery is stuck — so there is nothing for the threshold to evaluate and they stay silent. The outage this PR fixes is therefore still one nobody would be paged for. A rule belongs in observability/alerts/, which has its own owners and requires regenerating the deployed bicep, so it is being kept out of this PR and will follow separately.

    Worst-case staleness under sustained Resource Graph failure, once the exporter has discovered at least once*, rises from "retry continuously" to a bounded gap between attempts: a 10-minute base ceiling (maxDiscoveryBackoffBase) plus up to 20% jitter, so at most 12 minutes. The jitter is intentionally not clamped back to the base — the ceiling is where the most exporters are backed off simultaneously, and clamping would land them all on an identical delay, re-synchronising the retries the jitter exists to spread. This trade is intended: the previous behaviour did not produce fresher data, it produced throttling.

    An exporter that has never discovered anything keeps retrying at its normal poll interval, so time-to-recovery from a cold start is bounded by one interval rather than by the backoff ceiling.

    Verification

  • go test ./... passes in tooling/aro-hcp-exporter; test/e2e builds and vets clean; make verify-gomega-assertions passes.

  • New unit tests cover both backoff regimes, backoff reset after success, the health metrics' pre/post-success values, and that a shutdown-cancelled query is not counted as a failure.

  • Each regression test was confirmed to fail against the behaviour it guards, not just to pass against the fix:

  • - TestClusterDiscoveryPoller_Poll_SleepsOnError → "0s" is not greater than or equal to "100ms" against the original early-return.
    - TestClusterDiscoveryPoller_retryDelay_NoOverflowForHugePollInterval → the pre-fix shift yields 65.536µs for (1<<48)+1 at 17 failures.
    - TestJitteredDelay_OverflowFallsBackToBase → raw wait.Jitter(MaxInt64, 0.2) returns a negative duration on every draw.
  • TestClusterDiscoveryPoller_retryDelay_FlatUntilFirstSuccess pins the cold-start recovery window against the 30m collector budget, so it cannot silently regress past the point where the e2e gives up.

  • Not verified locally: -race (no cgo toolchain on the dev machine). Concurrency is by confinement — consecutiveFailures is touched only by Poll, which runs on a single goroutine; everything shared is either mutex-guarded or a thread-safe Prometheus collector.
  • Dependencies

    tooling/aro-hcp-exporter/go.mod gains k8s.io/utils as an indirect dependency, pulled in by k8s.io/apimachinery/pkg/util/wait (used for backoff jitter). No CI/CD, pipeline, Dockerfile, Makefile or Helm changes.

    Non-goals

  • Scoping the discovery query to explicit subscriptions. dev-infrastructure/templates/svc-exporter-permissions.bicep grants the exporter Reader on a single subscription, and Resource Graph already bounds results to subscriptions the caller can read, so an explicit scope would return an identical result set today. It would also mask a future Reader grant on the management subscription, which the current query would pick up for free. Related loose end worth separate tracking: customExporter.clusterTypes advertises mgmt-cluster, which the exporter likely cannot see under that RBAC.

  • --kusto-query-interval. The flag is validated but never reaches NewKustoLogsCurrentCollector, which hardcodes 5 minutes. Pre-existing and unrelated to this failure mode; left for a separate change.

  • Kusto ingestion latency. A freshly provisioned environment may legitimately have no rows inside the collector's 120-minute query window. That is a distinct cause of the same test failure; the diagnostics added here are what distinguish the two.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: garrickdabbs Review duration: 29938m
    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 #7693"
    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: 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