Home: one time range across the health block, and failures that follow it
The health screen was fixed at 24 hours everywhere except its lists, which were fixed at nothing: `failuresQueryOptions` read the newest 100 rows and `HealthActivity` filtered them client-side, so on a busy engine the failures list covered whatever few minutes 100 rows happened to span while the chart beside it spanned a day — and pinning an older minute showed an empty card. One `RangePicker` now sits on the Health heading and governs the whole block: the tiles, the flow table, both charts and both lists. Presets are 1h / 6h / 24h / 7d — the collector prunes at `OBS_RETENTION_DAYS` (30), so a week is behind the last one. The longer windows ask for coarser buckets, since a week of minute rollups is ten thousand points nobody can see. Failures get the escape hatch the runs already had: a pinned minute is asked for with `since`/`until` rather than filtered out of what is held, and the list itself is bound to the selected range. `RUN_DEPTH`/`EVENT_DEPTH` become one `LIST_DEPTH`, which now buys coverage of the window on screen instead of a fixed newest-N — narrowing the range is what makes the same rows reach the whole of it. The "Failures (24h)" tile counts errors over the selected window from the rollups the table is drawn from, so tile, column and chart agree. The node-panel and edge trend curves get no picker. They are a Redis ring of the last 120 values per message with no window to ask for, so hovering one reveals what it actually shows — how many readings, and the span they cover. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XC2jX6Hdj7pxGGKzBTrbqB
This commit is contained in:
@@ -3,6 +3,7 @@ import { ChevronDown, ChevronRight, X } from "lucide-react"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import type { EventRow, HistoryPoint } from "@/client"
|
||||
import type { Range } from "@/components/Common/RangePicker"
|
||||
import { UplotChart } from "@/components/Common/UplotChart"
|
||||
import { useEngineEvents } from "@/components/Flow/liveStore"
|
||||
import { PANEL_SECTION } from "@/components/Flow/SidePanel"
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
deadLetterQueryOptions,
|
||||
failuresQueryOptions,
|
||||
healthKeys,
|
||||
minuteFailuresQueryOptions,
|
||||
minuteOf,
|
||||
minuteRunsQueryOptions,
|
||||
runsQueryOptions,
|
||||
@@ -175,22 +177,27 @@ function Failure({ event }: { event: EventRow }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* What the engine has been doing, as charts over a day and the records behind
|
||||
* them.
|
||||
* What the engine has been doing over the selected window, as charts and the
|
||||
* records behind them.
|
||||
*
|
||||
* The two charts each drive the list beside them: throughput picks the runs of
|
||||
* a minute, failures and timing picks that minute's failures.
|
||||
* a minute, failures and timing picks that minute's failures. The window comes
|
||||
* from the health block's one range control, so the lists cover the same span
|
||||
* the charts are drawn from rather than however far their newest rows reach.
|
||||
*/
|
||||
export function HealthActivity() {
|
||||
export function HealthActivity({ range }: { range: Range }) {
|
||||
const live = useEngineEvents()
|
||||
const queryClient = useQueryClient()
|
||||
const runsAt = useMoment()
|
||||
const failuresAt = useMoment()
|
||||
|
||||
const { data: series } = useQuery(timeseriesQueryOptions())
|
||||
const { data: runs } = useQuery(runsQueryOptions())
|
||||
const { data: series } = useQuery(timeseriesQueryOptions(range))
|
||||
const { data: runs } = useQuery(runsQueryOptions(range))
|
||||
const { data: pinnedRuns } = useQuery(minuteRunsQueryOptions(runsAt.pinned))
|
||||
const { data: failures } = useQuery(failuresQueryOptions())
|
||||
const { data: failures } = useQuery(failuresQueryOptions(range))
|
||||
const { data: pinnedFailures } = useQuery(
|
||||
minuteFailuresQueryOptions(failuresAt.pinned),
|
||||
)
|
||||
const { data: audit } = useQuery(auditQueryOptions())
|
||||
const { data: dead } = useQuery(deadLetterQueryOptions())
|
||||
|
||||
@@ -219,8 +226,8 @@ export function HealthActivity() {
|
||||
|
||||
// A pin is read back from the server, so it reaches a minute the recent list
|
||||
// is nowhere near deep enough to hold. A hover stays the client-side preview
|
||||
// it is: scrubbing a day's chart would otherwise be a request per minute the
|
||||
// pointer rests on.
|
||||
// it is: scrubbing a whole window's chart would otherwise be a request per
|
||||
// minute the pointer rests on.
|
||||
const shownRuns =
|
||||
runsAt.pinned !== null
|
||||
? (pinnedRuns ?? [])
|
||||
@@ -228,9 +235,13 @@ export function HealthActivity() {
|
||||
? (runs ?? []).slice(0, RUNS_SHOWN)
|
||||
: (runs ?? []).filter((run) => minuteOf(run.started_at) === runsAt.at)
|
||||
const shownFailures =
|
||||
failuresAt.at === null
|
||||
? (failures ?? []).slice(0, FAILURES_SHOWN)
|
||||
: (failures ?? []).filter((event) => minuteOf(event.ts) === failuresAt.at)
|
||||
failuresAt.pinned !== null
|
||||
? (pinnedFailures ?? [])
|
||||
: failuresAt.at === null
|
||||
? (failures ?? []).slice(0, FAILURES_SHOWN)
|
||||
: (failures ?? []).filter(
|
||||
(event) => minuteOf(event.ts) === failuresAt.at,
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -329,8 +340,10 @@ export function HealthActivity() {
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{failuresAt.at === null
|
||||
? "Nothing has failed in the last day."
|
||||
: "Nothing failed in this minute."}
|
||||
? `Nothing has failed in the last ${range.label}.`
|
||||
: failuresAt.pinned !== null
|
||||
? "Nothing failed in this minute."
|
||||
: "No failure from this minute is in the recent list."}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useQuery } from "@tanstack/react-query"
|
||||
import { Link } from "@tanstack/react-router"
|
||||
|
||||
import type { FlowRollup, HistoryPoint } from "@/client"
|
||||
import { type Range, RangePicker } from "@/components/Common/RangePicker"
|
||||
import { Sparkline } from "@/components/Common/Sparkline"
|
||||
import { PANEL_SECTION } from "@/components/Flow/SidePanel"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
@@ -37,9 +38,11 @@ function Tile({
|
||||
/**
|
||||
* A flow's execution trend, drawn from the 60 slices the rollup carries.
|
||||
*
|
||||
* The same curve the node panel and the edge popover draw, in the chart ramp
|
||||
* this page's other graphs use. No live dot: the rollups are polled, so the
|
||||
* right edge is the last completed slice rather than this instant.
|
||||
* Sixty slices of whatever window is selected, so the curve stays the same
|
||||
* width and only its resolution moves. The same curve the node panel and the
|
||||
* edge popover draw, in the chart ramp this page's other graphs use. No live
|
||||
* dot: the rollups are polled, so the right edge is the last completed slice
|
||||
* rather than this instant.
|
||||
*/
|
||||
function Spark({ counts }: { counts: number[] }) {
|
||||
const points: HistoryPoint[] = counts.map((value, index) => ({
|
||||
@@ -61,28 +64,40 @@ function Spark({ counts }: { counts: number[] }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* How the engine is doing, and how each flow has been doing for a day.
|
||||
* How the engine is doing, and how each flow has been doing over the window.
|
||||
*
|
||||
* The tiles are the standing state; the table below is the same day the charts
|
||||
* cover, one row per flow.
|
||||
* The tiles are the standing state; the table below is the same window the
|
||||
* charts cover, one row per flow. The range control sits on this heading
|
||||
* because it governs the whole health block, the activity below included —
|
||||
* one window, not one per card.
|
||||
*/
|
||||
export function HealthOverview() {
|
||||
export function HealthOverview({
|
||||
range,
|
||||
onRangeChange,
|
||||
}: {
|
||||
range: Range
|
||||
onRangeChange: (range: Range) => void
|
||||
}) {
|
||||
const { data: summary } = useQuery(summaryQueryOptions())
|
||||
const { data: flows } = useQuery(flowRollupsQueryOptions())
|
||||
const { data: flows } = useQuery(flowRollupsQueryOptions(range))
|
||||
// Shares the list below's cache entry, for the one tile that dates them.
|
||||
const { data: failures } = useQuery(failuresQueryOptions())
|
||||
const { data: failures } = useQuery(failuresQueryOptions(range))
|
||||
|
||||
const queue = (summary?.queue ?? {}) as Record<string, number>
|
||||
const degraded = summary?.status === "degraded"
|
||||
const errors = (flows ?? []).reduce((total, row) => total + row.errors, 0)
|
||||
|
||||
return (
|
||||
<>
|
||||
<section className="grid gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<h2 className={PANEL_SECTION}>Health</h2>
|
||||
<Badge variant={degraded ? "destructive" : "secondary"}>
|
||||
{degraded ? "Degraded" : "Running normally"}
|
||||
</Badge>
|
||||
<div className="ml-auto">
|
||||
<RangePicker value={range} onChange={onRangeChange} />
|
||||
</div>
|
||||
</div>
|
||||
{summary?.problems.length ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
@@ -112,8 +127,12 @@ export function HealthOverview() {
|
||||
}
|
||||
/>
|
||||
<Tile
|
||||
label="Failures (24h)"
|
||||
value={si(summary?.failures_24h ?? 0)}
|
||||
label={`Failures (${range.label})`}
|
||||
// Summed from the rollups the table below is drawn from, so the
|
||||
// tile, the Errors column and the chart's error line all count the
|
||||
// same thing over the same window. Narrower than the list beside
|
||||
// it, which also carries quarantines and crashed tasks.
|
||||
value={si(errors)}
|
||||
note={
|
||||
failures?.length
|
||||
? `latest ${ago(failures[0].ts)}`
|
||||
@@ -134,7 +153,7 @@ export function HealthOverview() {
|
||||
</section>
|
||||
|
||||
<section className="grid gap-3">
|
||||
<h2 className={PANEL_SECTION}>Flow activity (24h)</h2>
|
||||
<h2 className={PANEL_SECTION}>Flow activity ({range.label})</h2>
|
||||
<div className={`${CARD} overflow-x-auto`}>
|
||||
{/* The name anchors the left, the numbers read down their own
|
||||
centre, and the trend closes the row on the right. */}
|
||||
@@ -197,7 +216,7 @@ export function HealthOverview() {
|
||||
colSpan={6}
|
||||
className="py-6 text-center text-muted-foreground"
|
||||
>
|
||||
No flow has run in the last day.
|
||||
No flow has run in the last {range.label}.
|
||||
</td>
|
||||
</tr>
|
||||
) : null}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { ObservabilityService } from "@/client"
|
||||
|
||||
/** The live view; anything older is the collector's rollups. */
|
||||
export const HOURS = 24
|
||||
import { type Range, rangeStart } from "@/components/Common/RangePicker"
|
||||
|
||||
/** Another tab can change things, and the engine fails flows on its own. */
|
||||
const REFRESH = 30_000
|
||||
@@ -11,11 +9,14 @@ const REFRESH = 30_000
|
||||
*
|
||||
* Deeper than they are shown: hovering a minute on a chart previews these rows
|
||||
* client-side, and a list holding only the newest handful would have nothing
|
||||
* to show for any minute but the current one. Pinning asks the server for the
|
||||
* minute instead, which is what reaches past this depth.
|
||||
* to show for any minute but the current one.
|
||||
*
|
||||
* Both lists are bound to the selected range, so the depth buys coverage of
|
||||
* whatever window is on screen — narrowing the range is what makes the same
|
||||
* rows reach the whole of it. Pinning asks the server for the minute, which
|
||||
* reaches past this depth at any range. 200 is the cap `/runs` enforces.
|
||||
*/
|
||||
const RUN_DEPTH = 200
|
||||
const EVENT_DEPTH = 100
|
||||
const LIST_DEPTH = 200
|
||||
|
||||
export const healthKeys = {
|
||||
all: ["observability"] as const,
|
||||
@@ -32,49 +33,81 @@ export const summaryQueryOptions = () => ({
|
||||
refetchInterval: 10_000,
|
||||
})
|
||||
|
||||
export const timeseriesQueryOptions = () => ({
|
||||
queryKey: ["observability", "timeseries", HOURS] as const,
|
||||
queryFn: () => ObservabilityService.readTimeseries({ hours: HOURS }),
|
||||
export const timeseriesQueryOptions = (range: Range) => ({
|
||||
queryKey: ["observability", "timeseries", range.hours] as const,
|
||||
queryFn: () =>
|
||||
ObservabilityService.readTimeseries({
|
||||
hours: range.hours,
|
||||
bucketS: range.bucketS,
|
||||
}),
|
||||
refetchInterval: REFRESH,
|
||||
})
|
||||
|
||||
export const flowRollupsQueryOptions = () => ({
|
||||
queryKey: ["observability", "flows", HOURS] as const,
|
||||
queryFn: () => ObservabilityService.readFlowRollups({ hours: HOURS }),
|
||||
export const flowRollupsQueryOptions = (range: Range) => ({
|
||||
queryKey: ["observability", "flows", range.hours] as const,
|
||||
queryFn: () => ObservabilityService.readFlowRollups({ hours: range.hours }),
|
||||
refetchInterval: REFRESH,
|
||||
})
|
||||
|
||||
export const runsQueryOptions = () => ({
|
||||
queryKey: ["observability", "runs"] as const,
|
||||
queryFn: () => ObservabilityService.readRuns({ limit: RUN_DEPTH }),
|
||||
export const runsQueryOptions = (range: Range) => ({
|
||||
queryKey: ["observability", "runs", "recent", range.hours] as const,
|
||||
queryFn: () =>
|
||||
ObservabilityService.readRuns({
|
||||
since: rangeStart(range),
|
||||
limit: LIST_DEPTH,
|
||||
}),
|
||||
refetchInterval: REFRESH,
|
||||
})
|
||||
|
||||
export const failuresQueryOptions = (range: Range) => ({
|
||||
queryKey: [...healthKeys.events, "failure", "recent", range.hours] as const,
|
||||
queryFn: () =>
|
||||
ObservabilityService.readEvents({
|
||||
kind: "failure",
|
||||
since: rangeStart(range),
|
||||
limit: LIST_DEPTH,
|
||||
}),
|
||||
refetchInterval: REFRESH,
|
||||
})
|
||||
|
||||
/** One minute, as the bounds both history endpoints take. */
|
||||
const minuteWindow = (at: number | null) => ({
|
||||
since: new Date((at ?? 0) * 1000).toISOString(),
|
||||
until: new Date(((at ?? 0) + 60) * 1000).toISOString(),
|
||||
})
|
||||
|
||||
/**
|
||||
* The runs of one minute, wherever it sits in the day.
|
||||
* The runs of one minute, wherever it sits in the range.
|
||||
*
|
||||
* A busy engine writes more runs per minute than the recent list is deep, so a
|
||||
* pinned moment is asked for rather than filtered out of what is already held.
|
||||
* `at` is a minute start, and the window is that minute.
|
||||
*/
|
||||
export const minuteRunsQueryOptions = (at: number | null) => ({
|
||||
queryKey: ["observability", "runs", at] as const,
|
||||
queryKey: ["observability", "runs", "minute", at] as const,
|
||||
queryFn: () =>
|
||||
ObservabilityService.readRuns({
|
||||
since: new Date((at ?? 0) * 1000).toISOString(),
|
||||
until: new Date(((at ?? 0) + 60) * 1000).toISOString(),
|
||||
limit: RUN_DEPTH,
|
||||
}),
|
||||
ObservabilityService.readRuns({ ...minuteWindow(at), limit: LIST_DEPTH }),
|
||||
// A minute that has passed does not change, and the current one is refreshed
|
||||
// by the unpinned list anyway.
|
||||
enabled: at !== null,
|
||||
})
|
||||
|
||||
export const failuresQueryOptions = () => ({
|
||||
queryKey: [...healthKeys.events, "failure"] as const,
|
||||
/**
|
||||
* The failures of one minute — the same escape hatch the runs have.
|
||||
*
|
||||
* Without it the list could only ever answer for the minutes its newest rows
|
||||
* happen to span, which on a failing engine is a fraction of the range the
|
||||
* chart beside it draws.
|
||||
*/
|
||||
export const minuteFailuresQueryOptions = (at: number | null) => ({
|
||||
queryKey: [...healthKeys.events, "failure", "minute", at] as const,
|
||||
queryFn: () =>
|
||||
ObservabilityService.readEvents({ kind: "failure", limit: EVENT_DEPTH }),
|
||||
refetchInterval: REFRESH,
|
||||
ObservabilityService.readEvents({
|
||||
kind: "failure",
|
||||
...minuteWindow(at),
|
||||
limit: LIST_DEPTH,
|
||||
}),
|
||||
enabled: at !== null,
|
||||
})
|
||||
|
||||
export const auditQueryOptions = () => ({
|
||||
|
||||
Reference in New Issue
Block a user