Commit e466c6f
authored
use correct route value in proxy metrics tags instead of route_prefix (#58180)
## Expose Route Patterns in Proxy Metrics
fixes #52212
### Problem
Proxy metrics (`ray_serve_num_http_requests_total`,
`ray_serve_http_request_latency_ms`) only expose `route_prefix` (e.g.,
`/api`) instead of actual route patterns (e.g., `/api/users/{user_id}`).
This prevents granular monitoring of individual endpoints without
causing high cardinality from unique request paths.
### Design
**Route Pattern Extraction & Propagation:**
- Replicas extract route patterns from ASGI apps (FastAPI/Starlette) at
initialization using `extract_route_patterns()`
- Patterns propagate: Replica → `ReplicaMetadata` → `DeploymentState` →
`EndpointInfo` → Proxy
- Works with both normal patterns (routes in class) and factory patterns
(callable returns app)
**Proxy Route Matching:**
- `ProxyRouter.match_route_pattern()` matches incoming requests to
specific patterns using cached mock Starlette apps
- Metrics tag requests with parameterized routes (e.g.,
`/api/users/{user_id}`) instead of prefixes
- Fallback to `route_prefix` if patterns unavailable or matching fails
**Performance:**
Metric | Before | After
-- | -- | --
Requests per second (RPS) | 403.39 | 397.82
Mean latency (ms) | 247.9 | 251.37
p50 (ms) | 224 | 223
p90 (ms) | 415 | 428
p99 (ms) | 526 | 544
### Testing
- Unit tests for `extract_route_patterns()`
- Integration test verifying metrics use patterns and avoid high
cardinality
- Parametrized for both normal and factory patterns
---------
Signed-off-by: abrar <abrar@anyscale.com>1 parent 6dd3776 commit e466c6f
File tree
13 files changed
+821
-14
lines changed- python/ray/serve
- _private
- thirdparty
- tests
- unit
13 files changed
+821
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
541 | 548 | | |
542 | 549 | | |
543 | 550 | | |
| |||
550 | 557 | | |
551 | 558 | | |
552 | 559 | | |
| 560 | + | |
553 | 561 | | |
554 | 562 | | |
555 | 563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
104 | 135 | | |
105 | 136 | | |
| 137 | + | |
106 | 138 | | |
107 | 139 | | |
108 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| 254 | + | |
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
| |||
348 | 349 | | |
349 | 350 | | |
350 | 351 | | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
351 | 356 | | |
352 | 357 | | |
353 | 358 | | |
| |||
768 | 773 | | |
769 | 774 | | |
770 | 775 | | |
| 776 | + | |
771 | 777 | | |
772 | 778 | | |
773 | 779 | | |
| |||
1126 | 1132 | | |
1127 | 1133 | | |
1128 | 1134 | | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
1129 | 1139 | | |
1130 | 1140 | | |
1131 | 1141 | | |
| |||
1773 | 1783 | | |
1774 | 1784 | | |
1775 | 1785 | | |
| 1786 | + | |
1776 | 1787 | | |
1777 | 1788 | | |
1778 | 1789 | | |
| |||
1865 | 1876 | | |
1866 | 1877 | | |
1867 | 1878 | | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
1868 | 1883 | | |
1869 | 1884 | | |
1870 | 1885 | | |
| |||
2538 | 2553 | | |
2539 | 2554 | | |
2540 | 2555 | | |
2541 | | - | |
| 2556 | + | |
2542 | 2557 | | |
2543 | 2558 | | |
| 2559 | + | |
2544 | 2560 | | |
2545 | 2561 | | |
2546 | 2562 | | |
| |||
3191 | 3207 | | |
3192 | 3208 | | |
3193 | 3209 | | |
| 3210 | + | |
| 3211 | + | |
| 3212 | + | |
| 3213 | + | |
| 3214 | + | |
| 3215 | + | |
| 3216 | + | |
| 3217 | + | |
3194 | 3218 | | |
3195 | 3219 | | |
3196 | 3220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
386 | 389 | | |
387 | 390 | | |
388 | 391 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
3 | 8 | | |
4 | 9 | | |
5 | 10 | | |
| 11 | + | |
6 | 12 | | |
7 | 13 | | |
8 | 14 | | |
| |||
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
41 | 54 | | |
42 | 55 | | |
43 | 56 | | |
| |||
80 | 93 | | |
81 | 94 | | |
82 | 95 | | |
| 96 | + | |
83 | 97 | | |
84 | 98 | | |
85 | 99 | | |
86 | 100 | | |
| 101 | + | |
| 102 | + | |
87 | 103 | | |
88 | 104 | | |
89 | 105 | | |
| |||
103 | 119 | | |
104 | 120 | | |
105 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
106 | 125 | | |
107 | 126 | | |
108 | 127 | | |
| |||
163 | 182 | | |
164 | 183 | | |
165 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
| |||
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
124 | 131 | | |
125 | 132 | | |
126 | 133 | | |
| |||
573 | 580 | | |
574 | 581 | | |
575 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
576 | 591 | | |
577 | 592 | | |
578 | 593 | | |
| |||
582 | 597 | | |
583 | 598 | | |
584 | 599 | | |
| 600 | + | |
585 | 601 | | |
586 | 602 | | |
587 | 603 | | |
| |||
0 commit comments