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.

Keep mixed host history from claiming a single source

pulse-triage[bot]8925065c5ccd
diff --git a/internal/api/router.go b/internal/api/router.go
index 3338fbfc9d..ba33c16d7a 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -7384,6 +7384,7 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
// Convert to frontend format
if response == nil {
apiData := make(map[string][]map[string]interface{})
+ mixedHostHistory := false
for metric, points := range metricsMap {
apiPoints := make([]map[string]interface{}, len(points))
for i, p := range points {
@@ -7425,7 +7426,7 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
}
if len(withinWindow) > 0 {
apiData[metric] = buildHistoryPoints(withinWindow, stepSecs)
- source = historySourceMemory
+ mixedHostHistory = true
}
}
}
@@ -7464,6 +7465,12 @@ func (r *Router) handleMetricsHistory(w http.ResponseWriter, req *http.Request)
"metrics": apiData,
"source": source,
}
+ if mixedHostHistory {
+ // The optional hint describes no single origin in this reply:
+ // stored CPU/capacity survives beside native or ring I/O. Calling
+ // all of it "memory" falsely says the history store has no data.
+ delete(response.(map[string]interface{}), "source")
+ }
}
}
diff --git a/internal/api/truenas_host_io_history_test.go b/internal/api/truenas_host_io_history_test.go
index 29950fd786..325b7fdfdd 100644
--- a/internal/api/truenas_host_io_history_test.go
+++ b/internal/api/truenas_host_io_history_test.go
@@ -231,6 +231,7 @@ func TestTrueNASHostIOHistoryWithPartialStore(t *testing.T) {
rec := request(token, "org-host-io", "agent", "host-io-target", "")
var result struct {
Metrics map[string][]hostIOHistoryPoint
+ Source *string
}
if rec.Code != 200 || json.Unmarshal(rec.Body.Bytes(), &result) != nil {
t.Fatalf("host history %d %s", rec.Code, rec.Body.String())
@@ -238,6 +239,13 @@ func TestTrueNASHostIOHistoryWithPartialStore(t *testing.T) {
if (len(result.Metrics["diskread"]) > 0) != test.read || (len(result.Metrics["diskwrite"]) > 0) != test.write {
t.Fatalf("host I/O completeness: read=%d write=%d want %t/%t", len(result.Metrics["diskread"]), len(result.Metrics["diskwrite"]), test.read, test.write)
}
+ if test.read || test.write {
+ if result.Source != nil {
+ t.Fatal("mixed native/stored history claimed a single source")
+ }
+ } else if result.Source == nil || *result.Source != "store" {
+ t.Fatal("unchanged stored history lost its source hint")
+ }
if f.reads.Load()-before != 1 || other.reads.Load() != 0 {
t.Fatalf("host fallback read other appliance or lost its one-request bound: reads %d/%d", f.reads.Load()-before, other.reads.Load())
}