The portal in English and Turkish: a catalogue per language, a switcher at the foot of every page, landing.language, Turkish numbers and dates
Every template and handler message in internal/web goes through a JSON
catalogue under internal/web/locales/<code>/, with English as the fallback.
The language is the person's choice (a cookie set by /_lang/{code}), else
Accept-Language, else landing.language. Tests refuse a key some language
lacks, a translation with other arguments than English, and template text
left in English.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
30f7f3474a
commit
11231d8c2b
113 files changed
+8091
-1981
No files matched your search
+56
-17
@@ -5,6 +5,8 @@ import (
|
||||
"html/template"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
|
||||
@@ -94,8 +96,38 @@ type DashboardData struct {
|
||||
// way to tell that from a bug.
|
||||
Nav NavExtras
|
||||
RefreshSec int
|
||||
Version string
|
||||
Now string
|
||||
// RefreshMeta is the reload for a browser without script.
|
||||
RefreshMeta template.HTML
|
||||
Version string
|
||||
Now string
|
||||
}
|
||||
|
||||
// stateWords are every state a node, a replica, a shard or an engine's
|
||||
// installation can be in. Each is a CSS class and a word; the class stays as
|
||||
// it is and the word is looked up, as dash.state.<state>. A state not listed
|
||||
// here shows its key, which the catalogue test is there to stop.
|
||||
var stateWords = []string{
|
||||
"ready", "cordoned", "draining", "unreachable", "lost", "unknown",
|
||||
"placing", "pending", "starting", "loading", "stopped", "failed",
|
||||
"installing", "unsupported", "skipped",
|
||||
}
|
||||
|
||||
func init() {
|
||||
for _, s := range stateWords {
|
||||
registerKeys("dash.state." + s)
|
||||
}
|
||||
// How bad a fabric's or an NVLink domain's problem is.
|
||||
registerKeys("fabric.level.fail", "fabric.level.warn", "fabric.level.info")
|
||||
}
|
||||
|
||||
// refreshMeta is the meta element that reloads a page every sec seconds,
|
||||
// for the <noscript> in its head.
|
||||
//
|
||||
// Built here rather than written in the template because the inside of a
|
||||
// <noscript> is text to an HTML tokenizer, and the catalogue check would
|
||||
// read the element's attribute names there as English left on the page.
|
||||
func refreshMeta(sec int) template.HTML {
|
||||
return template.HTML(`<meta http-equiv="refresh" content="` + strconv.Itoa(sec) + `">`) //nolint:gosec // a number
|
||||
}
|
||||
|
||||
// Source is what the dashboard reads. An interface so the page can be rendered
|
||||
@@ -170,12 +202,14 @@ func Dashboard(src Source, usage UsageSource, version string, refresh time.Durat
|
||||
refresh = 5 * time.Second
|
||||
}
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := langOf(r)
|
||||
d := DashboardData{
|
||||
Menu: navFrom(r, "cluster"),
|
||||
OnAdminListener: onAdminListener,
|
||||
Nav: nav,
|
||||
Fleet: LoadFleetCharts(r.Context(), nav.History, nav.Window, log),
|
||||
Fleet: l.loadFleetCharts(r.Context(), nav.History, nav.Window, log),
|
||||
RefreshSec: int(refresh.Seconds()),
|
||||
RefreshMeta: refreshMeta(int(refresh.Seconds())),
|
||||
Version: version,
|
||||
Now: time.Now().UTC().Format(time.RFC3339),
|
||||
AuthEnabled: usage != nil,
|
||||
@@ -184,7 +218,12 @@ func Dashboard(src Source, usage UsageSource, version string, refresh time.Durat
|
||||
d.Notice, d.Problem = r.URL.Query().Get("notice"), r.URL.Query().Get("problem")
|
||||
}
|
||||
if src != nil {
|
||||
d.Nodes = src.Nodes()
|
||||
// A copy, since the ages are rewritten in the reader's units
|
||||
// and the source's slice may be what it hands everybody.
|
||||
d.Nodes = slices.Clone(src.Nodes())
|
||||
for i := range d.Nodes {
|
||||
d.Nodes[i].LastSeenAgo = l.clockText(d.Nodes[i].LastSeenAgo)
|
||||
}
|
||||
d.CPU = cpuCapacityOf(d.Nodes)
|
||||
d.Models = src.Models()
|
||||
d.Replicas = src.Replicas("")
|
||||
@@ -206,8 +245,8 @@ func Dashboard(src Source, usage UsageSource, version string, refresh time.Durat
|
||||
}
|
||||
d.NodePrefix = sharedPrefix(ids)
|
||||
if d.AnyGPUs {
|
||||
d.GPUMap = buildGPUMap(d.Nodes, d.Replicas, r.URL.Query().Get("gpumap"), d.NodePrefix)
|
||||
d.IdleGPUs = idleHoldings(d.Nodes, d.Replicas, d.NodePrefix)
|
||||
d.GPUMap = buildGPUMap(l, d.Nodes, d.Replicas, r.URL.Query().Get("gpumap"), d.NodePrefix)
|
||||
d.IdleGPUs = idleHoldings(l, d.Nodes, d.Replicas, d.NodePrefix)
|
||||
}
|
||||
for _, m := range d.Models {
|
||||
d.AnyFallbacks = d.AnyFallbacks || len(m.Fallbacks) > 0
|
||||
@@ -235,13 +274,13 @@ 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)
|
||||
d.addCharts(r.Context(), l, usage, log)
|
||||
d.addPeopleAndModels(r.Context(), usage, log)
|
||||
}
|
||||
// Only ever shown to an administrator, whatever wrapped it.
|
||||
d.Menu.Admin = true
|
||||
d.Menu.Mirror = d.Menu.Mirror || nav.Mirror
|
||||
render(w, "dashboard", d)
|
||||
render(w, r, "dashboard", d)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +315,7 @@ func (d *DashboardData) addPeopleAndModels(ctx context.Context, usage UsageSourc
|
||||
//
|
||||
// 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) {
|
||||
func (d *DashboardData) addCharts(ctx context.Context, l *Lang, 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)
|
||||
@@ -290,19 +329,19 @@ func (d *DashboardData) addCharts(ctx context.Context, usage UsageSource, log *s
|
||||
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"))
|
||||
requests.Labels = append(requests.Labels, l.hourLabel(b.Start, float64(b.Requests), l.T("dash.unit.requests")))
|
||||
|
||||
tok := float64(b.Prompt + b.Completion)
|
||||
tokens.Values = append(tokens.Values, tok)
|
||||
tokens.Labels = append(tokens.Labels, hourLabel(b.Start, tok, "tokens"))
|
||||
tokens.Labels = append(tokens.Labels, l.hourLabel(b.Start, tok, l.T("dash.unit.tokens")))
|
||||
|
||||
latency.Values = append(latency.Values, float64(b.LatencyMs))
|
||||
latency.Labels = append(latency.Labels, hourLabel(b.Start, float64(b.LatencyMs), "ms mean"))
|
||||
latency.Labels = append(latency.Labels, l.hourLabel(b.Start, float64(b.LatencyMs), l.T("dash.unit.ms_mean")))
|
||||
}
|
||||
|
||||
d.RequestChart = BarChart(requests, "requests/h")
|
||||
d.TokenChart = BarChart(tokens, "tokens/h")
|
||||
d.LatencyChart = BarChart(latency, "ms")
|
||||
d.RequestChart = l.BarChart(requests, l.T("dash.unit.requests_h"))
|
||||
d.TokenChart = l.BarChart(tokens, l.T("dash.unit.tokens_h"))
|
||||
d.LatencyChart = l.BarChart(latency, "ms")
|
||||
d.HasCharts = true
|
||||
|
||||
// The headline figures. Numbers rather than charts, because a single
|
||||
@@ -315,8 +354,8 @@ func (d *DashboardData) addCharts(ctx context.Context, usage UsageSource, log *s
|
||||
d.Errors24h += b.Errors
|
||||
d.Spend24h += b.CostMicros
|
||||
}
|
||||
d.RequestSpark = Sparkline(requests.Values, "--viz-1")
|
||||
d.TokenSpark = Sparkline(tokens.Values, "--viz-3")
|
||||
d.RequestSpark = l.Sparkline(requests.Values, "--viz-1")
|
||||
d.TokenSpark = l.Sparkline(tokens.Values, "--viz-3")
|
||||
}
|
||||
|
||||
// unplaced collects the placement explanations for models short of replicas.
|
||||
|
||||
Reference in new issue
Block a user