Skip to content

prometheus: fix race between metric export and test fetch#1051

Merged
sknat merged 1 commit into
masterfrom
abasu-fix-prom
Jun 23, 2026
Merged

prometheus: fix race between metric export and test fetch#1051
sknat merged 1 commit into
masterfrom
abasu-fix-prom

Conversation

@aritrbas

Copy link
Copy Markdown
Collaborator

This patch fixes the flaky Prometheus integration tests that started failing after f4674d5 - stats-segment refactor that removed implicit delays (waitForStatsSocket + statsclient.Connect) which masked a race condition.

  • Added fetchMetricsUntilPresent() helper that polls /metrics until the expected metric name appears, replacing the flaky fetchMetricsWithRetry() mehcanism which returned on the first successful HTTP response regardless of content.
  • Applied the robust fetch to all tests that assert metric presence (interface stats, TCP stats, pod addition events).
  • Also removed the brittle time.Sleep(2s) from pod test.

@aritrbas aritrbas self-assigned this Jun 23, 2026
The interface-stats integration test fetches /metrics as soon as
the HTTP server is reachable, but exportMetrics() may not have
completed its first cycle by that point. This race was exposed
by f4674d5 which removed implicit delays (waitForStatsSocket
+ statsclient.Connect) that previously masked the timing issue.

Added a new helper function fetchMetricsUntilPresent() to retry
the HTTP fetch until the expected metric name appears in the
response body (or a timeout expires). Applied it to all tests
that assert metric presence.

Signed-off-by: Aritra Basu <aritrbas+gh@cisco.com>

@hedibouattour hedibouattour left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks !

@sknat sknat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@sknat sknat merged commit 1aafc1d into master Jun 23, 2026
5 checks passed
@sknat sknat deleted the abasu-fix-prom branch June 23, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants