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.

Deduplicate rebuilt PBS storage samples

pulse-triage[bot]a91b6da37d63
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 0b4f5da6e4..273ee87c2a 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -7578,6 +7578,16 @@ monitor select loop is progressing; agent report success or failure cannot
independently assert that Pulse is healthy. Agent-lifecycle behavior and proof
routes remain unchanged.
+### Unified storage history does not alter agent lifecycle state
+
+`internal/monitoring/monitor.go` may preserve a unified storage metric's source
+observation time while projecting it into history, but that shared monitoring
+path has no host enrollment authority. A storage-history sync must not clear or
+rewrite durable host-removal entries, admit a report from a denied credential,
+or create agent continuity evidence. The removal lifecycle proof keeps a
+removed host blocked across a PBS storage sync so metric timestamp maintenance
+cannot become an accidental re-enrollment transition.
+
### Deploy enrollment swaps credentials as one durable transition
A deploy bootstrap token remains the live credential until Pulse can durably
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 91e217b41b..d39d984839 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -1852,6 +1852,20 @@ metrics into persisted history, it must append in-memory history first and
flush the backing store through one `metrics.WriteBatchSync` batch per sync
sweep instead of per-metric async writes, so canonical chart history cannot
race itself into partial persisted windows.
+
+### Unified storage rebuilds preserve source observation time
+
+Canonical resource-store rebuilds are projections, not fresh storage polls.
+When `internal/monitoring/monitor.go` syncs a non-native storage metric into
+in-memory and persisted history, every metric in that projected observation
+must use the selected metric source's `SourceStatus.LastSeen`. If that source
+timestamp is unavailable, the resource `LastSeen` is the continuity fallback;
+wall-clock sync time is used only when neither observation timestamp exists.
+Repeated registry rebuilds of one unchanged PBS datastore observation must
+therefore replace the same timestamped history point rather than create a new
+raw point for each unrelated provider completion. This does not change the
+native Proxmox storage writer exclusion or canonical storage target selection.
+
That same chart boundary now also owns long-range in-memory coverage
selection. `internal/monitoring/metrics_history.go` must expose guest and node
coverage spans for the requested metric families, and
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 5247f32e29..e5f1268f72 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -5385,7 +5385,7 @@ func (m *Monitor) syncUnifiedStorageMetrics(store ResourceStoreInterface) {
now := time.Now()
storeWrites := make([]metrics.WriteMetric, 0)
- appendStoreWrite := func(resourceType, resourceID, metricType string, value float64) {
+ appendStoreWrite := func(resourceType, resourceID, metricType string, value float64, observedAt time.Time) {
if m.metricsStore == nil {
return
}
@@ -5394,7 +5394,7 @@ func (m *Monitor) syncUnifiedStorageMetrics(store ResourceStoreInterface) {
ResourceID: resourceID,
MetricType: metricType,
Value: value,
- Timestamp: now,
+ Timestamp: observedAt,
Tier: metrics.TierRaw,
})
}
@@ -5434,6 +5434,7 @@ func (m *Monitor) syncUnifiedStorageMetrics(store ResourceStoreInterface) {
seenTargets[targetID] = struct{}{}
disk := resource.Metrics.Disk
+ observedAt := unifiedMetricObservedAt(resource, disk, now)
usage := disk.Percent
used := int64(0)
total := int64(0)
@@ -5452,18 +5453,18 @@ func (m *Monitor) syncUnifiedStorageMetrics(store ResourceStoreInterface) {
}
if m.metricsHistory != nil {
- m.metricsHistory.AddStorageMetric(targetID, "usage", usage, now)
+ m.metricsHistory.AddStorageMetric(targetID, "usage", usage, observedAt)
if total > 0 {
- m.metricsHistory.AddStorageMetric(targetID, "used", float64(used), now)
- m.metricsHistory.AddStorageMetric(targetID, "total", float64(total), now)
- m.metricsHistory.AddStorageMetric(targetID, "avail", float64(free), now)
+ m.metricsHistory.AddStorageMetric(targetID, "used", float64(used), observedAt)
+ m.metricsHistory.AddStorageMetric(targetID, "total", float64(total), observedAt)
+ m.metricsHistory.AddStorageMetric(targetID, "avail", float64(free), observedAt)
}
}
- appendStoreWrite("storage", targetID, "usage", usage)
+ appendStoreWrite("storage", targetID, "usage", usage, observedAt)
if total > 0 {
- appendStoreWrite("storage", targetID, "used", float64(used))
- appendStoreWrite("storage", targetID, "total", float64(total))
- appendStoreWrite("storage", targetID, "avail", float64(free))
+ appendStoreWrite("storage", targetID, "used", float64(used), observedAt)
+ appendStoreWrite("storage", targetID, "total", float64(total), observedAt)
+ appendStoreWrite("storage", targetID, "avail", float64(free), observedAt)
}
}
if len(storeWrites) > 0 {
@@ -5471,6 +5472,22 @@ func (m *Monitor) syncUnifiedStorageMetrics(store ResourceStoreInterface) {
}
}
+// unifiedMetricObservedAt returns the source observation time represented by a
+// canonical metric. Registry rebuilds can happen several times during one
+// polling cycle; using rebuild time here would turn one upstream observation
+// into several distinct history samples.
+func unifiedMetricObservedAt(resource unifiedresources.Resource, metric *unifiedresources.MetricValue, fallback time.Time) time.Time {
+ if metric != nil && metric.Source != "" {
+ if status, ok := resource.SourceStatus[metric.Source]; ok && !status.LastSeen.IsZero() {
+ return status.LastSeen
+ }
+ }
+ if !resource.LastSeen.IsZero() {
+ return resource.LastSeen
+ }
+ return fallback
+}
+
func (m *Monitor) syncUnifiedPhysicalDiskMetrics(store ResourceStoreInterface) {
if store == nil || m.metricsStore == nil {
return
diff --git a/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go b/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go
index a86772836f..3b9eac2272 100644
--- a/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go
+++ b/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go
@@ -763,3 +763,52 @@ func TestHostAgentRemovalLifecycleOrdersConcurrentReportsBeforeDeletion(t *testi
t.Fatal("old token reported after concurrent deletion completed")
}
}
+
+func TestUnifiedStorageMetricSyncPreservesHostRemovalBlock(t *testing.T) {
+ monitor := newHostRemovalLifecycleMonitor(t, t.TempDir())
+ now := time.Now().UTC().Truncate(time.Second)
+ report := hostRemovalLifecycleReport(
+ "storage-sync-machine",
+ "storage-sync-machine",
+ "storage-sync-agent",
+ "storage-sync.local",
+ "linux",
+ now,
+ )
+ token := &config.APITokenRecord{ID: "storage-sync-token", CreatedAt: now.Add(-time.Hour)}
+ host, err := monitor.ApplyHostReport(report, token)
+ if err != nil {
+ t.Fatalf("initial ApplyHostReport: %v", err)
+ }
+ if _, err := monitor.RemoveHostAgent(host.ID); err != nil {
+ t.Fatalf("RemoveHostAgent: %v", err)
+ }
+
+ resourceStore := unifiedresources.NewMonitorAdapter(nil)
+ resourceStore.PopulateFromSnapshot(models.StateSnapshot{
+ PBSInstances: []models.PBSInstance{{
+ ID: "pbs-lifecycle-boundary",
+ Name: "pbs-lifecycle-boundary",
+ Status: "online",
+ LastSeen: now,
+ Datastores: []models.PBSDatastore{{
+ Name: "backups",
+ Status: "available",
+ Total: 1000,
+ Used: 400,
+ Free: 600,
+ Usage: 40,
+ }},
+ }},
+ })
+ monitor.metricsHistory = NewMetricsHistory(16, time.Hour)
+ monitor.syncUnifiedStorageMetrics(resourceStore)
+
+ if got := monitor.hostContinuityStore.RemovedEntries(); len(got) != 1 {
+ t.Fatalf("storage metric sync changed durable removal entries: %+v", got)
+ }
+ report.Timestamp = now.Add(time.Minute)
+ if _, err := monitor.ApplyHostReport(report, token); err == nil {
+ t.Fatal("storage metric sync allowed a removed host to report with its denied token")
+ }
+}
diff --git a/internal/monitoring/monitor_polling_test.go b/internal/monitoring/monitor_polling_test.go
index 12ae7c1c47..b9f0169168 100644
--- a/internal/monitoring/monitor_polling_test.go
+++ b/internal/monitoring/monitor_polling_test.go
@@ -592,6 +592,79 @@ func TestSyncUnifiedAppContainerMetricsRecordsTrueNASHistory(t *testing.T) {
}
}
+func TestSyncUnifiedStorageMetricsUsesPBSObservationTimeAcrossRegistryRebuilds(t *testing.T) {
+ observedAt := time.Now().UTC().Add(-time.Minute).Truncate(time.Second)
+ resourceStore := unifiedresources.NewMonitorAdapter(nil)
+ resourceStore.PopulateFromSnapshot(models.StateSnapshot{
+ PBSInstances: []models.PBSInstance{{
+ ID: "pbs-main",
+ Name: "pbs-main",
+ Status: "online",
+ LastSeen: observedAt,
+ Datastores: []models.PBSDatastore{{
+ Name: "backups",
+ Status: "available",
+ Total: 1000,
+ Used: 400,
+ Free: 600,
+ Usage: 40,
+ }},
+ }},
+ })
+
+ var targetID string
+ for _, resource := range resourceStore.GetAll() {
+ if resource.Type != unifiedresources.ResourceTypeStorage || resource.Storage == nil || resource.Storage.Platform != "pbs" {
+ continue
+ }
+ target := resourceStore.MetricsTargetForResource(resource.ID)
+ if target == nil || target.ResourceType != "storage" {
+ t.Fatalf("unexpected PBS datastore metrics target: %+v", target)
+ }
+ targetID = target.ResourceID
+ break
+ }
+ if targetID == "" {
+ t.Fatal("expected a PBS datastore in the unified resource store")
+ }
+
+ cfg := metrics.DefaultConfig(t.TempDir())
+ persistentStore, err := metrics.NewStore(cfg)
+ if err != nil {
+ t.Fatalf("metrics.NewStore() error = %v", err)
+ }
+ defer func() { _ = persistentStore.Close() }()
+
+ monitor := &Monitor{
+ metricsHistory: NewMetricsHistory(1024, 24*time.Hour),
+ metricsStore: persistentStore,
+ }
+
+ // PVE node completions and read-side refreshes can rebuild the registry
+ // repeatedly without a new PBS poll. They must not invent fresh samples.
+ monitor.syncUnifiedStorageMetrics(resourceStore)
+ monitor.syncUnifiedStorageMetrics(resourceStore)
+
+ inMemory := monitor.GetStorageMetrics(targetID, time.Hour)["usage"]
+ if len(inMemory) != 1 {
+ t.Fatalf("in-memory PBS usage points = %d, want one per source observation: %+v", len(inMemory), inMemory)
+ }
+ if !inMemory[0].Timestamp.Equal(observedAt) {
+ t.Fatalf("in-memory PBS usage timestamp = %s, want source observation %s", inMemory[0].Timestamp, observedAt)
+ }
+
+ persisted, err := persistentStore.Query("storage", targetID, "usage", observedAt.Add(-time.Second), observedAt.Add(time.Second), 0)
+ if err != nil {
+ t.Fatalf("query persisted PBS usage: %v", err)
+ }
+ if len(persisted) != 1 {
+ t.Fatalf("persisted PBS usage points = %d, want one per source observation: %+v", len(persisted), persisted)
+ }
+ if !persisted[0].Timestamp.Equal(observedAt) {
+ t.Fatalf("persisted PBS usage timestamp = %s, want source observation %s", persisted[0].Timestamp, observedAt)
+ }
+}
+
func TestSyncUnifiedAppContainerMetricsSkipsMockOwnedTrueNASHistoryWhenMockEnabled(t *testing.T) {
previousFeature := truenas.IsFeatureEnabled()
truenas.SetFeatureEnabled(true)