You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
0 commit comments