Skip to content

[Serve] Fix flaky test_router_queue_len_metric - #60333

Merged
aslonnie merged 5 commits into
ray-project:masterfrom
eicherseiji:fix-flaky-router-queue-len-test
Jan 21, 2026
Merged

aslonnie merged 5 commits into
ray-project:masterfrom
eicherseiji:fix-flaky-router-queue-len-test

Conversation

@eicherseiji

Copy link
Copy Markdown
Contributor

Why are these changes needed?

The test_router_queue_len_metric test was flaky because the router queue length gauge has a 100ms throttle (RAY_SERVE_ROUTER_QUEUE_LEN_GAUGE_THROTTLE_S) that can skip updates when they happen too quickly.

When replica initialization sets the gauge to 0 and a request immediately updates it to 1, the second update may be throttled, causing the test to see 0 instead of 1.

Related issue number

Fixes flaky test introduced in #59233 after #60139 added throttling.

Checks

The test was flaky because the router queue length gauge has a 100ms
throttle (RAY_SERVE_ROUTER_QUEUE_LEN_GAUGE_THROTTLE_S) that can skip
updates when they happen too quickly. When replica initialization
sets the gauge to 0 and a request immediately updates it to 1, the
second update may be throttled, causing the test to see 0 instead of 1.

Fix by adding a fixture that disables throttling for this test.

Signed-off-by: Seiji Eicher <[email protected]>
@eicherseiji
eicherseiji requested a review from a team as a code owner January 20, 2026 19:18

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request addresses a flaky test, test_router_queue_len_metric, by disabling the router queue length gauge throttling during the test. The fix is implemented by introducing a new pytest fixture, disable_router_queue_len_throttle, that sets the RAY_SERVE_ROUTER_QUEUE_LEN_GAUGE_THROTTLE_S environment variable to "0". The change is correct, well-isolated, and follows good testing practices. The code is clean, and the new fixture is well-documented. Overall, this is a good fix for the reported flakiness.

@ray-gardener ray-gardener Bot added the serve Ray Serve Related Issue label Jan 20, 2026
@eicherseiji eicherseiji added the go add ONLY when ready to merge, run all tests label Jan 20, 2026
Comment thread python/ray/serve/tests/test_metrics.py Outdated
The throttle can cause flakiness: if the gauge is set to 0 on replica init
and then updated to 1 within the throttle window (100ms), the update is skipped.
"""
monkeypatch.setenv("RAY_SERVE_ROUTER_QUEUE_LEN_GAUGE_THROTTLE_S", "0")

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.

let's set this in the buildkite since it applies to all tests

eicherseiji and others added 3 commits January 20, 2026 23:35
Per review feedback, set RAY_SERVE_ROUTER_QUEUE_LEN_GAUGE_THROTTLE_S=0
in Buildkite CI configuration instead of using a test-specific fixture,
since the throttle can cause flakiness in any serve test that sends
requests through the router.

Signed-off-by: Seiji Eicher <[email protected]>
Keep RAY_SERVE_ROUTER_QUEUE_LEN_GAUGE_THROTTLE_S=0 only in the main
":ray-serve: serve: tests" step that runs test_metrics.py.

Signed-off-by: Seiji Eicher <[email protected]>
Set env var on py_test_module_list in BUILD.bazel instead of
buildkite config so all CI targets automatically use it.

This addresses reviewer feedback to have a single source of truth
for the env var rather than replicating it across buildkite steps.

Signed-off-by: Seiji Eicher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants