Skip to content

[Serve] Fix flaky test_replica_metrics_fields in test_metrics_haproxy - #60953

Merged
abrarsheikh merged 10 commits into
ray-project:masterfrom
eicherseiji:fix-haproxy-metrics-timeout
Feb 15, 2026
Merged

abrarsheikh merged 10 commits into
ray-project:masterfrom
eicherseiji:fix-haproxy-metrics-timeout

Conversation

@eicherseiji

@eicherseiji eicherseiji commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

test_metrics_haproxy.py::test_replica_metrics_fields is failing in postmerge.

Fix: add the missing env var to the HAProxy target.

Example failure: https://buildkite.com/ray-project/postmerge/builds/15966#019c49dc-52b4-40dd-a67e-9f5ea5c61755

PR ray-project#60823 throttled the serve_deployment_replica_healthy gauge with a
10s cache TTL and bumped the timeout in test_metrics.py to 40s, but
missed applying the same fix to the HAProxy variant. The default 10s
wait_for_condition timeout is too short now that the gauge is cached.

Increase the timeout to 40s to match test_metrics.py.

Signed-off-by: Seiji Eicher <[email protected]>
@eicherseiji eicherseiji added the go add ONLY when ready to merge, run all tests label Feb 11, 2026

@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 fixes a flaky test test_replica_metrics_fields in test_metrics_haproxy.py by increasing the timeout for a wait_for_condition call. This change is necessary because the metric being checked, serve_deployment_replica_healthy, is now cached for 10s, making the previous default timeout too short. The fix aligns the HAProxy test with a similar fix made in test_metrics.py. The change is correct and addresses the issue described. I've added one suggestion to improve code clarity by explaining the magic number 40 with a comment.

wait_for_condition(
lambda: len(get_metric_dictionaries("ray_serve_deployment_replica_healthy"))
== 3,
timeout=40,

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.

medium

The timeout value 40 is a magic number. To improve readability and future maintenance, please add a comment explaining why this value was chosen. Based on the PR description, it's to account for the 10s cache TTL on the serve_deployment_replica_healthy gauge.

Suggested change
timeout=40,
timeout=40, # Needs to be >10s to account for the metric cache TTL.

- serve
- python
- flaky
- skip-on-premerge

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.

i dont think we want to do this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am adding this temporarily so I can test the fix on premerge, otherwise it seems RAYCI_SELECT cannot activate the flaky test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will remove before setting PR to "Ready for review"

@eicherseiji

Copy link
Copy Markdown
Contributor Author

@eicherseiji

Copy link
Copy Markdown
Contributor Author

eicherseiji and others added 3 commits February 13, 2026 23:47
The HAProxy BUILD target was missing the
RAY_SERVE_REPLICA_HEALTH_GAUGE_REPORT_INTERVAL_S=0.1 env var that the
non-HAProxy metrics tests already set. Without it, the health gauge
uses the default 10s cache TTL, causing scrapes to miss gauges that
haven't been refreshed within the export window.

The non-HAProxy test_metrics.py target has had this override since
PR ray-project#60823 added the caching optimization.

Signed-off-by: Seiji Eicher <[email protected]>
…o fix-haproxy-metrics-timeout

Signed-off-by: Seiji Eicher <[email protected]>
@eicherseiji

Copy link
Copy Markdown
Contributor Author

@eicherseiji

eicherseiji commented Feb 14, 2026 •

Copy link
Copy Markdown
Contributor Author

We also want this to fix python/ray/serve/tests/test_request_timeout.py::test_with_rest_api from https://buildkite.com/ray-project/postmerge/builds/16057#019c5a13-3c1b-4764-9874-2c32242afe21 that one was just flaky

@eicherseiji

eicherseiji commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@eicherseiji
eicherseiji marked this pull request as ready for review February 15, 2026 00:16
@eicherseiji
eicherseiji requested a review from a team as a code owner February 15, 2026 00:16
@abrarsheikh
abrarsheikh merged commit f645d59 into ray-project:master Feb 15, 2026
3 checks passed
ans9868 pushed a commit to ans9868/ray that referenced this pull request Feb 18, 2026
…ray-project#60953)

##  Why are these changes needed?
`test_metrics_haproxy.py::test_replica_metrics_fields` is failing in
postmerge.

- ray-project#60823 added a 10s cache on the health gauge, with
`RAY_SERVE_REPLICA_HEALTH_GAUGE_REPORT_INTERVAL_S=0.1` in the metrics
BUILD target to keep tests passing
- ray-project#60914 added a HAProxy BUILD target that re-runs serve tests with
`RAY_SERVE_ENABLE_HA_PROXY=1`, but didn't carry over that env var
- Without it, the health gauge goes stale between scrapes and the test
misses one deployment's metric

 Fix: add the missing env var to the HAProxy target.

Example failure:
https://buildkite.com/ray-project/postmerge/builds/15966#019c49dc-52b4-40dd-a67e-9f5ea5c61755

---------

Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Adel Nour <[email protected]>
Aydin-ab pushed a commit to kunling-anyscale/ray that referenced this pull request Feb 20, 2026
…ray-project#60953)

##  Why are these changes needed?                              
`test_metrics_haproxy.py::test_replica_metrics_fields` is failing in
postmerge.

- ray-project#60823 added a 10s cache on the health gauge, with
`RAY_SERVE_REPLICA_HEALTH_GAUGE_REPORT_INTERVAL_S=0.1` in the metrics
BUILD target to keep tests passing
- ray-project#60914 added a HAProxy BUILD target that re-runs serve tests with
`RAY_SERVE_ENABLE_HA_PROXY=1`, but didn't carry over that env var
- Without it, the health gauge goes stale between scrapes and the test
misses one deployment's metric

 Fix: add the missing env var to the HAProxy target.

Example failure:
https://buildkite.com/ray-project/postmerge/builds/15966#019c49dc-52b4-40dd-a67e-9f5ea5c61755

---------

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants