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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix(ai): query capacity forecast history under metrics-target ID not canonical ID
rcourtman8fff04eac565
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 889c5c8766..23384be506 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -67,7 +67,13 @@ ingested as a time-series in metrics history; resources without recordedhistory cannot produce a forecast and must report its absence honestly ratherthan fabricate one, and stable-high (>=80%) pools with no clear fill trend mustcarry the deterministic "no fill trend" reading so the model's speculation-cannot override the verified trend.+cannot override the verified trend. The forecast must query utilization+history under the resource's metrics-target ID (the same key the monitoring+layer records under, exposed as `StoragePoolView.SourceID()`), not the+canonical resource ID; the two diverge for most storage sources, so querying+the canonical ID silently leaves the feature dormant. The forecast's own+`resourceID` stays canonical so it can still be stamped onto findings keyed by+canonical resource ID.The public Pulse Intelligence overview is a projection of those runtimecontracts, not a second Assistant tool inventory. It must point readers at thediff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.goindex 34b48e7252..b51f85bc80 100644--- a/internal/ai/patrol_ai.go+++ b/internal/ai/patrol_ai.go@@ -1593,7 +1593,11 @@ func (p *PatrolService) seedPrecomputeIntelligenceState(snap patrolRuntimeState,}}for _, s := range storageSources {- allMetrics := mh.GetAllStorageMetrics(s.id, 48*time.Hour)+ queryID := s.metricsID+ if strings.TrimSpace(queryID) == "" {+ queryID = s.id+ }+ allMetrics := mh.GetAllStorageMetrics(queryID, 48*time.Hour)if pts, ok := allMetrics["usage"]; ok && len(pts) >= 5 {addForecast(s.id, s.name, "usage", pts, s.usagePercent)}@@ -1739,12 +1743,12 @@ type patrolAppContainerRow struct {}type patrolStoragePoolRow struct {- id, name, stype, node, status string- used, total int64- hasBytes bool- usage float64- zfsRead, zfsWrite, zfsCksum int64- hasZFSErrors bool+ id, metricsID, name, stype, node, status string+ used, total int64+ hasBytes bool+ usage float64+ zfsRead, zfsWrite, zfsCksum int64+ hasZFSErrors bool}type patrolPhysicalDiskRow struct {@@ -1771,8 +1775,8 @@ type patrolPrecomputeGuestSource struct {}type patrolPrecomputeStorageSource struct {- id, name string- usagePercent float64+ id, metricsID, name string+ usagePercent float64}type patrolConnectionHealthEntry struct {@@ -2124,6 +2128,7 @@ func patrolStoragePoolRows(snap patrolRuntimeState, scopedSet map[string]bool) [rows = append(rows, patrolStoragePoolRow{id: spv.ID(),+ metricsID: spv.SourceID(),name: name,stype: stype,node: node,@@ -2200,8 +2205,14 @@ func patrolStoragePoolRows(snap patrolRuntimeState, scopedSet map[string]bool) [zfsCksum := r.Storage.ZFSChecksumErrorshasZFSErrors := r.Storage.IsZFS && (zfsRead > 0 || zfsWrite > 0 || zfsCksum > 0)+ metricsID := r.ID+ if r.MetricsTarget != nil && strings.TrimSpace(r.MetricsTarget.ResourceID) != "" {+ metricsID = strings.TrimSpace(r.MetricsTarget.ResourceID)+ }+rows = append(rows, patrolStoragePoolRow{id: r.ID,+ metricsID: metricsID,name: name,stype: stype,node: node,@@ -2368,6 +2379,7 @@ func patrolPrecomputeStorageSources(snap patrolRuntimeState, scopedSet map[strinfor _, s := range storageRows {rows = append(rows, patrolPrecomputeStorageSource{id: s.id,+ metricsID: s.metricsID,name: s.name,usagePercent: s.usage,})diff --git a/internal/ai/patrol_findings_forecast_test.go b/internal/ai/patrol_findings_forecast_test.goindex a4836583bf..960c260c06 100644--- a/internal/ai/patrol_findings_forecast_test.go+++ b/internal/ai/patrol_findings_forecast_test.go@@ -3,6 +3,9 @@ package aiimport ("testing""time"++ "github.com/rcourtman/pulse-go-rewrite/internal/models"+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources")func TestStampCapacityForecasts_AttachesToCapacityFindingByResourceID(t *testing.T) {@@ -175,3 +178,68 @@ func mustForecastMap(seeds []seedForecast) map[string]CapacityForecast {}return out}++func TestSeedPrecompute_StorageForecastQueriesMetricsTargetID(t *testing.T) {+ now := time.Now()+ ps := NewPatrolService(nil, nil)++ // Metrics history is recorded under the metrics-target ID+ // ("storage-metrics"), which differs from the canonical resource ID+ // ("storage-canonical"). Before the fix the forecast queried the+ // canonical ID and found nothing, leaving the feature dormant for every+ // storage type whose metrics target diverges from its canonical ID.+ series := func(start float64) []models.MetricPoint {+ return []models.MetricPoint{+ {Value: start, Timestamp: now.Add(-5 * time.Hour)},+ {Value: start + 2, Timestamp: now.Add(-4 * time.Hour)},+ {Value: start + 4, Timestamp: now.Add(-3 * time.Hour)},+ {Value: start + 6, Timestamp: now.Add(-2 * time.Hour)},+ {Value: start + 8, Timestamp: now.Add(-1 * time.Hour)},+ }+ }+ mh := &precomputeMetricsHistoryProvider{+ storage: map[string][]models.MetricPoint{+ "storage-metrics:usage": series(80),+ },+ }+ ps.SetMetricsHistoryProvider(mh)++ used := int64(850)+ total := int64(1000)+ pool := unifiedresources.Resource{+ ID: "storage-canonical",+ Name: "test-pool",+ Type: unifiedresources.ResourceTypeStorage,+ MetricsTarget: &unifiedresources.MetricsTarget{+ ResourceType: "storage",+ ResourceID: "storage-metrics",+ },+ Storage: &unifiedresources.StorageMeta{Type: "lvm"},+ Metrics: &unifiedresources.ResourceMetrics{+ Disk: &unifiedresources.MetricValue{+ Used: &used, Total: &total, Percent: 85,+ },+ },+ }++ snap := patrolRuntimeState{+ unifiedResourceProvider: &mockUnifiedResourceProvider{+ getByTypeFunc: func(rt unifiedresources.ResourceType) []unifiedresources.Resource {+ if rt == unifiedresources.ResourceTypeStorage {+ return []unifiedresources.Resource{pool}+ }+ return nil+ },+ },+ }++ intel := ps.seedPrecomputeIntelligenceState(snap, nil, now)+ if len(intel.forecasts) == 0 {+ t.Fatalf("expected a capacity forecast queried via the metrics-target ID, got none")+ }+ // The forecast resourceID must stay canonical so StampCapacityForecasts+ // can still match it to findings keyed by canonical resource ID.+ if intel.forecasts[0].resourceID != "storage-canonical" {+ t.Fatalf("forecast resourceID = %q, want canonical storage-canonical", intel.forecasts[0].resourceID)+ }+}