package web import ( "net/http" "strings" "testing" "time" "gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi" "gitea.mynodes.xyz/ilker/llmgw/internal/promq" ) // nodeMux mounts the page where it lives, so the path carries the node. func nodeMux(src Source, h History) http.Handler { mux := http.NewServeMux() if h == nil { mux.HandleFunc("GET /admin/nodes/{id}", NodePage(src, nil, time.Hour, false, "v1", nil)) } else { mux.HandleFunc("GET /admin/nodes/{id}", NodePage(src, h, time.Hour, false, "v1", nil)) } return mux } // busySource is fakeSource with a node that has been measured. type busySource struct{ fakeSource } func (busySource) Nodes() []adminapi.NodeView { n := fakeSource{}.Nodes()[0] n.Load = &adminapi.LoadView{CPUPercent: 62, CPUs: 8, Load1: 3.25, Load5: 2, Load15: 1, MemUsed: 6 << 30, MemTotal: 8 << 30, MemPercent: 75} return []adminapi.NodeView{n} } func (busySource) Replicas(string) []adminapi.ReplicaView { r := fakeSource{}.Replicas("") r[0].Shards[0].CPUCores, r[0].Shards[0].MemoryBytes = 4, 5<<30 return r } func TestANodesPageShowsHowBusyItIsAndWhatIsUsingIt(t *testing.T) { h := &fakeHistory{byExpr: map[string][]promq.Series{ `llmgw_node_cpu_utilization_percent{node="llmgw-node01"} / 100`: {ts("llmgw-node01", 0.2, 0.6)}, }} code, body := get(t, nodeMux(busySource{}, h), "http://x/admin/nodes/llmgw-node01", nil) if code != http.StatusOK { t.Fatalf("status %d", code) } for _, want := range []string{ "62%", "CPU ยท 8 cores", "RAM in use", "3.25", // The engine and its share: four of eight cores is half the machine. "