Clusters: sections by kind; each cluster summed up in its own terms #55

Merged
jcoffey-dev merged 2 commits from feature/clusters-page into main 2026-11-16 06:34:35 +00:00
7 changed files with 233 additions and 16 deletions

No files matched your search

+14 -5
View File
@@ -327,11 +327,20 @@ hide a real outage.
Built on the paged, server-side lists from #69. No page ever lists
everything at once.
- **Dashboard:** one line per cluster: version, nodes ready of total,
workloads by state, open incidents. The "needs attention" list takes
workloads too, capped as for hosts.
- **Clusters:** each cluster's nodes, operators and update state, then
its namespaces with counts by state, problems first.
- **Dashboard:** one line per cluster: its version, state and a summary
in its kind's terms: "31/32 nodes ready · 3,300 workloads" for
Kubernetes, "2/2 controllers ready · 600 volumes · 71% used" for an
array, "CPU 41% · system ASP 85% · 4 of 5 subsystems active" for an
IBM i partition. The network map's cluster boxes use the same line.
The "needs attention" list takes workloads too, capped as for hosts.
- **Clusters:** in sections by kind (Kubernetes, Virtualization, Storage,
IBM i, Secrets), the ones that need a look first in each, with a jump
list counting each kind and its problems. Filters for kind, "need a
look" and name stay in the address
(`/clusters?group=Storage&show=problems&q=prod`). Each cluster shows
its nodes, operators and update state, then its kinds of workload with
counts by state. The API gives each cluster's `group` and `summary`.
A host's own libvirt or Hyper-V VMs are on its page, not here.
- **Workloads:** one table for every kind, filtered by cluster, namespace,
kind, node and state and searched by name, problems first, paged. The
same table filtered to `vm` is the **VMs** page.
+7 -3
View File
@@ -289,7 +289,7 @@ func (srv *Server) networkView(focus string, now time.Time) (*MapView, bool) {
_, conds := srv.view(now)
for _, c := range srv.clusterViews(now, conds) {
v.Boxes = append(v.Boxes, MapBox{ID: "cluster:" + c.Name, Kind: "cluster", Name: c.Name, Status: c.Status,
Sub: fmt.Sprintf("%d/%d nodes ready", c.NodesReady, c.Nodes), Count: c.Nodes})
Sub: c.Summary, Count: c.Nodes})
}
case "site", "group":
@@ -688,14 +688,18 @@ func (srv *Server) servicesView(focus string, steps int, now time.Time) (*MapVie
where[s.ID] = gid
layer[gid] = min(layer[gid], s.Layer)
}
kinds := map[string]string{} // a source's name → what it is, for its box (#37)
for _, s := range srv.workloadSnapshot() {
kinds[s.name] = s.kindLabel()
}
for _, gid := range order {
b := fold(gid, "group", names[gid], members[gid], status)
for i, m := range b.Problems {
b.Problems[i] = svc[m].Name
}
b.Layer = layer[gid]
if strings.HasPrefix(gid, "group:cluster:") {
b.Sub = "Kubernetes cluster"
if c, ok := strings.CutPrefix(gid, "group:cluster:"); ok {
b.Sub = cmp.Or(kinds[c], "Kubernetes cluster")
}
v.Boxes = append(v.Boxes, b)
}
+89 -1
View File
@@ -552,6 +552,87 @@ func (s wsnap) noun() string {
return "Cluster"
}
// group is the Clusters page's section for the source (#41).
func (s wsnap) group() string {
switch d := s.distribution(); {
case strings.HasPrefix(d, "Vault"), d == "OpenBao":
return "Secrets"
case strings.HasPrefix(d, "Purity"):
return "Storage"
case d == ibmiDistribution, d == hmcDistribution:
return "IBM i"
case d == "vCenter", d == "Prism Central", strings.HasPrefix(d, "Proxmox"):
return "Virtualization"
}
return "Kubernetes"
}
// kindLabel is what the source is, said on its own: "Kubernetes
// cluster", "Proxmox cluster", "vCenter", "HMC", "IBM i partition".
func (s wsnap) kindLabel() string {
d := s.distribution()
switch n := s.noun(); {
case n == "Partition":
return "IBM i partition"
case n == "Array":
return "Pure array"
case n != "Cluster":
return n // vCenter, Prism Central, HMC, Vault, OpenBao
case strings.HasPrefix(d, "Proxmox"):
return "Proxmox cluster"
case d == "OpenShift", d == "OKD":
return d + " cluster"
}
return "Kubernetes cluster"
}
// summary is a cluster's state in a line, in the terms of its kind (#46).
func (v *ClusterView) summary() string {
count := func(n int) string { return humanCount(n) }
if p := v.Partition; p != nil {
var out []string
cpu := p.CPUPct
if v.Usage != nil && v.Usage.CPUOf > 0 {
cpu = &v.Usage.CPUPct // the last minute's, as the page shows
}
if cpu != nil {
out = append(out, fmt.Sprintf("CPU %.0f%%", *cpu))
}
out = append(out, fmt.Sprintf("system ASP %.0f%%", p.SystemASPPct))
if p.Subsystems > 0 {
out = append(out, fmt.Sprintf("%d of %d subsystems active", p.SubsystemsActive, p.Subsystems))
}
return strings.Join(out, " · ")
}
nodes := strings.ToLower(cmp.Or(v.NodeNoun, "Node")) + "s"
out := []string{fmt.Sprintf("%d/%d %s ready", v.NodesReady, v.Nodes, nodes)}
switch v.Noun {
case "Array":
out = append(out, count(v.Workloads)+" volumes")
if v.Usage != nil && v.Usage.IO != nil && v.Usage.IO.UsedOf > 0 {
out = append(out, fmt.Sprintf("%.0f%% used", 100*float64(v.Usage.IO.Used)/float64(v.Usage.IO.UsedOf)))
}
case "HMC":
out = append(out, count(v.Workloads)+" partitions")
case "Vault", "OpenBao":
out = append(out, count(v.Workloads)+" certificates")
case "vCenter", "Prism Central":
out = append(out, count(v.Workloads)+" VMs")
default:
out = append(out, count(v.Workloads)+" workloads")
}
return strings.Join(out, " · ")
}
// humanCount is n with thousands separated: 3,300.
func humanCount(n int) string {
s := strconv.Itoa(n)
for i := len(s) - 3; i > 0 && s[i-1] != '-'; i -= 3 {
s = s[:i] + "," + s[i:]
}
return s
}
// nodeNoun is what its nodes are: a FlashArray's are controllers, a
// FlashBlade's blades; a vCenter's and Prism Central's, hosts; an HMC's,
// Power servers.
@@ -1079,6 +1160,12 @@ type ClusterView struct {
NodeNoun string `json:"node_noun"`
// Partition is an IBM i partition's own numbers (docs/ibmi.md).
Partition *PartitionView `json:"partition,omitempty"`
// Group is the Clusters page's section: Kubernetes, Virtualization,
// Storage, IBM i or Secrets. Summary is one line fitted to the kind,
// for the dashboard and the maps: "31/32 nodes ready · 3,300
// workloads", "CPU 54% · system ASP 85% · 4 of 5 subsystems active".
Group string `json:"group"`
Summary string `json:"summary"`
}
// expectSubsystems marks an IBM i partition's subsystems that
@@ -1269,7 +1356,7 @@ func (srv *Server) clusterViews(now time.Time, conds []Condition) []ClusterView
if s.host {
continue // a host's VMs: on its page and Workloads, not Clusters
}
v := ClusterView{Name: s.name, Agent: s.agent, Problems: probs[s.name], Kinds: map[string]map[string]int{}, Noun: s.noun(), NodeNoun: s.nodeNoun()}
v := ClusterView{Name: s.name, Agent: s.agent, Problems: probs[s.name], Kinds: map[string]map[string]int{}, Noun: s.noun(), NodeNoun: s.nodeNoun(), Group: s.group()}
v.Status, v.Word, _ = srv.sourceStatus(s, now)
if !s.heard.IsZero() {
h := s.heard
@@ -1352,6 +1439,7 @@ func (srv *Server) clusterViews(now time.Time, conds []Condition) []ClusterView
if v.Status == "good" && v.Problems > 0 {
v.Status, v.Word = "warning", plural(v.Problems, "problem", "problems")
}
v.Summary = v.summary()
out = append(out, v)
}
return out
+46
View File
@@ -668,3 +668,49 @@ func TestLowerFirst(t *testing.T) {
}
}
}
// A cluster's summary says what matters for its kind (#46).
func TestClusterSummary(t *testing.T) {
cpu := 41.0
cases := []struct {
v ClusterView
want string
}{
{ClusterView{Noun: "Cluster", NodeNoun: "Node", Nodes: 32, NodesReady: 31, Workloads: 3300}, "31/32 nodes ready · 3,300 workloads"},
{ClusterView{Noun: "Partition", Partition: &PartitionView{CPUPct: &cpu, SystemASPPct: 84.6, Subsystems: 5, SubsystemsActive: 4}}, "CPU 41% · system ASP 85% · 4 of 5 subsystems active"},
{ClusterView{Noun: "Array", NodeNoun: "Controller", Nodes: 2, NodesReady: 2, Workloads: 600,
Usage: &UsageNow{IO: &report.IO{Used: 71, UsedOf: 100}}}, "2/2 controllers ready · 600 volumes · 71% used"},
{ClusterView{Noun: "HMC", NodeNoun: "Server", Nodes: 2, NodesReady: 2, Workloads: 6}, "2/2 servers ready · 6 partitions"},
}
for _, c := range cases {
if got := c.v.summary(); got != c.want {
t.Errorf("%s: %q, want %q", c.v.Noun, got, c.want)
}
}
if humanCount(1234567) != "1,234,567" || humanCount(999) != "999" {
t.Errorf("humanCount: %s %s", humanCount(1234567), humanCount(999))
}
}
// The service map says what a cluster is, not "Kubernetes cluster" for an
// HMC or a vCenter (#37); the Clusters page puts each in its section (#41).
func TestClusterKind(t *testing.T) {
snap := func(d string) wsnap {
return wsnap{recs: []report.Workload{{Kind: report.KindCluster, ID: report.ClusterSelf, Facts: map[string]any{"distribution": d}}}}
}
for d, want := range map[string][2]string{
"": {"Kubernetes cluster", "Kubernetes"},
"OpenShift": {"OpenShift cluster", "Kubernetes"},
"Proxmox VE": {"Proxmox cluster", "Virtualization"},
"vCenter": {"vCenter", "Virtualization"},
"Prism Central": {"Prism Central", "Virtualization"},
"HMC": {"HMC", "IBM i"},
"IBM i": {"IBM i partition", "IBM i"},
"Purity//FA": {"Pure array", "Storage"},
"OpenBao": {"OpenBao", "Secrets"},
} {
if got := [2]string{snap(d).kindLabel(), snap(d).group()}; got != want {
t.Errorf("%q: %v, want %v", d, got, want)
}
}
}
+2
View File
@@ -68,6 +68,8 @@ export interface Cluster {
usage?: Usage; history?: string;
/** What it is (Cluster, Array, vCenter, Prism Central) and what its nodes are (Node, Controller, Host). */
noun: string; node_noun: string;
/** The Clusters page's section (Kubernetes, Virtualization, Storage, IBM i, Secrets), and its state in a line, in its kind's terms. */
group: string; summary: string;
/** An IBM i partition's own numbers, in place of nodes. */
partition?: PartitionNums;
}
+3 -4
View File
@@ -111,8 +111,7 @@
<b class="mono">{k.name}</b>
<Status s={k.status} word={k.word} />
<span class="sub">{k.version ?? ''}</span>
<span><b class="mono">{k.nodes_ready}</b><span class="sub">/{k.nodes} {(k.node_noun || 'Node').toLowerCase()}s ready</span></span>
<span><b class="mono">{k.workloads}</b> <span class="sub">workloads</span></span>
<span class="sub sum">{k.summary}</span>
</a>
{/each}
</div>
@@ -189,8 +188,8 @@
.csum span { color: var(--muted-fg); font-size: 12px; }
.csum .bad b { color: var(--critical); }
.clist { display: grid; gap: 6px; }
.crow { display: grid; grid-template-columns: minmax(120px, 1.2fr) minmax(140px, 1.4fr) minmax(60px, .8fr) 1fr 1fr; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--foreground); }
.crow { display: grid; grid-template-columns: minmax(120px, 1.2fr) minmax(140px, 1.4fr) minmax(60px, .8fr) 2fr; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--foreground); }
.crow:hover { border-color: color-mix(in oklab, var(--primary) 45%, var(--border)); }
@media (max-width: 700px) { .crow { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .crow { grid-template-columns: 1fr 1fr; } .crow .sum { grid-column: 1 / -1; } }
@media (max-width: 860px) { .clock { text-align: left; } .csum { grid-template-columns: 1fr 1fr; } }
</style>
+72 -3
View File
@@ -1,4 +1,6 @@
<script lang="ts">
import { page } from '$app/state';
import { replaceState } from '$app/navigation';
import Icon from '$lib/Icon.svelte';
import Panel from '$lib/Panel.svelte';
import Status from '$lib/Status.svelte';
@@ -37,20 +39,78 @@
return s ? (m[s] ?? 0) : Object.values(m).reduce((a, b) => a + b, 0);
};
const href = (c: string, extra: Record<string, string>) => '/workloads?' + new URLSearchParams({ source: c, ...extra });
// Sections by kind, problems first in each, and filters that live in
// the address (#41): ?group=Storage&show=problems&q=prod.
const groups = ['Kubernetes', 'Virtualization', 'Storage', 'IBM i', 'Secrets'];
const u = page.url.searchParams;
let group = $state(u.get('group') ?? '');
let show = $state(u.get('show') ?? '');
let typed = $state(u.get('q') ?? '');
let q = $state(u.get('q') ?? '');
$effect(() => {
const t = typed;
const d = setTimeout(() => (q = t.trim()), 200);
return () => clearTimeout(d);
});
$effect(() => {
const p = new URLSearchParams();
for (const [k, v] of [['group', group], ['show', show], ['q', q]]) if (v) p.set(k, v);
try { replaceState('/clusters' + (p.size ? '?' + p : ''), {}); } catch { /* before the router is up */ }
});
const rank: Record<string, number> = { critical: 0, warning: 1, waiting: 2, off: 3, good: 4 };
const needsLook = (c: Cluster) => c.status === 'critical' || c.status === 'warning' || c.problems > 0;
const matches = (c: Full) => {
if (show === 'problems' && !needsLook(c)) return false;
if (!q) return true;
const f = q.toLowerCase();
return [c.name, c.title, c.read_by, c.version, c.noun].some((x) => x?.toLowerCase().includes(f));
};
const sections = $derived(
groups
.map((g) => {
const all = clusters.filter((c) => (c.group || 'Kubernetes') === g);
const shown = all.filter(matches).sort((a, b) => (rank[a.status] ?? 5) - (rank[b.status] ?? 5) || b.problems - a.problems || a.name.localeCompare(b.name));
return { g, all, shown, bad: all.filter(needsLook).length };
})
.filter((x) => x.all.length)
);
const anchor = (g: string) => 'kind-' + g.toLowerCase().replace(/[^a-z]+/g, '-');
const badCount = $derived(clusters.filter(needsLook).length);
</script>
<svelte:head><title>Cairn OBS · Clusters</title></svelte:head>
<div class="phead">
<span class="tile"><Icon name="cluster" /></span>
<div><h1>Clusters</h1><p>Each cluster a cluster agent watches: its nodes, and what runs on them by state. A node that's down is one problem, with what's on it listed under it.</p></div>
<div><h1>Clusters</h1><p>Everything Cairn OBS reads as a cluster, by kind: Kubernetes, hypervisor managers, arrays, IBM i and Vault. The ones that need a look come first in each. A node that's down is one problem, with what's on it listed under it.</p></div>
<div class="acts"><a class="btn sm" href="/workloads?show=problems"><Icon name="grid" /> Workloads that need a look</a></div>
</div>
{#if error}<p class="foot-note" style="color:var(--critical)">{error}</p>{/if}
{#if loaded && clusters.length === 0}<p class="empty">No clusters yet. A cluster agent adds its cluster once it has joined.</p>{/if}
{#each clusters as c (c.name)}
{#if clusters.length}
<nav class="jump" aria-label="Kinds of cluster">
{#each sections as x (x.g)}
<a href="#{anchor(x.g)}" class:dim={group && group !== x.g}>{x.g} <b>{x.all.length}</b>{#if x.bad}<span class="badn" title="{x.bad} need a look">{x.bad}</span>{/if}</a>
{/each}
</nav>
<div class="filters">
<Icon name="filter" />
<input class="input" placeholder="Name, version or what it is" aria-label="Find a cluster" bind:value={typed} style="width:240px" />
<button class="chip" class:on={group === ''} onclick={() => (group = '')}>All kinds</button>
{#each sections as x (x.g)}<button class="chip" class:on={group === x.g} onclick={() => (group = group === x.g ? '' : x.g)}>{x.g}</button>{/each}
<button class="chip" class:on={show === 'problems'} onclick={() => (show = show === 'problems' ? '' : 'problems')}>Need a look <b>{badCount}</b></button>
{#if group || show || q}<button class="btn sm" onclick={() => { group = ''; show = ''; typed = ''; q = ''; }}>Clear</button>{/if}
</div>
{/if}
{#each sections as x (x.g)}
{#if !group || group === x.g}
<h2 class="sect" id={anchor(x.g)}>{x.g} <span class="sub">{(x.shown.length === x.all.length ? `${x.all.length}` : `${x.shown.length} of ${x.all.length}`) + (x.bad ? ` · ${x.bad} ${x.bad === 1 ? 'needs' : 'need'} a look` : '')}</span></h2>
{#if !x.shown.length}<p class="empty">None match.</p>{/if}
{#each x.shown as c (c.name)}
<div class="mt">
<Panel title={c.title ? `${c.title} · read by ${c.read_by || c.name}` : c.name} aside={c.version ? `version ${c.version}` : ''}>
<div class="top">
@@ -93,7 +153,7 @@
{#each kinds as [k, label]}
{#if n(c, k)}
<tr>
<td><a href={href(c.name, { kind: k })}>{k === 'node' && c.node_noun ? c.node_noun + 's' : label}</a></td>
<td><a href={href(c.name, { kind: k })}>{k === 'node' && c.node_noun ? c.node_noun + 's' : k === 'vm' && c.noun === 'HMC' ? 'Partitions' : label}</a></td>
<td class="mono">{n(c, k)}</td>
{#each sevs as [s]}
<td class="mono">{#if n(c, k, s)}<a class="sv {s}" href={href(c.name, { kind: k, show: s === 'critical' || s === 'warning' ? 'problems' : s })}>{n(c, k, s)}</a>{:else}<span class="sub">0</span>{/if}</td>
@@ -114,10 +174,19 @@
{/if}
</Panel>
</div>
{/each}
{/if}
{/each}
<p class="foot-note">Refreshes every 10 seconds.</p>
<style>
.jump { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 10px; font-size: 13px; }
.jump a { color: var(--foreground); display: inline-flex; align-items: center; gap: 5px; }
.jump a b { font-family: var(--mono); color: var(--muted-fg); font-weight: 500; }
.jump a.dim { opacity: 0.5; }
.badn { font: 600 11px var(--mono); color: var(--critical); border: 1px solid color-mix(in oklab, var(--critical) 50%, transparent); border-radius: 9px; padding: 0 6px; }
.sect { font-size: 15px; margin: 22px 0 0; scroll-margin-top: 70px; display: flex; gap: 10px; align-items: baseline; }
.sect .sub { font-size: 12px; font-weight: 400; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.nums a, .nums > div { display: flex; flex-direction: column; color: var(--foreground); }