Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Fix Kubernetes pod demo history contracts

rcourtman05b132b11085
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 27a7e98ce8..c2da69eeed 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -624,6 +624,12 @@ surfaces that deep-link into recovery may still depend on those handlers, but
they must treat response `platform` / `platforms` as API-owned fields and use
legacy `provider` aliases only as compatibility fallback rather than reviving
provider-shaped transport assumptions in fleet flows.
+That same lifecycle boundary also relies on canonical Kubernetes pod metrics
+targets. Pod-facing drawers may expose `MetricsTarget.ResourceID` only as the
+history lookup coordinate, but they must keep the prefixed
+`k8s:<cluster>:pod:<uid>` contract and let metrics-history handlers
+canonicalize any legacy bare pod ID back onto that key, otherwise pod detail
+history and workload summary cards split onto different timelines.
The router now wires the tenant resource state provider during initial setup
when a multi-tenant monitor is present, so tenant-scoped fleet pages do not
trip a missing-provider 500 before the monitor has finished initializing.
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 62d7c92b16..05dcca2ed9 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -207,6 +207,11 @@ when the disabled candidate no longer counts toward monitored-system capacity.
monitor-owned aggregate summary cache rather than rehydrating each pool
chart on request.
28. Keep workload-chart response identity canonical on that same shared API surface: `internal/api/router.go`, `internal/api/contract_test.go`, and workload summary consumers must emit provider-backed VM and system-container series under the same canonical workload IDs that workloads page rows use, while resolving history through the unified `MetricsTarget.ResourceID`, so hover and focus selection do not fall off for provider-backed rows.
+ Kubernetes pod workload rows follow that same contract through their
+ metrics target. `/api/resources` may expose pod history only through the
+ unified `MetricsTarget.ResourceID`, but that target must be the canonical
+ prefixed runtime key `k8s:<cluster>:pod:<uid>` and not the bare source pod
+ ID, so pod workload rows and pod chart payloads stay on one history series.
29. Keep the hosted account portal bootstrap intelligible without duplicate
chrome. `internal/cloudcp/portal/page.go`, the maintained portal frontend
bundle, and the shared portal styles may refine layout density, but the
@@ -497,6 +502,14 @@ windows. `/api/metrics-store/history` must accept `resourceType=disk`, keep
`MetricsTarget.ResourceID` that unified resources already expose, instead of
leaving storage drawers or other callers to fork a disk-local history route or
invent an alternate disk identity.
+That same metrics-history contract also owns Kubernetes pod identity
+normalization. `/api/metrics-store/history` must accept legacy bare pod IDs
+such as `cluster-1:pod:pod-1`, canonicalize them onto the unified pod metrics
+target `k8s:cluster-1:pod:pod-1`, and keep the response `resourceId` on that
+canonical key. When store-backed history is absent, the handler must fall back
+to the same in-memory guest metrics cache that workload charts use for pods,
+so demo and mock Kubernetes charts do not go blank while aggregate workload
+charts still render.
The Pulse Account commercial shell now also owns a dedicated bootstrap
contract in `internal/cloudcp/portal/page.go`, `internal/cloudcp/portal/handlers.go`,
and `internal/cloudcp/portal/handlers_test.go`. `/api/portal/bootstrap` and
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index f1b79f3d70..cc7b266623 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -688,6 +688,11 @@ The aggregate `/api/charts/workloads-summary` endpoint now also has its own
explicit API p95 budget constant, aligned with the per-workload charts budget,
and `internal/api/slo_bench_test.go` must fail if that aggregate budget or its
store-backed mixed-workload benchmark coverage drifts.
+Those budgets also assume Kubernetes pod history lookups hit one canonical
+series key. Pod chart and history consumers must normalize bare pod IDs onto
+`k8s:<cluster>:pod:<uid>` before lookup; otherwise demo and mock workloads pay
+repeated empty-store misses and redundant refetch churn even while the shared
+workload charts already hold the same pod metrics in memory.
The infrastructure and workload summary cards now share a canonical
throughput-rate formatter in `frontend-modern/src/utils/throughputPresentation.ts`,
so bytes-per-second labels stay consistent between the two summary surfaces
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index a5e1058858..406460a16c 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -372,6 +372,12 @@ querying, and the operator-facing storage health presentation layer.
metrics targets, but infrastructure/workloads/storage/recovery navigation
and focus handoffs must stay on canonical workload IDs instead of
provider-native metric keys.
+ The same cross-surface rule applies when recovery-adjacent drawers or
+ summaries hand off Kubernetes pod history. Those surfaces may request pod
+ metrics only through the unified prefixed target
+ `k8s:<cluster>:pod:<uid>` and must rely on API-side canonicalization for
+ any legacy bare pod ID instead of inventing a recovery-local pod history
+ key.
20. Keep storage row emphasis on the shared frontend primitive contract. Pool
rows and physical-disk rows that mirror the active summary entity must
expose that state through `data-summary-row-active` and let the shared row
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 911a94b453..ba25e71a51 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -1177,6 +1177,14 @@ surface `MetricsTarget` only as the history lookup target, while workload
chart transport and hover/focus selection must keep using the canonical
workload row ID so provider-backed workloads such as VMware VMs stay aligned
with `/workloads` rows and summary cards.
+Kubernetes pods follow that same split. Pod rows may surface
+`MetricsTarget.ResourceID` only as the history lookup target, but that target
+must stay on the canonical prefixed runtime key
+`k8s:<cluster>:pod:<uid>` even when the underlying source-owned pod ID arrives
+as bare `<cluster>:pod:<uid>`. `/api/resources`, workload charts, and
+`/api/metrics-store/history` must therefore collapse onto that prefixed pod
+target instead of letting pod rows and pod charts drift onto separate metric
+series.
The drawer's discovery mapper also reuses that helper for pod fallback agent
IDs, so the resource-detail path and the dashboard path stay aligned on the
same cluster-name source of truth.
@@ -1505,6 +1513,12 @@ series just because one ingest path emitted `" host-1 "` and another emitted
`"host-1"`.
If the canonicalized target ID is empty after that normalization, the metrics
target must fail closed to `nil` instead of emitting an empty query coordinate.
+Kubernetes pod metrics targets must also canonicalize onto the shared
+`k8s:` runtime namespace before they become query coordinates. Bare pod source
+IDs such as `cluster-1:pod:pod-1` are discovery keys, not public history IDs;
+unified resources and history consumers must expose and query them as
+`k8s:cluster-1:pod:pod-1` so pod charts, drawer history, and workload summary
+cards stay on one owned series.
ReadState resource-resolution lookups must also normalize surrounding
whitespace on the incoming name before matching canonical resources. A valid
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index be263edfb1..82a8350e53 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -7945,6 +7945,57 @@ func TestContract_MetricsHistoryLiveFallbackJSONSnapshot(t *testing.T) {
assertJSONSnapshot(t, got, want)
}
+func TestContract_MetricsHistoryCanonicalizesLegacyKubernetesPodIDs(t *testing.T) {
+ mh := monitoring.NewMetricsHistory(1000, time.Hour)
+ now := time.Now().UTC().Truncate(time.Second)
+ legacyID := "cluster-1:pod:pod-1"
+ canonicalID := "k8s:" + legacyID
+ for i, value := range []float64{21, 34, 29} {
+ mh.AddGuestMetric(canonicalID, "cpu", value, now.Add(time.Duration(i-2)*10*time.Minute))
+ }
+
+ router := &Router{
+ monitor: &monitoring.Monitor{},
+ }
+ setUnexportedField(t, router.monitor, "metricsHistory", mh)
+
+ req := httptest.NewRequest(
+ http.MethodGet,
+ "/api/metrics-store/history?resourceType=k8s&resourceId="+legacyID+"&metric=cpu&range=30m",
+ nil,
+ )
+ rec := httptest.NewRecorder()
+ router.handleMetricsHistory(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
+ }
+
+ var resp metricsHistoryResponse
+ if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
+ t.Fatalf("failed to unmarshal response: %v", err)
+ }
+
+ if resp.ResourceType != "k8s" {
+ t.Fatalf("expected resourceType k8s, got %q", resp.ResourceType)
+ }
+ if resp.ResourceId != canonicalID {
+ t.Fatalf("expected canonical pod resource id %q, got %q", canonicalID, resp.ResourceId)
+ }
+ if resp.Metric != "cpu" {
+ t.Fatalf("expected metric cpu, got %q", resp.Metric)
+ }
+ if resp.Range != "30m" {
+ t.Fatalf("expected range 30m, got %q", resp.Range)
+ }
+ if resp.Source != "memory" {
+ t.Fatalf("expected source memory, got %q", resp.Source)
+ }
+ if len(resp.Points) != 3 {
+ t.Fatalf("expected 3 cpu points, got %d", len(resp.Points))
+ }
+}
+
func TestContract_MetricsHistoryPhysicalDiskIOLiveWindowUsesCanonicalDiskTarget(t *testing.T) {
mh := monitoring.NewMetricsHistory(1000, time.Hour)
now := time.Now().UTC().Truncate(time.Second)
diff --git a/internal/api/metrics_history_fallback_test.go b/internal/api/metrics_history_fallback_test.go
index 407c03a6e8..e9ea18f146 100644
--- a/internal/api/metrics_history_fallback_test.go
+++ b/internal/api/metrics_history_fallback_test.go
@@ -184,6 +184,50 @@ func TestMetricsHistoryDiskIOMetricsUseMemoryFallback(t *testing.T) {
}
}
+func TestMetricsHistoryKubernetesPodUsesMemoryFallback(t *testing.T) {
+ mh := monitoring.NewMetricsHistory(1000, time.Hour)
+ now := time.Now().UTC().Truncate(time.Second)
+ resourceID := "k8s:cluster-1:pod:pod-1"
+ for i, value := range []float64{18.5, 22.0, 19.0, 24.2} {
+ mh.AddGuestMetric(resourceID, "cpu", value, now.Add(time.Duration(i-3)*10*time.Minute))
+ }
+
+ monitor := &monitoring.Monitor{}
+ setUnexportedField(t, monitor, "metricsHistory", mh)
+
+ router := &Router{monitor: monitor}
+
+ req := httptest.NewRequest(
+ http.MethodGet,
+ "/api/metrics-store/history?resourceType=k8s&resourceId=cluster-1:pod:pod-1&metric=cpu&range=30m",
+ nil,
+ )
+ rec := httptest.NewRecorder()
+ router.handleMetricsHistory(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("expected status 200, got %d", rec.Code)
+ }
+
+ var resp metricsHistoryResponse
+ if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
+ t.Fatalf("failed to unmarshal response: %v", err)
+ }
+
+ if resp.Source != "memory" {
+ t.Fatalf("expected source memory, got %q", resp.Source)
+ }
+ if resp.ResourceId != resourceID {
+ t.Fatalf("expected canonical resourceId %q, got %q", resourceID, resp.ResourceId)
+ }
+ if resp.Metric != "cpu" {
+ t.Fatalf("expected metric cpu, got %q", resp.Metric)
+ }
+ if len(resp.Points) < 2 {
+ t.Fatalf("expected kubernetes pod history points, got %d", len(resp.Points))
+ }
+}
+
func TestMetricsHistoryStorageDiskAliasUsesMemory(t *testing.T) {
state := models.NewState()
state.UpdateStorageForInstance("pve1", []models.Storage{
diff --git a/internal/api/resources_test.go b/internal/api/resources_test.go
index a42374e735..09960e678d 100644
--- a/internal/api/resources_test.go
+++ b/internal/api/resources_test.go
@@ -1402,6 +1402,9 @@ func TestResourceListIncludesKubernetesPods(t *testing.T) {
if resource.MetricsTarget.ResourceType != string(unified.ResourceTypePod) {
t.Fatalf("metrics target type = %q, want %q", resource.MetricsTarget.ResourceType, unified.ResourceTypePod)
}
+ if resource.MetricsTarget.ResourceID != "k8s:cluster-1:pod:pod-1" {
+ t.Fatalf("metrics target resourceID = %q, want %q", resource.MetricsTarget.ResourceID, "k8s:cluster-1:pod:pod-1")
+ }
}
func TestResourceListFiltersCanonicalKubernetesNamespace(t *testing.T) {
diff --git a/internal/api/router.go b/internal/api/router.go
index 0474fc4fba..10eabb2d6e 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -8081,6 +8081,7 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
+ resourceID = canonicalizeMetricsHistoryResourceID(runtimeResourceType, resourceID)
// Parse time range
var duration time.Duration
@@ -8644,6 +8645,17 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
return nil, "", false
}
return buildHistoryPoints(points, stepSecs), historySourceMemory, true
+ case "k8s":
+ metrics := monitor.GetGuestMetrics(resourceID, duration)
+ points := metrics[metricType]
+ if len(points) == 0 {
+ livePoints := liveMetricPoints(runtimeResourceType, resourceID)
+ if live, ok := livePoints[metricType]; ok {
+ return buildHistoryPoints([]monitoring.MetricPoint{live}, 0), historySourceLive, true
+ }
+ return nil, "", false
+ }
+ return buildHistoryPoints(points, stepSecs), historySourceMemory, true
case "node":
points := monitor.GetNodeMetrics(resourceID, metricType, duration)
if len(points) == 0 {
@@ -8693,6 +8705,8 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
switch runtimeResourceType {
case "vm", "system-container", "oci-container":
metrics = monitor.GetGuestMetrics(resourceID, duration)
+ case "k8s":
+ metrics = monitor.GetGuestMetrics(resourceID, duration)
case "docker-host":
metrics = monitor.GetGuestMetrics(fmt.Sprintf("dockerHost:%s", resourceID), duration)
case "agent":
@@ -9000,6 +9014,17 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
}
+func canonicalizeMetricsHistoryResourceID(runtimeResourceType, resourceID string) string {
+ trimmed := strings.TrimSpace(resourceID)
+ if runtimeResourceType != "k8s" {
+ return trimmed
+ }
+ if strings.Contains(trimmed, ":pod:") {
+ return unifiedresources.CanonicalKubernetesPodMetricID(trimmed)
+ }
+ return trimmed
+}
+
func normalizeMetricsHistoryResourceType(input string) (responseType string, runtimeType string, storeTypes []string, err error) {
switch strings.ToLower(strings.TrimSpace(input)) {
case "node":
diff --git a/internal/unifiedresources/metrics_targets.go b/internal/unifiedresources/metrics_targets.go
index 57d81174f6..c0fb9df36b 100644
--- a/internal/unifiedresources/metrics_targets.go
+++ b/internal/unifiedresources/metrics_targets.go
@@ -91,7 +91,9 @@ func BuildMetricsTarget(resource Resource, sourceTargets []SourceTarget) *Metric
}
case ResourceTypePod:
if st, ok := bySource[SourceK8s]; ok {
- return &MetricsTarget{ResourceType: string(ResourceTypePod), ResourceID: st.SourceID}
+ if resourceID := CanonicalKubernetesPodMetricID(st.SourceID); resourceID != "" {
+ return &MetricsTarget{ResourceType: string(ResourceTypePod), ResourceID: resourceID}
+ }
}
case ResourceTypeK8sCluster:
if st, ok := bySource[SourceK8s]; ok {
@@ -118,6 +120,17 @@ func BuildMetricsTarget(resource Resource, sourceTargets []SourceTarget) *Metric
return nil
}
+func CanonicalKubernetesPodMetricID(sourceID string) string {
+ trimmed := strings.TrimSpace(sourceID)
+ if trimmed == "" {
+ return ""
+ }
+ if strings.HasPrefix(trimmed, "k8s:") {
+ return trimmed
+ }
+ return "k8s:" + trimmed
+}
+
func canonicalAppContainerMetricID(sourceID string) string {
trimmed := strings.TrimSpace(sourceID)
trimmed = strings.TrimPrefix(trimmed, "app:")
diff --git a/internal/unifiedresources/metrics_targets_test.go b/internal/unifiedresources/metrics_targets_test.go
index 4697daa43e..b01b6ed74b 100644
--- a/internal/unifiedresources/metrics_targets_test.go
+++ b/internal/unifiedresources/metrics_targets_test.go
@@ -110,10 +110,10 @@ func TestBuildMetricsTarget_CanonicalizesSourceIDWhitespace(t *testing.T) {
},
sourceTargets: []SourceTarget{{
Source: SourceK8s,
- SourceID: " ns/pod-1 ",
+ SourceID: " cluster-1:pod:pod-1 ",
}},
wantType: string(ResourceTypePod),
- wantID: "ns/pod-1",
+ wantID: "k8s:cluster-1:pod:pod-1",
},
}