Draw boolean alert metrics as an on/off timeline

A metric that only ever reads 0 or 1 (up == 0, anything with bool) gave the
line chart nothing to show: a flat line or a square wave on a y axis padded
to -1..2. When every drawn series is 0/1 the incident page now draws one row
per series instead, filled where the value was 1, a thin mark where it was
0, and the bare track where Prometheus returned no samples, which for these
expressions means the condition did not hold.

The decision is per chart, so one chart never mixes styles; any other value
keeps the line chart as before. Frontend only: the endpoint already returns
the points and step_seconds, which pick() now passes on so the last sample
gets a width and a gap in the samples shows as a gap.

Claude-Session: https://claude.ai/code/session_016mBLURvJoMuUEr9cB2RpUN
This commit is contained in:
Niklas Ye
2026-10-25 19:00:24 +01:00
parent cd3b2c2bea
commit 6e95c86521
4 changed files with 107 additions and 12 deletions
+4
View File
@@ -51,6 +51,10 @@ data" for the current value means the condition no longer holds**, not that Prom
A rule expression matches every series, not just the one that fired; only series that agree with the
alert's labels are kept, at most five per alert.
When every series only ever reads `0` or `1` (a boolean such as `up == 0`), a line is not
informative, so the UI draws an on/off timeline instead: one row per series, filled where the value
was `1`, a thin mark where it was `0`, and the bare track where there were no samples.
## Endpoint
`GET /api/incidents/{id}/metrics` — same team scoping as the other incident routes.