Skip to content

Fix flaky Prometheus metrics startup test - #3610

Merged
chenBright merged 1 commit into
apache:masterfrom
songgaoye:fix/prometheus-metrics-test-flake
Oct 15, 2026
Merged

chenBright merged 1 commit into
apache:masterfrom
songgaoye:fix/prometheus-metrics-test-flake

Conversation

@songgaoye

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

PrometheusMetrics.sanity waits for asynchronous server method metrics to be
exposed after Server::Start().

The test used a fixed number of bthread_usleep() calls. Since
bthread_usleep() may return early when interrupted, the loop can finish in a
few milliseconds instead of waiting for its intended five seconds. This makes
the test flaky when UpdateDerivedVars has not yet exposed the method bvars.

What is changed and the side effects?

Changed:

  • Replace the fixed retry count with a five-second deadline based on
    butil::cpuwide_time_us().
  • Continue polling until the expected bvar is exposed or the deadline expires.

Side effects:

  • Performance effects:

    None. This only affects a unit test.

  • Breaking backward compatibility:

    None.


Check List:

  • Build brpc_prometheus_metrics_unittest
  • Run PrometheusMetrics.sanity

@chenBright chenBright left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@chenBright
chenBright merged commit dfce965 into apache:master Oct 15, 2026
25 checks passed
@songgaoye
songgaoye deleted the fix/prometheus-metrics-test-flake branch October 15, 2026 04:43
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.

2 participants