test(amp): defensive retry-on-empty for AMP query path - #736
Conversation
al2:selinux_amp_test (EC2SELinuxTests) is a top flaky job in recent CI run-history (roughly 9 of 16 observations, ~56 percent). It provisions a real AMP workspace via Terraform then validates each metric with a single avg_over_time(m[3m]) instant query and no retry, so a datapoint not yet queryable due to remote-write propagation fails the whole suite (TestGroupResult is all-or-nothing). Add queryAMPMetricsWithRetry wrapping queryAMPMetrics with 3 attempts 30s apart, retrying on request errors and empty result sets. There is no explicit query window to recompute: each attempt is a fresh instant query evaluated at AMP server-now, so the 3m lookback advances on its own. On exhaustion the last response or error is returned unchanged so validateMetric's existing empty-result check still fails the test genuinely. Verified: gofmt clean; go test -c -tags=integration ./test/amp/ compiles on go 1.23.12 (matches CI ~1.23.0). Not exercised in CI.
|
Closing this in favor of aws/amazon-cloudwatch-agent#2233. This PR hardened the AMP query path (retry-on-empty) on the theory that The Go test binary never runs, so the query path this PR touches is never The real fix is aws/amazon-cloudwatch-agent#2233, which adds a Closing this since it targets no observed failure. Happy to reopen if the query |
Scope (updated after root-cause investigation)
This is a defensive hardening of the AMP query path. It does not fix the current
al2:selinux_amp_testfailures. See "Why this does not fix the current flake" below.What this changes
validateMetricissued a single PromQL instant query (avg_over_time(m[3m])) viaqueryAMPMetricswith no retry, and failed the metric if the result set was empty. This addsqueryAMPMetricsWithRetry(3 attempts, 30s apart), retrying on both request errors and empty result sets, and switchesvalidateMetricto use it.avg_over_timelookback advances on its own. There is no explicit start/end window to recompute.This guards against remote-write propagation delay: once a workspace exists and the agent is publishing, a metric can briefly be un-queryable and land moments later.
Why this does not fix the current flake
Investigation of PR aws/amazon-cloudwatch-agent#2225's failing
al2:selinux_amp_testjobs (run 30667884230 attempts 1 and 9, run 30764785279 attempt 2, run 30995079411 attempt 1 on the current head) shows every failure is a Terraform provisioning error, upstream of the query path:terraform applyfails ataws_prometheus_workspacecreation, so the Go test binary never runs andqueryAMPMetricsis never reached. No query-path log lines and no 429/403/throttle appear in any failed log. That is an infrastructure service-quota issue (the region is at the 75 AMP-workspace cap), addressed by raising the quota and/or ensuring workspaces are reliably torn down, not by this test-code change.Status
Kept open as an independent, low-risk query-path improvement. It is not a fix for the quota-driven flake and should not be treated as one.
Verification
gofmtcleango test -c -tags=integration ./test/amp/compiles on go 1.23.12 (matches CI)