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
Tighten VMware degraded runtime contract
rcourtmana3a3c9754b24
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 01f217d99c..0619d13dcf 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -116,6 +116,11 @@ runtime failure. The client should preserve the usable base snapshot, recorddegraded enrichment issues on the snapshot, and let the poller publish thoseas `observed.degraded` plus summarized issue metadata instead of clearing theobserved contribution or pretending the refresh was fully healthy.+That same poller-owned partial-success model must also keep runtime+observability non-noisy. Repeated polls with the same degraded optional-read+issue classes should not emit a fresh warning every interval; monitoring+should log only when VMware optional enrichment first degrades, materially+changes, or recovers.That provider ownership now has a concrete phase-1 runtime seam:`internal/monitoring/vmware_poller.go` must keep VMware inventory on theshared supplemental-ingest path, declare `SourceVMware` as its owned source,diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 4dc9fbd79a..ac63dd1f0b 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -264,6 +264,90 @@ func TestContract_VMwareConnectionListCarriesObservedSummary(t *testing.T) {}}+func TestContract_VMwareConnectionListCarriesDegradedObservedSummary(t *testing.T) {+ setVMwareFeatureForTest(t, true)++ connection := config.VMwareVCenterInstance{+ ID: "conn-1",+ Name: "lab-vcenter",+ Host: "vcsa.lab.local",+ Port: 443,+ Username: "[email protected]",+ Password: "super-secret",+ Enabled: true,+ }+ handler, persistence := newVMwareHandlersForTest(t)+ if err := persistence.SaveVMwareConfig([]config.VMwareVCenterInstance{connection}); err != nil {+ t.Fatalf("seed vmware config: %v", err)+ }++ collectedAt := time.Date(2026, 3, 31, 18, 15, 0, 0, time.UTC)+ handler.statusMu.Lock()+ handler.statuses = map[string]vmwareConnectionRuntimeStatus{+ connection.ID: {+ Poll: &monitoring.VMwareConnectionPollStatus{+ IntervalSeconds: 60,+ LastSuccessAt: &collectedAt,+ },+ Observed: &monitoring.VMwareConnectionObservedSummary{+ CollectedAt: &collectedAt,+ Hosts: 4,+ VMs: 24,+ Datastores: 6,+ VIRelease: "8.0.3",+ Degraded: true,+ IssueCount: 3,+ Issues: []monitoring.VMwareConnectionObservedIssue{+ {+ Stage: "signals",+ Category: "permission",+ Message: "VMware permissions are insufficient for HostSystem overall status",+ Occurrences: 2,+ },+ {+ Stage: "topology",+ Category: "unavailable",+ Message: "VMware vm guest identity is temporarily unavailable",+ Occurrences: 1,+ },+ },+ },+ },+ }+ handler.statusMu.Unlock()++ req := httptest.NewRequest(http.MethodGet, "/api/vmware/connections", nil)+ rec := httptest.NewRecorder()+ handler.HandleList(rec, req)++ if rec.Code != http.StatusOK {+ t.Fatalf("expected 200, got %d: %s", rec.Code, rec.Body.String())+ }++ var responses []vmwareConnectionResponse+ if err := json.Unmarshal(rec.Body.Bytes(), &responses); err != nil {+ t.Fatalf("unmarshal vmware degraded list response: %v", err)+ }+ if len(responses) != 1 || responses[0].Observed == nil {+ t.Fatalf("expected 1 vmware connection with degraded observed summary, got %+v", responses)+ }+ if !responses[0].Observed.Degraded {+ t.Fatalf("expected degraded observed summary, got %+v", responses[0].Observed)+ }+ if responses[0].Observed.IssueCount != 3 {+ t.Fatalf("observed issueCount = %d, want 3", responses[0].Observed.IssueCount)+ }+ if len(responses[0].Observed.Issues) != 2 {+ t.Fatalf("observed issues len = %d, want 2", len(responses[0].Observed.Issues))+ }+ if responses[0].Observed.Issues[0].Stage != "signals" || responses[0].Observed.Issues[0].Occurrences != 2 {+ t.Fatalf("unexpected first observed issue: %+v", responses[0].Observed.Issues[0])+ }+ if responses[0].Observed.Issues[1].Stage != "topology" || responses[0].Observed.Issues[1].Occurrences != 1 {+ t.Fatalf("unexpected second observed issue: %+v", responses[0].Observed.Issues[1])+ }+}+func TestContract_SSOTestRejectsMetadataURLWithUserinfo(t *testing.T) {called := make(chan struct{}, 1)metadataServer := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex 8bbf5c9470..2fa6d1c54c 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -128,6 +128,14 @@ func TestVMwarePollerUsesCanonicalSupplementalIngestOwnership(t *testing.T) {"summary.Degraded = true","summary.IssueCount = len(snapshot.EnrichmentIssues)","summary.Issues = summarizeVMwareObservedIssues(snapshot.EnrichmentIssues)",+ "observedIssueKey string",+ "transition := p.recordConnectionSuccessLocked(entry.orgID, entry.connectionID, at, snapshot)",+ "classifyVMwareObservedTransition(status.observed, status.observedIssueKey, nextObserved, nextIssueKey)",+ "status.observedIssueKey = nextIssueKey",+ `strings.HasPrefix(transition.action, "refresh_partial")`,+ `action: "refresh_partial_changed",`,+ `action: "refresh_recovered",`,+ "func summarizeVMwareObservedIssueKey(issues []vmware.InventoryEnrichmentIssue) string {",}for _, snippet := range requiredSnippets {if !strings.Contains(source, snippet) {diff --git a/internal/monitoring/vmware_poller.go b/internal/monitoring/vmware_poller.goindex 6634c573cb..ef61cd62c6 100644--- a/internal/monitoring/vmware_poller.go+++ b/internal/monitoring/vmware_poller.go@@ -4,6 +4,7 @@ import ("context""errors""sort"+ "strconv""strings""sync""time"@@ -69,6 +70,13 @@ type vmwareConnectionRuntimeStatus struct {lastError *VMwareConnectionPollErrorconsecutiveFailures intobserved *VMwareConnectionObservedSummary+ observedIssueKey string+}++type vmwareObservedTransition struct {+ action string+ message string+ issueCount int}type vmwarePollerProvider interface {@@ -402,18 +410,9 @@ func (p *VMwarePoller) pollConnection(ctx context.Context, entry vmwarePollerProrecords := cloneIngestRecords(entry.provider.Records())changes := cloneResourceChanges(entry.provider.ActivityChanges())snapshot := entry.provider.Snapshot()- if snapshot != nil && len(snapshot.EnrichmentIssues) > 0 {- log.Warn().- Str("component", "vmware_poller").- Str("action", "refresh_partial").- Str("org_id", entry.orgID).- Str("connection_id", entry.connectionID).- Int("issue_count", len(snapshot.EnrichmentIssues)).- Msg("VMware poller refreshed base inventory with degraded optional enrichment")- }p.mu.Lock()- p.recordConnectionSuccessLocked(entry.orgID, entry.connectionID, at, snapshot)+ transition := p.recordConnectionSuccessLocked(entry.orgID, entry.connectionID, at, snapshot)if p.cachedRecordsByOrg[entry.orgID] == nil {p.cachedRecordsByOrg[entry.orgID] = make(map[string][]unifiedresources.IngestRecord)}@@ -423,6 +422,20 @@ func (p *VMwarePoller) pollConnection(ctx context.Context, entry vmwarePollerProp.cachedRecordsByOrg[entry.orgID][entry.connectionID] = recordsp.cachedChangesByOrg[entry.orgID][entry.connectionID] = changesp.mu.Unlock()++ if transition != nil {+ event := log.Info()+ if strings.HasPrefix(transition.action, "refresh_partial") {+ event = log.Warn()+ }+ event.+ Str("component", "vmware_poller").+ Str("action", transition.action).+ Str("org_id", entry.orgID).+ Str("connection_id", entry.connectionID).+ Int("issue_count", transition.issueCount).+ Msg(transition.message)+ }}func (p *VMwarePoller) providerEntries() []vmwarePollerProviderEntry {@@ -711,15 +724,21 @@ func (p *VMwarePoller) ensureConnectionRuntimeStatusLocked(orgID, connID string)return p.statusByOrg[orgID][connID]}-func (p *VMwarePoller) recordConnectionSuccessLocked(orgID, connID string, at time.Time, snapshot *vmware.InventorySnapshot) {+func (p *VMwarePoller) recordConnectionSuccessLocked(orgID, connID string, at time.Time, snapshot *vmware.InventorySnapshot) *vmwareObservedTransition {status := p.ensureConnectionRuntimeStatusLocked(orgID, connID)status.lastAttemptAt = atstatus.lastSuccessAt = atstatus.lastError = nilstatus.consecutiveFailures = 0if snapshot != nil {- status.observed = buildVMwareObservedSummary(snapshot)+ nextObserved := buildVMwareObservedSummary(snapshot)+ nextIssueKey := summarizeVMwareObservedIssueKey(snapshot.EnrichmentIssues)+ transition := classifyVMwareObservedTransition(status.observed, status.observedIssueKey, nextObserved, nextIssueKey)+ status.observed = nextObserved+ status.observedIssueKey = nextIssueKey+ return transition}+ return nil}func (p *VMwarePoller) recordConnectionFailureLocked(orgID, connID string, err error, at time.Time) {@@ -764,6 +783,7 @@ func (p *VMwarePoller) RecordConnectionTestSuccess(orgID, connID string, summaryDatastores: summary.Datastores,VIRelease: strings.TrimSpace(summary.VIRelease),}+ status.observedIssueKey = ""}}@@ -805,6 +825,33 @@ func buildVMwareObservedSummary(snapshot *vmware.InventorySnapshot) *VMwareConnereturn summary}+func classifyVMwareObservedTransition(previous *VMwareConnectionObservedSummary, previousIssueKey string, next *VMwareConnectionObservedSummary, nextIssueKey string) *vmwareObservedTransition {+ prevDegraded := previous != nil && previous.Degraded+ nextDegraded := next != nil && next.Degraded++ switch {+ case !prevDegraded && nextDegraded:+ return &vmwareObservedTransition{+ action: "refresh_partial",+ message: "VMware poller refreshed base inventory with degraded optional enrichment",+ issueCount: next.IssueCount,+ }+ case prevDegraded && nextDegraded && previousIssueKey != nextIssueKey:+ return &vmwareObservedTransition{+ action: "refresh_partial_changed",+ message: "VMware poller degraded optional enrichment changed",+ issueCount: next.IssueCount,+ }+ case prevDegraded && !nextDegraded:+ return &vmwareObservedTransition{+ action: "refresh_recovered",+ message: "VMware poller optional enrichment recovered",+ }+ default:+ return nil+ }+}+func classifyVMwarePollError(err error) string {if err == nil {return ""@@ -901,6 +948,27 @@ func summarizeVMwareObservedIssues(issues []vmware.InventoryEnrichmentIssue) []Vreturn summary}+func summarizeVMwareObservedIssueKey(issues []vmware.InventoryEnrichmentIssue) string {+ if len(issues) == 0 {+ return ""+ }++ counts := make(map[string]int, len(issues))+ for _, issue := range issues {+ key := strings.ToLower(strings.TrimSpace(issue.Stage)) + "\x00" ++ strings.ToLower(strings.TrimSpace(issue.Category)) + "\x00" ++ strings.ToLower(strings.TrimSpace(issue.Message))+ counts[key]+++ }++ parts := make([]string, 0, len(counts))+ for key, count := range counts {+ parts = append(parts, key+"\x00"+strconv.Itoa(count))+ }+ sort.Strings(parts)+ return strings.Join(parts, "\n")+}+func cloneVMwareObservedIssues(in []VMwareConnectionObservedIssue) []VMwareConnectionObservedIssue {if in == nil {return nildiff --git a/internal/monitoring/vmware_poller_test.go b/internal/monitoring/vmware_poller_test.goindex f0895bb000..17927310e5 100644--- a/internal/monitoring/vmware_poller_test.go+++ b/internal/monitoring/vmware_poller_test.go@@ -1,14 +1,18 @@package monitoringimport (+ "bytes""context""errors"+ "strings""testing""time""github.com/rcourtman/pulse-go-rewrite/internal/config""github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources""github.com/rcourtman/pulse-go-rewrite/internal/vmware"+ "github.com/rs/zerolog"+ "github.com/rs/zerolog/log")func TestVMwarePollerPollsConfiguredConnections(t *testing.T) {@@ -306,3 +310,116 @@ func TestVMwarePollerPublishesDegradedObservedSummaryOnPartialSuccess(t *testingt.Fatalf("expected aggregated permission issue first, got %+v", summary.Observed.Issues[0])}}++type sequencedVMwarePollerProvider struct {+ snapshots []*vmware.InventorySnapshot+ index int+ current *vmware.InventorySnapshot+}++func (p *sequencedVMwarePollerProvider) Refresh(context.Context) error {+ if len(p.snapshots) == 0 {+ p.current = nil+ return nil+ }+ if p.index >= len(p.snapshots) {+ p.current = p.snapshots[len(p.snapshots)-1]+ return nil+ }+ p.current = p.snapshots[p.index]+ p.index+++ return nil+}++func (p *sequencedVMwarePollerProvider) Records() []unifiedresources.IngestRecord { return nil }+func (p *sequencedVMwarePollerProvider) ActivityChanges() []unifiedresources.ResourceChange {+ return nil+}+func (p *sequencedVMwarePollerProvider) Snapshot() *vmware.InventorySnapshot { return p.current }+func (p *sequencedVMwarePollerProvider) Close() {}++func TestVMwarePollerLogsDegradedTransitionsOnlyWhenStateChanges(t *testing.T) {+ logs := captureVMwarePollerLogs(t)+ poller := NewVMwarePoller(nil, time.Minute)+ connection := config.NewVMwareVCenterInstance()+ connection.ID = "vc-log"+ connection.Host = "vc.log.local"+ connection.Username = "[email protected]"+ connection.Password = "secret"++ issueA := vmware.InventoryEnrichmentIssue{+ Stage: "signals",+ Category: "permission",+ Message: "VMware permissions are insufficient for HostSystem overall status",+ }+ issueB := vmware.InventoryEnrichmentIssue{+ Stage: "topology",+ Category: "unavailable",+ Message: "VMware vm guest identity is temporarily unavailable",+ }+ provider := &sequencedVMwarePollerProvider{+ snapshots: []*vmware.InventorySnapshot{+ {+ ConnectionID: connection.ID,+ CollectedAt: time.Date(2026, 3, 31, 11, 0, 0, 0, time.UTC),+ Hosts: []vmware.InventoryHost{{Host: "host-101", Name: "esxi-01"}},+ EnrichmentIssues: []vmware.InventoryEnrichmentIssue{issueA, issueA},+ },+ {+ ConnectionID: connection.ID,+ CollectedAt: time.Date(2026, 3, 31, 11, 1, 0, 0, time.UTC),+ Hosts: []vmware.InventoryHost{{Host: "host-101", Name: "esxi-01"}},+ EnrichmentIssues: []vmware.InventoryEnrichmentIssue{issueA, issueA},+ },+ {+ ConnectionID: connection.ID,+ CollectedAt: time.Date(2026, 3, 31, 11, 2, 0, 0, time.UTC),+ Hosts: []vmware.InventoryHost{{Host: "host-101", Name: "esxi-01"}},+ EnrichmentIssues: []vmware.InventoryEnrichmentIssue{issueB},+ },+ {+ ConnectionID: connection.ID,+ CollectedAt: time.Date(2026, 3, 31, 11, 3, 0, 0, time.UTC),+ Hosts: []vmware.InventoryHost{{Host: "host-101", Name: "esxi-01"}},+ },+ },+ }++ entry := vmwarePollerProviderEntry{+ orgID: "default",+ connectionID: connection.ID,+ provider: provider,+ }+ for i := 0; i < 4; i++ {+ poller.pollConnection(context.Background(), entry)+ }++ output := logs.String()+ if got := strings.Count(output, `"action":"refresh_partial"`); got != 1 {+ t.Fatalf("expected one refresh_partial warning, got %d logs: %s", got, output)+ }+ if got := strings.Count(output, `"action":"refresh_partial_changed"`); got != 1 {+ t.Fatalf("expected one refresh_partial_changed warning, got %d logs: %s", got, output)+ }+ if got := strings.Count(output, `"action":"refresh_recovered"`); got != 1 {+ t.Fatalf("expected one refresh_recovered info log, got %d logs: %s", got, output)+ }++ summary := poller.ConnectionSummaries("default", []config.VMwareVCenterInstance{connection})[connection.ID]+ if summary.Observed == nil || summary.Observed.Degraded {+ t.Fatalf("expected recovered observed summary after final healthy poll, got %+v", summary.Observed)+ }+}++func captureVMwarePollerLogs(t *testing.T) *bytes.Buffer {+ t.Helper()++ var buf bytes.Buffer+ origLogger := log.Logger+ log.Logger = zerolog.New(&buf).Level(zerolog.DebugLevel).With().Timestamp().Logger()+ t.Cleanup(func() {+ log.Logger = origLogger+ })++ return &buf+}