Repository navigation
Commit f7b8962
authored
feat(mesh): routing decision observability 1/2 — decision metrics on the router port (#3141)
* feat(mesh): define routing decision metric schema
Add names, help text, label values and histogram buckets for the routing
decision metrics of the P0-4 spec: route branches, prefix match ratio, route
cost, session affinity, prefill overlap blocks, dispatched DP rank, and the
estimated versus engine-reported cached tokens. Recorder APIs land with them;
labels carry pool, policy, branch, worker and rank only, never session or
request IDs.
* feat(mesh): serve /metrics on the router port
Build the Prometheus recorder instead of install() so the handle stays
available, keep the exporter listener on --prometheus-port (29000 by
default), and render the same registry at GET /metrics on the router port.
Clients that discover <router>:<port>/metrics, such as AIPerf in InferenceX,
can now scrape Mesh self metrics; worker atom: metrics are unaffected.
* feat(mesh): report routing decisions from every policy
Each built-in policy declares its decision branches and reports one per
selection through policies::decision, feeding mesh_route_branch_total,
mesh_route_prefix_match_ratio (cache_aware), mesh_route_cost (load-based
branches) and mesh_session_affinity_total (dp_sticky). New policies plug in
the same way by declaring decision_branches() and calling decision::report.
* ci(atomesh): keep a router /metrics snapshot with each agentic run
After each aiperf run the PD benchmark saves the router port's /metrics to
metrics/router-metrics.prom (best effort), and the latency report staging
keeps .prom files, so the routing-decision counters ship in the artifact.
* refactor(mesh): deprecate mesh_prefix_hash_policy_branch_total
mesh_route_branch_total{policy="prefix_hash"} now counts the same branches
by pool, so mark the old counter and its recorder deprecated instead of
dropping a metric that main already exports. It stays until its scrapers
move to the new counter.
* refactor(mesh): record the selected worker's active requests on every selection
mesh_route_cost was named and described as a cost in the policy's own unit,
but every caller recorded Worker::load(), the router-tracked active request
count, and only on five branches that its pool and policy labels could not
tell apart. Rename it mesh_route_selected_worker_active_requests, record it
for every selection that picks a worker, read before the router adds the
request, label it by branch, and size its buckets for request counts.
Policies no longer compute a cost.
* test(mesh): count a selection without healthy candidates once in its pool
Every policy given only unhealthy prefill candidates reports one
no_healthy_workers decision labeled pool="prefill" and records no active
requests sample.
* fix(mesh): register metric HELP text after installing the recorder
start_prometheus described every metric before installing the Prometheus
recorder, so the descriptions went to the no-op recorder and the exporter
rendered no # HELP lines. Describe after the install.
* fix(mesh): count a pool without candidates as no_healthy_workers
When a pool has no available worker, the planner returns before any policy
runs, so the failure never reached mesh_route_branch_total and no-capacity
alerts could not see it. Count it where the pool is known: a regular,
prefill or decode pool left empty by the health filter, and a PD request
without any prefill or decode worker. A request for a model without any
worker has no pool and stays uncounted.
* docs(mesh): document the router /metrics endpoint
List /metrics with the other router endpoints and note that the router port
serves the whole Mesh registry whatever --prometheus-host binds the exporter
to. The README is already part of this pull request, which keeps #3141
within its 15-file budget.
* docs(mesh): add a routing metrics reference
Explain each routing decision metric: type, labels and their values, units
and buckets, the policies and branches that record it, and which change
starts recording it. Cover how to read the prefix match ratio, the route
cost, session affinity results and the router estimate against the
engine-reported cached tokens, with collection steps, example queries and a
sample scrape. Link it from the README's Prometheus metrics section.
* docs(mesh): document the selected worker's active requests and empty pools
#3141 replaced mesh_route_cost with mesh_route_selected_worker_active_requests,
labeled by branch and recorded on every selection that picks a worker, and
#3213 counts a pool without candidates as no_healthy_workers. The reference
states when the active requests are read and which branches record none, and
the sample is recaptured.
* feat(mesh): count session requests that move to a different worker
dp_sticky records where each session's last request was dispatched. Routers
report the dispatched worker, after DP rank mapping, through
LoadBalancingPolicy::on_dispatch, and mesh_session_worker_change_total{pool,
reason} counts a request dispatched to a different worker (URL and DP rank)
than the session's previous one: rebind or expired when the policy reassigned
the session, rank_mapping when idx2idx moved a pinned session. A new session,
a hit and an expiry back to the same worker count nothing.
* fix(ci): save a router metrics baseline and increase for each concurrency level
Concurrency levels reuse one router, so the snapshot after a level also
counted every earlier level. Each level now saves router-metrics-before.prom
just before aiperf and router-metrics.prom after it, both with their scrape
time, and router-metrics-delta.prom with the increase of every counter and
histogram series, including buckets, sums and counts. A counter that went down
means the router restarted; the increase then counts from the restart and
says so.
* docs(mesh): document session worker changes and the per-run CI baseline
The reference lists mesh_session_worker_change_total and when each reason
applies, describes the before, after and delta router snapshots that CI saves
for each concurrency level, and states that the router counts a pool without
candidates as no_healthy_workers. Sections about #3142 metrics say so, and the
sample comes from a build of this PR.
* fix(mesh): count a session worker change when the request is sent
Routers reported the dispatched worker to the policy as soon as the PD pair
was reserved, and before the regular request was prepared. A reserved worker
that never received the request, such as the decode worker after an ATOM
prefill failure or an external-processing reservation that is canceled or
expires, still counted a change and became the session's previous worker.
Call on_dispatch from send_worker as each upstream request starts, with the
mapped worker, and in the regular router right before the send.
* refactor(mesh): keep only the routing metrics this PR records
mesh_prefill_overlap_blocks had no caller in either PR, so it goes with its
medium labels, inventory entry, buckets and recorder. The DP rank and
cached-token metrics, their labels, recorders and test move to #3142, which
first records them, so this PR no longer declares planned metrics. The
reference drops their rows and sections.
* refactor(mesh): return each routing decision from the policy and record it once
A policy now returns the branch that chose the worker along with its index
(select_with_decision; select_worker wraps it), and apply_policy, the only
production caller, records one decision per call. Policies no longer touch the
routing metrics, so policies/decision.rs, decision_branches and its
debug_assert go away.
mesh_session_affinity_total duplicated
mesh_route_branch_total{policy="dp_sticky"} and is dropped; the documented hit
rate reads the branch counter. A stale_tenant match is on a worker that is
gone, so it no longer records a prefix match ratio.
* fix(mesh): run the PD dispatch hook before spawning the mooncake prefill
send_worker took the headers only so on_dispatch could read the session ID,
and the mooncake path cloned the whole HeaderMap and the router into the
prefill task for it. dispatch now runs the hook on the request task, once the
request is built and right before it is sent, and returns the worker's
policy; the spawned task only sends.1 parent f9698ba commit f7b8962
25 files changed
Lines changed: 1513 additions & 132 deletions
File tree
- .github/scripts/atomesh
- observability
- atom/mesh
- docs
- src
- core/placement
- observability/metrics
- policies
- routers
- tests/routing
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2453 | 2453 | | |
2454 | 2454 | | |
2455 | 2455 | | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
2456 | 2468 | | |
2457 | 2469 | | |
2458 | 2470 | | |
| |||
2522 | 2534 | | |
2523 | 2535 | | |
2524 | 2536 | | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
2525 | 2543 | | |
2526 | 2544 | | |
2527 | 2545 | | |
| |||
2563 | 2581 | | |
2564 | 2582 | | |
2565 | 2583 | | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
2566 | 2600 | | |
2567 | 2601 | | |
2568 | 2602 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
298 | 299 | | |
299 | 300 | | |
300 | 301 | | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
305 | 310 | | |
306 | 311 | | |
307 | 312 | | |
308 | 313 | | |
309 | 314 | | |
310 | 315 | | |
311 | 316 | | |
| 317 | + | |
312 | 318 | | |
313 | 319 | | |
314 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
315 | 325 | | |
316 | 326 | | |
317 | 327 | | |
| |||
0 commit comments