From 8bc457d7e764e95149fcd03e8484d891f1c89996 Mon Sep 17 00:00:00 2001 From: "Memoria (Noblistic)" Date: Mon, 19 Oct 2026 23:59:16 +0000 Subject: [PATCH] dashboard: triple-tile rework, acceptance live-leads, Speculation bullet metrics: export radiance:decode_step_seconds_best/_recent (omitted until measured) scripts: statsdump.py -- /stats to JSONL verbatim recorder Base: pr/decode-floor tip 14c5c8a (PR #142 content). Rebase onto v1.9.0 owed at review time: upstream dashboard.cpp moved +87 lines in 1.9.0, expect conflicts. NOT pushed, NOT merged. Turnstone review pending (Qwen busy). Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI (cherry picked from commit 4a8b8fabdd834f8eb59320e1945471a8caff47c9) --- core/server/dashboard.cpp | 166 ++++++++++++++++++++++++++++++++++++-- core/server/metrics.cpp | 21 +++++ core/server/metrics.h | 4 + scripts/README.md | 1 + scripts/statsdump.py | 90 +++++++++++++++++++++ tests/server_test.cpp | 48 +++++++++++ 6 files changed, 324 insertions(+), 6 deletions(-) create mode 100755 scripts/statsdump.py diff --git a/core/server/dashboard.cpp b/core/server/dashboard.cpp index 16bac914..f98393e6 100644 --- a/core/server/dashboard.cpp +++ b/core/server/dashboard.cpp @@ -1102,7 +1102,7 @@ nav button.on { color:var(--fg); background:var(--track); }
–tok
per step
–%
- accepted
+ accepted now
@@ -1472,6 +1472,116 @@ function setMetric(key, value, text) { spark(key, hist[key]); } +/* BEST / RECENT / NOW ON THE OTHER FOUR TILES, in the shape the decode step established. + * + * WHAT THESE ARE NOT: engine figures. The engine publishes a floor and a recent window for the + * decode step alone (step_ns_decode_best / _recent); for tok/s, requests in flight and acceptance + * it publishes ONE figure per poll and nothing older. So these three figures are page-side, and + * they mean: + * best / highest - the extreme this page session has seen AT THE CURRENT CONCURRENCY. + * Resets on reload, not on restart. + * recent - the mean over the last 15 s at that concurrency; 5 s on prefill, whose + * events are shorter than the window that would fit them. Shorter + * than the sparkline on purpose: + * a 60 s mean still read 31 tok/s fifty seconds after the lane went + * quiet, which is the lane being remembered rather than measured. + * now - the current value as a percentage of that extreme. + * "highest" rather than "best" on the two tiles where more is not better: a lane at its highest + * request count is busy, not good. The word carries a direction the number alone does not. + * + * PER-CONCURRENCY BUCKETS, the decode step's structure: a c8 rate read against the + * single-stream best reports the batch arriving as a level change -- the mistake that took + * the old drift line out. Every figure on the line describes the current concurrency, and + * past c1 the line says so ("@c8"). Requests in flight is the exception: its value IS the + * concurrency, so bucketing it by concurrency would pin "highest" to the current number + * forever -- it keeps one session-wide bucket. While the lane is idle nothing new is + * recorded and the line keeps the last active concurrency's figures: frozen, no now clause, + * which is what the Decode Step tile does at idle. + * + * NO ~99 CAP HERE, unlike the decode step. That cap exists because `now` there is a 500 ms poll + * mean measured against a 32-step window mean -- different instruments, so a fast stretch can read + * faster than the floor without being one. Here the extreme is computed FROM the same series as + * `now`, so exceeding it is arithmetically impossible and 100% is exact: you are at your best. + */ +/* RECENT'S OWN WINDOW, deliberately shorter than the sparkline's. HIST is 60 s and that is right + * for a picture -- a sparkline wants the whole minute to show shape. It is wrong for a number: + * measured over real traffic (two 5 s bursts inside a quiet minute), a 60 s mean still read 31.7 + * tok/s fifty seconds after the lane went quiet, and 30 s only brought that to 26.9. Fifteen + * seconds decays to zero within a quarter-minute of silence while still tracking the running mean + * mid-burst (52.8 against an actual 53.3). Ten and five overshoot -- 79 and 144 against that same + * 53 -- which is the current value wearing a different name, and the big number above already is + * that. `best`/`highest` stay full-session: an extreme wants every chance to be broken. + * Idle polls do not enter an active bucket -- the lane is not at that concurrency while it + * sleeps -- but they DO count in requests in flight's window, whose value is meaningful + * while nothing runs. + * + * PREFILL GETS ITS OWN WINDOW (RECENT_PREFILL, 5 s). Measured: small prompts prefill in 1.5-6 s + * above 100 tok/s; the operator's compaction reload -- the big one -- runs 7-15 s by his own + * count. A 15 s mean cannot report a 7 s event while it is running: it reaches barely half the + * peak by the event's end, then spends a quarter-minute averaging it down. Five seconds is + * shorter than the shortest event, so `recent` rides the prefill while it happens instead of + * diluting it. The engine's own figure is already a windowed rate (its help text: "over the + * scheduler's recent window"), so this window sits on top of the engine's smoothing -- it + * decides how long the page remembers, not how sharply the engine measures. */ +const RECENT = 30; /* 15 s at the 500 ms poll */ +const RECENT_PREFILL = 10; /* 5 s: shorter than the shortest prefill event (see above) */ +const extAt = {}, winAt = {}; +let lastActiveC = 0; +function noteSample(key, c, value, cap) { + if (value == null || !finite(value)) return; + const e = extAt[key] || (extAt[key] = {}); + const w = winAt[key] || (winAt[key] = {}); + if (!(c in e) || value > e[c]) e[c] = value; + const s = w[c] || (w[c] = []); + s.push(value); if (s.length > (cap || RECENT)) s.shift(); +} +function triple(key, c, label, fmt, showNow) { + /* RECENT IS A WINDOW MEAN, not a window maximum -- a maximum would sit equal to `best` on + * any steady lane, and two figures that always agree read as a broken instrument. */ + const e = extAt[key]; + if (!e || !(c in e)) return ""; + /* A bucket whose extreme is zero still has a story -- requests in flight has seen nothing yet -- + * so it renders. Only the `now` clause needs a nonzero extreme to divide by. */ + const s = winAt[key][c]; + let sum = 0; + for (const v of s) sum += v; + const recent = sum / s.length; + const now = s[s.length - 1]; + const tag = typeof c === "number" && c > 1 ? "@c" + c : ""; + let out = label + " " + fmt(e[c]) + " · recent " + fmt(recent); + /* THE SAME GUARD THE DECODE STEP USES: no `now` clause while nothing is running. A rate of + * zero is the lane being idle, not the lane being slow, and "now 0% of best" reads as a + * fault. The "@cN" tag rides the tail, exactly where the decode step puts it. */ + if (showNow !== false && e[c] > 0) out += " · now " + Math.round(100 * now / e[c]) + "% of " + label + tag; + return out; +} +/* WINDOWED ACCEPTANCE. The engine's figure is cumulative and exact -- tot_accepted_/tot_drafted_ + * over the life of the process -- so a best/recent/now line built on it would print the same + * number three times and call it a trend. The per-position counters the acceptance chart already + * reads are cumulative too, and the DIFFERENCE between two polls is exact acceptance over that + * interval, which is the only figure a detail line can move on. Each sample covers 10 s of + * drafting; `recent` averages the last RECENT samples AT THAT CONCURRENCY and `now` is + * the newest one -- different windows, free to disagree. + * The counters go backwards when the engine restarts; that poll resets the window rather than + * reporting a negative draft. */ +const ACC_WIN = 20; /* 10 s of drafting at the 500 ms poll */ +let accPrev = null; +const accDelta = []; +function accWindow(s) { + let reach = 0, hit = 0; + for (const p of (s.draft_positions || [])) { reach += p.reached || 0; hit += p.accepted || 0; } + if (accPrev === null || reach < accPrev.r || hit < accPrev.a) { + accPrev = { r: reach, a: hit }; accDelta.length = 0; return null; + } + const dr = reach - accPrev.r, da = hit - accPrev.a; + accPrev = { r: reach, a: hit }; + if (dr <= 0) return null; + accDelta.push({ r: dr, a: da }); if (accDelta.length > ACC_WIN) accDelta.shift(); + let R = 0, A = 0; + for (const d of accDelta) { R += d.r; A += d.a; } + return R > 0 ? A / R : null; +} + /* ---------------------------------------------------------------- the batch * @@ -1517,7 +1627,14 @@ function kvPanel(host, keys) { return out; } const totals = kvPanel($("totals"), ["Requests", "Steps"]); -const spec = kvPanel($("spec"), ["Drafter", "Depth"]); +/* "Average" is the LIFETIME MARGINAL ratio -- upstream's figure, unchanged, and the one this + * panel used to carry as its headline. A bullet now rather than the big number: see the note at + * the accept tile. It divides by every token DRAFTED, so it is not comparable with the live + * figure above it, which divides by the positions actually REACHED -- the two bases are worked + * through in the GUIDE, and both are derivable from the log. Deliberately not spelled out on the + * face of the panel: the distinction is an analysis-time concern, and a tooltip is invisible on + * the phone anyway. */ +const spec = kvPanel($("spec"), ["Drafter", "Depth", "Average"]); /* ---------------------------------------------------------------- meters */ /* `split` gives the track a second segment for a fill that is two things -- see setSplit. */ @@ -1809,6 +1926,17 @@ function update(s, dt) { setMetric("decode", s.decode_tps, tps(s.decode_tps)); setMetric("prefill", s.prefill_tps, tps(s.prefill_tps)); setMetric("flight", s.in_flight, String(s.in_flight)); + const busy = s.running > 0; + if (busy) { + lastActiveC = s.running; + noteSample("decode", s.running, s.decode_tps); + noteSample("prefill", s.running, s.prefill_tps, RECENT_PREFILL); + } + noteSample("flight", "*", s.in_flight); + const cNow = busy ? s.running : lastActiveC; + $("m-decodedet").textContent = triple("decode", cNow, "best", tps, busy); + $("m-prefilldet").textContent = triple("prefill", cNow, "best", tps, busy); + $("m-flightdet").textContent = triple("flight", "*", "highest", (v) => String(Math.round(v)), s.in_flight > 0); /* THE MERGED POOL, not the maximum over groups. The max is the right preemption signal and the * wrong headline: the drafter's own window group is sized one block-run per slot and therefore * sits at 100% for the whole life of the server, so a headline reading the max reads 100% on a @@ -1834,9 +1962,23 @@ function update(s, dt) { + cnt3(s.kv_tokens_used) + " tok" + (kvGave > 0 ? " · " + hb(kvGave) + " lent to experts" : "") : ""; - setMetric("accept", 100 * s.draft_accept, - s.draft_positions && s.draft_positions.length - ? pctn(s.draft_accept, 0) : DASH); + const aw = accWindow(s); + if (aw != null) noteSample("accept", s.running > 0 ? s.running : lastActiveC, aw); + /* THE HEADLINE IS THE LIVE WINDOW, not the cumulative ratio. The engine's figure is exact but + * cumulative, so on a process that has been up for hours it cannot move: 559 fresh drafts moved + * it one point against a 33,000-draft denominator, and it froze outright the moment the lane + * went quiet. Every other tile's big number is the current value, and feeding the cumulative one + * here also fed the sparkline a quantity that is flat by construction. + * Polls with no new drafts push NOTHING and the headline freezes with them: acceptance is + * UNDEFINED when nothing was drafted, so neither 0 (reads as failure) nor the last value (reads + * as stable) is the truth. A server with no draft head shows the dash -- there is no such figure + * to show. The lifetime ratio stays on /stats and /metrics; what the tile answers is "what is it + * accepting now". + * THE SPARKLINE'S SCALE DIFFERS from the other tiles: its samples are 10 s drafting windows, not + * 500 ms polls, so this box spans up to 120 windows of actual drafting rather than 60 s. */ + if (!(s.draft_positions && s.draft_positions.length)) setMetric("accept", null, DASH); + else if (aw != null) setMetric("accept", 100 * aw, pctn(aw, 0)); + $("m-acceptdet").textContent = triple("accept", cNow, "highest", (v) => pct(v, 0), busy); M.flight.u.textContent = "/ " + s.queue_cap; const list = s.requests || []; @@ -1922,10 +2064,22 @@ function update(s, dt) { const perStep = sps > 0 && s.decode_tps > 0 ? s.decode_tps / sps / seqs : null; if (perStep != null) lastTps = perStep; $("tps_n").firstChild.nodeValue = lastTps == null ? DASH : sig3(lastTps); - $("acc_n").firstChild.nodeValue = pctn(s.draft_accept, 0); + /* ACCEPTED IS THE LIVE FIGURE, matching the tile above it. `aw` is the same pooled drafting + * window the tile's headline reads, computed earlier in this function -- one derivation, two + * readers, so the panel and the tile cannot disagree. + * DESIGN DECISION, 10-19, at the Operator's direction: this section shows the REAL-TIME + * accepted percentage and the lifetime average sits in the bullets below it. The reasoning is + * on the tile; the short form is that a cumulative ratio on a process that has been up for + * hours is a number that cannot move, and a headline that cannot move reads as a dead page. + * PINNED, NOT PRICED: the Operator may prefer the average back in the big seat, and the swap + * is these two lines. What must not happen is the average returning as the headline with no + * bullet left behind, because then the live figure is the thing nobody can see. + * Undefined when nothing was drafted -- freeze rather than print 0 or repaint the last value. */ + if (aw != null) $("acc_n").firstChild.nodeValue = pctn(aw, 0); $("specaside").textContent = "depth " + dp.length; spec["Drafter"].textContent = drafterName; spec["Depth"].textContent = dp.length; + spec["Average"].textContent = pctn(s.draft_accept, 0) + "%"; } /* ---- devices, in the same panel as the cache meter: they are one question. */ diff --git a/core/server/metrics.cpp b/core/server/metrics.cpp index 9fdcd15f..76c55085 100644 --- a/core/server/metrics.cpp +++ b/core/server/metrics.cpp @@ -140,6 +140,10 @@ void Metrics::sample(const SchedMetrics& m) { g_prefill_tps_.set(m.prefill_tps); g_decode_tps_.set(m.decode_tps); g_draft_accept_.set(m.draft_acceptance); + /* Nanoseconds in the scheduler, seconds on the wire: the base unit Prometheus expects, and + * what radiance:engine_step_seconds_* already use. */ + g_step_best_.set((double)m.step_ns_decode_best / 1e9); + g_step_recent_.set((double)m.step_ns_decode_recent / 1e9); const int seen = std::max(0, std::min(m.draft_depth_seen, (int)MAX_DRAFT_POS)); for (int j = 0; j < seen; ++j) { const int64_t r = m.draft_pos_reached[j]; @@ -324,6 +328,23 @@ std::string Metrics::render() const { "Prefill throughput over the scheduler's recent window.", L, g_prefill_tps_.get()); w.gauge("radiance:decode_tokens_per_second", "Decode throughput over the scheduler's recent window.", L, g_decode_tps_.get()); + /* THE DECODE FLOOR, the two figures the dashboard's Decode Step tile shows. They were on + * /stats only, and /stats is documented as not a stable API -- so the one figure worth + * comparing across restarts was reachable only from the surface automation is told not to + * use. Omitted until measured: a floor of 0 seconds is not an unmeasured floor, it is an + * infinitely fast one, and a scrape would plot it as a record. Both reset on restart, so a + * freshly started server simply has no floor to report yet. */ + if (g_step_best_.get() > 0) + w.gauge("radiance:decode_step_seconds_best", + "Fastest single-sequence decode step window this process has run, in seconds " + "per token. A mean over 32 consecutive single-stream steps, not a stopwatch " + "reading. Resets on restart.", L, g_step_best_.get()); + if (g_step_recent_.get() > 0) + w.gauge("radiance:decode_step_seconds_recent", + "Most recent single-sequence decode step window, in seconds per token. The gap " + "to _best tracks what else the machine is doing, not wear; see docs/GUIDE.md. " + "Freezes while the lane is idle, because no window is completing.", + L, g_step_recent_.get()); w.counter("radiance:engine_steps_total", "Scheduler steps executed. One forward pass of the model, plus whatever draft " "rounds followed it; with speculation a step emits more than one token.", diff --git a/core/server/metrics.h b/core/server/metrics.h index 9387e59b..11ba72c4 100644 --- a/core/server/metrics.h +++ b/core/server/metrics.h @@ -113,6 +113,10 @@ private: Gauge g_running_, g_waiting_, g_kv_util_, g_prefix_hit_; Gauge g_kv_max_tokens_, g_kv_max_bytes_; Gauge g_prefill_tps_, g_decode_tps_, g_draft_accept_, g_preempted_; + /* The decode floor, in seconds: the fastest single-sequence window this process has run, + * and the most recent one. Both stay 0 until a window of 32 single-stream steps completes, + * and both reset on restart -- the render omits them rather than expose an unmeasured 0. */ + Gauge g_step_best_, g_step_recent_; Gauge queue_depth_; /* Per-position conditional draft acceptance (see render() and core/sched/draft.h). */ enum { MAX_DRAFT_POS = 64 }; diff --git a/scripts/README.md b/scripts/README.md index 591a6198..ab3429a8 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -38,6 +38,7 @@ and `agentreplay.py` need `python3`. Scripts find each other through `$(dirname | `mctrace.sh` | A MiniCPM5-2B decode trace under `rocprofv3`, on its own server, formatted for `libr4d/isa/tsum.sh`, mainly for its `blocks` column. | | `ident.sh` | Run-to-run reproducibility at a fixed configuration: one hash per (temperature, question), to compare against another run of the same configuration. A speculative run need not match a non-speculative one byte for byte (the split-K count is chosen from M, so reduction orders differ and a near-tie can flip late in a long answer), but a divergence within the first sentence or two is a defect. | | `cardclock.py` | What holds each card's clock under sustained load, and which card a tensor-parallel step waits for (the slowest rank ends the step). Reads every AMD card's `gpu_metrics` table ten times a second and counts a throttler bit only when the clock is lower while it is set (some firmware keeps a bit on at idle). Shows the engine's step counters per window, so a slow window is attributed to slower steps, fewer tokens per step or host time between steps. Drives its own greedy load, or with `--watch` only samples a server under real traffic; `--compare` shows two saved runs side by side. Read-only on the cards. | +| `statsdump.py` | Record `/stats` to JSONL so the dashboard's figures can be measured over time instead of only watched: one object per poll, appended, `python3` only. Records the engine's snapshot verbatim plus the poll's own time and the gap since the last good poll -- it derives nothing, because the page's best/recent/now lines are computed from this same stream and a second copy of that arithmetic is a second thing that can drift. A failed poll leaves no row (a gap in the file is the honest record of a gap in the data) and an empty run exits non-zero, so a dead server cannot be mistaken for a quiet hour. The decode floor resets with the process: `step_ns_decode_best` improving across a restart is a new process finding its own best moment, not a faster machine. | | `oracle.sh` | Every op compared against libref on the operands the model issued, which rad-kbench cannot do: its operands are its own (dense, rank 2), while the engine's are arena slices and weights loaded from a file. Starts its own server on :8302. Read it for `MISMATCH` lines, and for `NOT CHECKED` lines naming rows whose weight layout has no published inverse and so cannot be compared. | ## Regression checks against a live server diff --git a/scripts/statsdump.py b/scripts/statsdump.py new file mode 100755 index 00000000..bb5db89c --- /dev/null +++ b/scripts/statsdump.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# statsdump.py -- record /stats to a JSONL file, so the dashboard's figures can be measured over +# time instead of only watched. +# +# The dashboard answers "what is this process doing right now". Answering "what was it doing at +# 3 a.m., and is its best step time worse than last week's" needs the same numbers kept. /stats +# already carries them -- the decode floor, throughput per window, cache behaviour, the draft +# counters -- and /metrics carries most of them for a Prometheus scrape. This is the third option, +# for anyone who does not run a scraper: one JSON object per poll, appended, no dependencies beyond +# python3. +# +# scripts/statsdump.py [--port 8800] [--every 1] [--seconds 3600] [--out stats.jsonl] +# scripts/statsdump.py --url http://host:8800 --every 2 --out week.jsonl +# RADIANCE_API_KEY=... scripts/statsdump.py --port 8800 +# +# WHAT IS RECORDED: the engine's own snapshot, verbatim, plus `t` (the poll's own unix time) and +# `dt_s` (seconds since the previous successful poll). Nothing is derived. The page's best/recent/ +# now lines are computed in the browser from this same stream, and recomputing them here would put +# a second copy of that arithmetic where it could drift from the first -- so the analysis step +# derives them, from data that cannot disagree with the engine. +# +# Restarts are visible in the rows themselves: `uptime_s` falls and `startup_s` is the cost of the +# restart that just happened. The decode floor resets with the process, so `step_ns_decode_best` +# improving across a restart is a new process finding its own best moment, not a faster machine -- +# compare `best` across restarts only against a known-good value for the same hardware. +# +# A poll that fails leaves NO row: a gap in the file is the honest record of a gap in the data, and +# a fabricated row would be a measurement. Consecutive failures are reported on stderr as they +# happen, and the exit summary states how many polls were lost, so an empty file cannot be mistaken +# for a quiet hour. +import argparse, json, os, sys, time, urllib.error, urllib.request + +def main(): + ap = argparse.ArgumentParser(add_help=True) + ap.add_argument("--port", type=int, default=8800) + ap.add_argument("--url", default=None, help="full base URL; overrides --port") + ap.add_argument("--every", type=float, default=1.0, help="seconds between polls") + ap.add_argument("--seconds", type=float, default=0.0, help="stop after this long; 0 = run until interrupted") + ap.add_argument("--out", default="stats.jsonl") + ap.add_argument("--api-key", default=os.environ.get("RADIANCE_API_KEY"), + help="or set RADIANCE_API_KEY; the key is never echoed") + a = ap.parse_args() + + base = (a.url or "http://127.0.0.1:%d" % a.port).rstrip("/") + hdr = {"Authorization": "Bearer " + a.api_key} if a.api_key else {} + deadline = time.time() + a.seconds if a.seconds > 0 else None + + # Append, never truncate: a file that already holds last week's data is worth more than a clean + # start, and the rows carry their own timestamps. + out = open(a.out, "a") + prev, ok, lost, streak = None, 0, 0, 0 + sys.stderr.write("statsdump: %s/stats every %.1fs -> %s\n" % (base, a.every, a.out)) + try: + while True: + t0 = time.time() + try: + req = urllib.request.Request(base + "/stats", headers=hdr) + with urllib.request.urlopen(req, timeout=max(5.0, 4 * a.every)) as r: + row = json.loads(r.read().decode()) + except (urllib.error.URLError, OSError, ValueError) as e: + lost += 1; streak += 1 + # Report the first failure and then every tenth: one bad hour should be visible + # without the file's own signal being buried in identical lines. + if streak == 1 or streak % 10 == 0: + sys.stderr.write("statsdump: poll failed (%s), streak %d, %d lost\n" + % (type(e).__name__, streak, lost)) + else: + streak = 0 + row["t"] = t0 + row["dt_s"] = round(t0 - prev, 3) if prev is not None else 0.0 + prev = t0 + out.write(json.dumps(row, separators=(",", ":")) + "\n") + out.flush() # a killed poller must not lose the polls it did get + ok += 1 + if deadline is not None and time.time() >= deadline: + break + # Sleep from the poll's START, so a slow engine does not walk the schedule later. + left = a.every - (time.time() - t0) + if left > 0: + time.sleep(left) + except KeyboardInterrupt: + sys.stderr.write("statsdump: interrupted\n") + finally: + out.close() + sys.stderr.write("statsdump: %d rows written, %d polls lost, %s\n" % (ok, lost, a.out)) + # An empty file is a failure, not a quiet run: say so with the exit status, not only in prose. + return 1 if ok == 0 else 0 + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/server_test.cpp b/tests/server_test.cpp index 9d9ac5bb..0c6cf36a 100644 --- a/tests/server_test.cpp +++ b/tests/server_test.cpp @@ -2284,6 +2284,12 @@ TEST(metrics_is_valid_prometheus_text_with_vllm_names) { CHECK_NEAR(find_one("radiance:draft_acceptance_ratio{"), 0.61, 1e-9); CHECK_NEAR(find_one("vllm:generation_tokens_total{"), 5.0, 1e-9); + /* An unmeasured decode floor is ABSENT, not 0: a floor of 0 seconds per token is an + * infinitely fast one, and a scrape would plot it as a record. This fixture never completes a + * window of 32 single-stream steps, so neither series may appear. */ + CHECK(r.body.find("radiance:decode_step_seconds_best") == std::string::npos); + CHECK(r.body.find("radiance:decode_step_seconds_recent") == std::string::npos); + /* Every sample carries the model_name label vLLM's dashboards group by. */ for (auto& kv : d.samples) CHECK(kv.first.find("model_name=\"test-model\"") != std::string::npos); @@ -2306,6 +2312,48 @@ TEST(metrics_is_valid_prometheus_text_with_vllm_names) { CHECK(r.body.find("le=\"2560\"") != std::string::npos); } +/* The decode floor reaches /metrics, in seconds. The scheduler keeps nanoseconds and the page + * divides for display; the wire uses the base unit Prometheus expects, the same choice + * radiance:engine_step_seconds_* already makes. */ +TEST(metrics_carries_the_decode_floor_in_seconds) { + Fixture f; + f.sched.m.step_ns_decode_best = 14708911; /* 14.71 ms/token: a measured floor */ + f.sched.m.step_ns_decode_recent = 16428860; /* 16.43 ms/token: the recent window */ + + HttpResponse r = f.get("/metrics"); + CHECK_EQ(r.status, 200); + PromDoc d = parse_prom(r.body); + CHECK_EQ((int)d.errors.size(), 0); + CHECK_EQ(d.type["radiance:decode_step_seconds_best"], std::string("gauge")); + CHECK_EQ(d.type["radiance:decode_step_seconds_recent"], std::string("gauge")); + + auto find_one = [&](const std::string& prefix) -> double { + for (auto& kv : d.samples) + if (kv.first.rfind(prefix, 0) == 0) return kv.second; + return -12345.0; + }; + CHECK_NEAR(find_one("radiance:decode_step_seconds_best{"), 0.014708911, 1e-12); + CHECK_NEAR(find_one("radiance:decode_step_seconds_recent{"), 0.016428860, 1e-12); + + /* A floor is a duration, so it must survive the number formatter: 0.0147 s rendered as an + * integer would read as infinitely fast. Checked on a prefix rather than the whole literal + * because num() prints 17 significant digits and the last ones are the double's own noise. */ + CHECK(r.body.find("radiance:decode_step_seconds_best{model_name=\"test-model\",engine=\"0\"} 0.01470891") + != std::string::npos); +} + +/* Half a window: a floor exists but the recent window has not completed since. Each series is + * gated on its own value, so one may appear while the other is absent. */ +TEST(metrics_omits_only_the_floor_half_that_is_unmeasured) { + Fixture f; + f.sched.m.step_ns_decode_best = 15000000; + f.sched.m.step_ns_decode_recent = 0; + + HttpResponse r = f.get("/metrics"); + CHECK(r.body.find("radiance:decode_step_seconds_best{") != std::string::npos); + CHECK(r.body.find("radiance:decode_step_seconds_recent") == std::string::npos); +} + /* The scheduler's totals are cumulative, and a scrape turns them into counter increments by adding * the difference from the counter's current value. Concurrent scrapes must still count each total * once: however many run, the counter ends at the total. */