Two things the dashboard was missing: it could not act, and it was a column of numbers. Account administration moves to /admin/users — approving into a project, suspending, reinstating. That is the work an operator does constantly and it should not need a terminal. Three things stay on the CLI, and the line is not arbitrary: promoting someone to admin, resetting a password, and issuing a key on another person's behalf each turn a stolen admin session into more than it was — permanent access, or somebody else's account. Approving and suspending do not. Suspending signs the account out everywhere, or suspension is advisory until the session happens to expire, and an admin cannot suspend themselves, which is not a thing an interface should let you do by misclicking. The charts are inline SVG generated in Go. A charting library would mean a JavaScript toolchain in CI and a megabyte of bundle for what is a list of rectangles, and the single-binary goal rules that out. Hourly over a day: fine enough to show a working day, coarse enough that one slow minute is not an incident. Empty hours are filled in, because a chart with hours missing where nothing happened reads as a chart with hours missing from the data. The SVG is marked as trusted HTML, so everything that reaches it is either a number this package computed or escaped explicitly, and a bar's colour can only be one of four names — a colour that could be anything is a way to write CSS into every page the chart appears on. There are tests for both. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e519dc587c
commit
859f08da9b
13 files changed
+687
-5
No files matched your search
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -18,6 +19,13 @@ type DashboardData struct {
|
||||
Unplaced []adminapi.ExplainView
|
||||
Usage []store.KeyUsage
|
||||
|
||||
// Charts are pre-rendered rather than assembled in the template: building
|
||||
// SVG out of template fragments is how a chart ends up unescaped.
|
||||
RequestChart template.HTML
|
||||
TokenChart template.HTML
|
||||
LatencyChart template.HTML
|
||||
HasCharts bool
|
||||
|
||||
NodeCount int
|
||||
ModelCount int
|
||||
ReadyReplicas int
|
||||
@@ -41,6 +49,7 @@ type Source interface {
|
||||
// UsageSource is the accounting half, absent when authentication is off.
|
||||
type UsageSource interface {
|
||||
UsageSince(ctx context.Context, since time.Time) ([]store.KeyUsage, error)
|
||||
UsageBuckets(ctx context.Context, since time.Time, width time.Duration) ([]store.Bucket, error)
|
||||
}
|
||||
|
||||
// Dashboard serves the read-only cluster view.
|
||||
@@ -93,11 +102,46 @@ func Dashboard(src Source, usage UsageSource, version string, refresh time.Durat
|
||||
log.Warn("could not read usage for the dashboard", "err", err)
|
||||
}
|
||||
d.Usage = rows
|
||||
d.addCharts(r.Context(), usage, log)
|
||||
}
|
||||
render(w, "dashboard", d)
|
||||
}
|
||||
}
|
||||
|
||||
// addCharts draws the last day of traffic.
|
||||
//
|
||||
// Hourly, over 24 hours: fine enough to show a working day and coarse enough
|
||||
// that one slow minute does not look like an incident.
|
||||
func (d *DashboardData) addCharts(ctx context.Context, usage UsageSource, log *slog.Logger) {
|
||||
buckets, err := usage.UsageBuckets(ctx, time.Now().Add(-24*time.Hour), time.Hour)
|
||||
if err != nil {
|
||||
log.Warn("could not read usage buckets for the dashboard", "err", err)
|
||||
return
|
||||
}
|
||||
if len(buckets) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var requests, tokens, latency Series
|
||||
requests.Colour, tokens.Colour, latency.Colour = "--accent", "--ok", "--warn"
|
||||
for _, b := range buckets {
|
||||
requests.Values = append(requests.Values, float64(b.Requests))
|
||||
requests.Labels = append(requests.Labels, hourLabel(b.Start, float64(b.Requests), "requests"))
|
||||
|
||||
tok := float64(b.Prompt + b.Completion)
|
||||
tokens.Values = append(tokens.Values, tok)
|
||||
tokens.Labels = append(tokens.Labels, hourLabel(b.Start, tok, "tokens"))
|
||||
|
||||
latency.Values = append(latency.Values, float64(b.LatencyMs))
|
||||
latency.Labels = append(latency.Labels, hourLabel(b.Start, float64(b.LatencyMs), "ms mean"))
|
||||
}
|
||||
|
||||
d.RequestChart = BarChart(requests, "requests/h")
|
||||
d.TokenChart = BarChart(tokens, "tokens/h")
|
||||
d.LatencyChart = BarChart(latency, "ms")
|
||||
d.HasCharts = true
|
||||
}
|
||||
|
||||
// unplaced collects the placement explanations for models short of replicas.
|
||||
//
|
||||
// Only for those: asking why a satisfied model was not placed produces an empty
|
||||
|
||||
Reference in new issue
Block a user