fix(exporter): back off cluster discovery retries and surface discovery health #7693
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 #7693"
general
weight: 0.35
garrickdabbs
JIRA
ARO-29203
Why
The
aro-hcp-exportercan stop publishing every metric it owns while still serving HTTP 200 on/metricsand passing its liveness probe. Nothing alerts on this state, because the exporter's own output is what disappears.ClusterDiscoveryPoller.Pollreturned before its trailing sleep whenever the Azure Resource Graph discovery query failed. Callers drive it from a barefor { 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.GetDiscoverResultblocks 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/# TYPElines. 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 intodiscoverOnce, andPollnow always waits before returning, short of shutdown. The delay has two regimes: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.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 / sleepTimerather than a fixed constant, becausesleepTime << shiftcan wrap int64 onto a small positive value that passes both the ceiling and the<= 0check. Andwait.Jitteraddsrand 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 makescollectLoopskip 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_totalon 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 == 0now 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). TheEventuallyreturns an error naming the missing metric(s) and inlining the health metrics above, instead of a bare bool — previously a failure said onlyExpected <bool>: ... to be trueafter 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_secondsis 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 ofstopChan.Operational contract
The three discovery metrics are a stable surface suitable for alerting. The intended signal is
time() - exporter_cluster_discovery_last_success_timestamp_secondsexceeding 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_secondsandpublic_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 inobservability/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 intooling/aro-hcp-exporter;test/e2ebuilds and vets clean;make verify-gomega-assertionspasses.-
TestClusterDiscoveryPoller_Poll_SleepsOnError→"0s" is not greater than or equal to "100ms"against the original early-return.-
TestClusterDiscoveryPoller_retryDelay_NoOverflowForHugePollInterval→ the pre-fix shift yields65.536µsfor(1<<48)+1at 17 failures.-
TestJitteredDelay_OverflowFallsBackToBase→ rawwait.Jitter(MaxInt64, 0.2)returns a negative duration on every draw.TestClusterDiscoveryPoller_retryDelay_FlatUntilFirstSuccesspins the cold-start recovery window against the 30m collector budget, so it cannot silently regress past the point where the e2e gives up.-race(no cgo toolchain on the dev machine). Concurrency is by confinement —consecutiveFailuresis touched only byPoll, which runs on a single goroutine; everything shared is either mutex-guarded or a thread-safe Prometheus collector.Dependencies
tooling/aro-hcp-exporter/go.modgainsk8s.io/utilsas an indirect dependency, pulled in byk8s.io/apimachinery/pkg/util/wait(used for backoff jitter). No CI/CD, pipeline, Dockerfile, Makefile or Helm changes.Non-goals
dev-infrastructure/templates/svc-exporter-permissions.bicepgrants 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.clusterTypesadvertisesmgmt-cluster, which the exporter likely cannot see under that RBAC.--kusto-query-interval. The flag is validated but never reachesNewKustoLogsCurrentCollector, which hardcodes 5 minutes. Pre-existing and unrelated to this failure mode; left for a separate change.