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
Harden canonical infrastructure counting coverage
rcourtman91fe294a0c42
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 8139dc6e5c..f68c354c21 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -157,6 +157,13 @@ agent IDs, connector-stable primary IDs, or the existing high-confidenceidentity matcher, and it may use exact-host attachment only as a boundedfallback onto a uniquely better existing surface. Friendly display names arepresentation-only and must not participate in monitored-system counting.+URL-backed host fields must be normalized down to canonical hostnames before+they participate in exact-host fallback attachment, and Kubernetes cluster+ownership metadata such as `AgentID` must not collapse a cluster into the+underlying host's monitored-system identity. The canonical resolver coverage+is pinned by an explicit top-level source matrix and mixed-environment+characterization tests so new top-level sources cannot quietly bypass the+counting contract.The unified-resource runtime now also owns the durable change timeline for thecanonical resource view. `internal/unifiedresources/monitor_adapter.go` feedsdiff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.goindex 22b722020d..54969bc386 100644--- a/internal/unifiedresources/code_standards_test.go+++ b/internal/unifiedresources/code_standards_test.go@@ -599,6 +599,7 @@ func TestTopLevelSystemResolverPinsCanonicalInfrastructureCounting(t *testing.T)"ResolveTopLevelSystems(resources []Resource) TopLevelSystemResolver","match.Confidence < HighConfidenceThreshold","monitoredSystemCandidateAllowsHostAttachment(candidate)",+ "When adding a new top-level monitored-system source, update:",},}for name, snippets := range requiredSnippets {diff --git a/internal/unifiedresources/top_level_systems.go b/internal/unifiedresources/top_level_systems.goindex 1025e0b594..88c840fbd1 100644--- a/internal/unifiedresources/top_level_systems.go+++ b/internal/unifiedresources/top_level_systems.go@@ -293,6 +293,13 @@ func buildTopLevelSystemNode(resource *Resource) topLevelSystemNode {}}+// When adding a new top-level monitored-system source, update:+// - topLevelSystemStrongIDs+// - topLevelSystemExactHosts+// - topLevelSystemExactIPs+// - monitoredSystemCandidateStrongIDs when candidate matching is exposed+// - TestResolveTopLevelSystemsTopLevelSourceMatrix+// - TestResolveTopLevelSystemsMixedEnvironmentCharacterizationfunc topLevelSystemStrongIDs(resource Resource) map[string]struct{} {ids := make(map[string]struct{})@@ -340,9 +347,6 @@ func topLevelSystemStrongIDs(resource Resource) map[string]struct{} {if clusterID := strings.TrimSpace(resource.Kubernetes.ClusterID); clusterID != "" {ids["k8s:"+clusterID] = struct{}{}}- if agentID := strings.TrimSpace(resource.Kubernetes.AgentID); agentID != "" {- ids["agent:"+agentID] = struct{}{}- }}return ids@@ -357,9 +361,9 @@ func topLevelSystemExactHosts(resource Resource) map[string]struct{} {canonicalPMGHostname(resource),canonicalTrueNASHostname(resource),canonicalProxmoxNodeName(resource),- firstTrimmed(topLevelSystemProxmoxHostURL(resource)),- firstTrimmed(topLevelSystemPBSHostURL(resource)),- firstTrimmed(topLevelSystemKubernetesServer(resource)),+ extractHostname(firstTrimmed(topLevelSystemProxmoxHostURL(resource))),+ extractHostname(firstTrimmed(topLevelSystemPBSHostURL(resource))),+ extractHostname(firstTrimmed(topLevelSystemKubernetesServer(resource))),firstTrimmed(topLevelSystemCanonicalHostname(resource)),} {if normalized := topLevelSystemNormalizeHost(candidate); normalized != "" {@@ -495,8 +499,10 @@ func monitoredSystemCandidateStrongIDs(candidate MonitoredSystemCandidate) map[sif machineID := strings.TrimSpace(candidate.MachineID); machineID != "" {ids["machine:"+machineID] = struct{}{}}- if agentID := strings.TrimSpace(candidate.AgentID); agentID != "" {- ids["agent:"+agentID] = struct{}{}+ if candidate.Type != ResourceTypeK8sCluster {+ if agentID := strings.TrimSpace(candidate.AgentID); agentID != "" {+ ids["agent:"+agentID] = struct{}{}+ }}return ids}diff --git a/internal/unifiedresources/top_level_systems_test.go b/internal/unifiedresources/top_level_systems_test.gonew file mode 100644index 0000000000..353556a6d0--- /dev/null+++ b/internal/unifiedresources/top_level_systems_test.go@@ -0,0 +1,287 @@+package unifiedresources++import "testing"++func TestResolveTopLevelSystemsTopLevelSourceMatrix(t *testing.T) {+ testCases := []struct {+ name string+ resources []Resource+ wantCount int+ same [][2]string+ different [][2]string+ }{+ {+ name: "agent and docker host share one top-level system",+ resources: []Resource{+ topLevelTestAgent("agent-host", "tower.local", "machine-1", "agent-1"),+ topLevelTestDockerHost("docker-host", "tower.local", "docker-runtime-1", "agent-1"),+ },+ wantCount: 1,+ same: [][2]string{{"agent-host", "docker-host"}},+ },+ {+ name: "agent and proxmox node share one top-level system",+ resources: []Resource{+ topLevelTestAgent("agent-host", "tower.local", "machine-1", "agent-1"),+ topLevelTestProxmoxNode("proxmox-node", "tower", "proxmox-1", "https://tower.local:8006"),+ },+ wantCount: 1,+ same: [][2]string{{"agent-host", "proxmox-node"}},+ },+ {+ name: "agent and truenas share one top-level system",+ resources: []Resource{+ topLevelTestAgent("agent-host", "archive.local", "machine-1", "agent-1"),+ topLevelTestTrueNAS("truenas-system", "archive.local"),+ },+ wantCount: 1,+ same: [][2]string{{"agent-host", "truenas-system"}},+ },+ {+ name: "agent and pbs share one top-level system",+ resources: []Resource{+ topLevelTestAgent("agent-host", "backup.local", "machine-1", "agent-1"),+ topLevelTestPBS("pbs-system", "backup.local", "pbs-1"),+ },+ wantCount: 1,+ same: [][2]string{{"agent-host", "pbs-system"}},+ },+ {+ name: "agent and pmg share one top-level system",+ resources: []Resource{+ topLevelTestAgent("agent-host", "mail.local", "machine-1", "agent-1"),+ topLevelTestPMG("pmg-system", "mail.local", "pmg-1"),+ },+ wantCount: 1,+ same: [][2]string{{"agent-host", "pmg-system"}},+ },+ {+ name: "kubernetes cluster remains separate even when the managing agent id is shared",+ resources: []Resource{+ topLevelTestAgent("agent-host", "cluster-host.local", "machine-1", "agent-1"),+ topLevelTestK8sCluster("cluster-1", "cluster-1", "agent-1", "https://cluster-host.local:6443"),+ },+ wantCount: 2,+ different: [][2]string{{"agent-host", "cluster-1"}},+ },+ {+ name: "equal-priority hostname-only hosts stay separate",+ resources: []Resource{+ topLevelTestAgentWithoutMachineID("host-a", "shared.local", "agent-1"),+ topLevelTestAgentWithoutMachineID("host-b", "shared.local", "agent-2"),+ },+ wantCount: 2,+ different: [][2]string{{"host-a", "host-b"}},+ },+ {+ name: "lower-priority fallback stays separate when host ownership is ambiguous",+ resources: []Resource{+ topLevelTestAgentWithoutMachineID("host-a", "shared.local", "agent-1"),+ topLevelTestAgentWithoutMachineID("host-b", "shared.local", "agent-2"),+ topLevelTestPBS("pbs-a", "shared.local", "pbs-1"),+ },+ wantCount: 3,+ different: [][2]string{+ {"host-a", "host-b"},+ {"host-a", "pbs-a"},+ {"host-b", "pbs-a"},+ },+ },+ }++ for _, tc := range testCases {+ t.Run(tc.name, func(t *testing.T) {+ resolver := ResolveTopLevelSystems(tc.resources)+ if resolver.Count() != tc.wantCount {+ t.Fatalf("ResolveTopLevelSystems() count = %d, want %d", resolver.Count(), tc.wantCount)+ }+ assertTopLevelSystemGroupPairs(t, resolver, tc.same, tc.different)+ })+ }+}++func TestResolveTopLevelSystemsMixedEnvironmentCharacterization(t *testing.T) {+ resolver := ResolveTopLevelSystems([]Resource{+ topLevelTestAgent("agent-host", "tower.local", "machine-1", "agent-1"),+ topLevelTestDockerHost("docker-host", "tower.local", "docker-runtime-1", "agent-1"),+ topLevelTestProxmoxNode("proxmox-node", "tower", "proxmox-1", "https://tower.local:8006"),+ topLevelTestPBS("pbs-system", "tower.local", "pbs-1"),+ topLevelTestPMG("pmg-system", "mail.local", "pmg-1"),+ topLevelTestK8sCluster("cluster-1", "cluster-1", "agent-1", "https://tower.local:6443"),+ })++ if resolver.Count() != 3 {+ t.Fatalf("ResolveTopLevelSystems() count = %d, want 3", resolver.Count())+ }++ assertTopLevelSystemGroupPairs(t, resolver,+ [][2]string{+ {"agent-host", "docker-host"},+ {"agent-host", "proxmox-node"},+ {"agent-host", "pbs-system"},+ },+ [][2]string{+ {"agent-host", "pmg-system"},+ {"agent-host", "cluster-1"},+ {"pbs-system", "cluster-1"},+ {"pmg-system", "cluster-1"},+ },+ )+}++func TestHasMatchingMonitoredSystemDoesNotMergeKubernetesCandidateBySharedAgentID(t *testing.T) {+ registry := NewRegistry(nil)+ registry.IngestRecords(SourceAgent, []IngestRecord{+ {+ SourceID: "host-1",+ Resource: topLevelTestAgent("host-1", "tower.local", "machine-1", "agent-1"),+ },+ })++ if HasMatchingMonitoredSystem(registry, MonitoredSystemCandidate{+ Type: ResourceTypeK8sCluster,+ AgentID: "agent-1",+ Hostname: "tower.local",+ HostURL: "https://tower.local:6443",+ }) {+ t.Fatal("expected kubernetes candidate to remain separate from the underlying host")+ }+}++func assertTopLevelSystemGroupPairs(t *testing.T, resolver TopLevelSystemResolver, same, different [][2]string) {+ t.Helper()++ for _, pair := range same {+ left, right := resolver.resourceToGroup[pair[0]], resolver.resourceToGroup[pair[1]]+ if left == "" || right == "" {+ t.Fatalf("expected resolver group ids for %q and %q, got %q and %q", pair[0], pair[1], left, right)+ }+ if left != right {+ t.Fatalf("expected %q and %q to share a group, got %q and %q", pair[0], pair[1], left, right)+ }+ }++ for _, pair := range different {+ left, right := resolver.resourceToGroup[pair[0]], resolver.resourceToGroup[pair[1]]+ if left == "" || right == "" {+ t.Fatalf("expected resolver group ids for %q and %q, got %q and %q", pair[0], pair[1], left, right)+ }+ if left == right {+ t.Fatalf("expected %q and %q to remain separate, both resolved to %q", pair[0], pair[1], left)+ }+ }+}++func topLevelTestAgent(id, hostname, machineID, agentID string) Resource {+ resource := topLevelTestAgentWithoutMachineID(id, hostname, agentID)+ resource.Identity.MachineID = machineID+ resource.Agent.MachineID = machineID+ return resource+}++func topLevelTestAgentWithoutMachineID(id, hostname, agentID string) Resource {+ return Resource{+ ID: id,+ Type: ResourceTypeAgent,+ Name: hostname,+ Status: StatusOnline,+ Agent: &AgentData{+ AgentID: agentID,+ Hostname: hostname,+ },+ Identity: ResourceIdentity{+ Hostnames: []string{hostname},+ },+ }+}++func topLevelTestDockerHost(id, hostname, runtimeID, agentID string) Resource {+ return Resource{+ ID: id,+ Type: ResourceTypeAgent,+ Name: hostname,+ Status: StatusOnline,+ Docker: &DockerData{+ HostSourceID: runtimeID,+ AgentID: agentID,+ Hostname: hostname,+ },+ Identity: ResourceIdentity{+ Hostnames: []string{hostname},+ },+ }+}++func topLevelTestProxmoxNode(id, nodeName, sourceID, hostURL string) Resource {+ return Resource{+ ID: id,+ Type: ResourceTypeAgent,+ Name: nodeName,+ Status: StatusOnline,+ Proxmox: &ProxmoxData{+ SourceID: sourceID,+ NodeName: nodeName,+ HostURL: hostURL,+ },+ }+}++func topLevelTestTrueNAS(id, hostname string) Resource {+ return Resource{+ ID: id,+ Type: ResourceTypeAgent,+ Name: hostname,+ Status: StatusOnline,+ TrueNAS: &TrueNASData{+ Hostname: hostname,+ },+ Identity: ResourceIdentity{+ Hostnames: []string{hostname},+ },+ }+}++func topLevelTestPBS(id, hostname, instanceID string) Resource {+ return Resource{+ ID: id,+ Type: ResourceTypePBS,+ Name: hostname,+ Status: StatusOnline,+ PBS: &PBSData{+ InstanceID: instanceID,+ Hostname: hostname,+ HostURL: "https://" + hostname + ":8007",+ },+ }+}++func topLevelTestPMG(id, hostname, instanceID string) Resource {+ return Resource{+ ID: id,+ Type: ResourceTypePMG,+ Name: hostname,+ Status: StatusOnline,+ PMG: &PMGData{+ InstanceID: instanceID,+ Hostname: hostname,+ },+ }+}++func topLevelTestK8sCluster(id, clusterID, agentID, server string) Resource {+ return Resource{+ ID: id,+ Type: ResourceTypeK8sCluster,+ Name: clusterID,+ Status: StatusOnline,+ Kubernetes: &K8sData{+ ClusterID: clusterID,+ ClusterName: clusterID,+ AgentID: agentID,+ Server: server,+ },+ Identity: ResourceIdentity{+ Hostnames: []string{clusterID, extractHostname(server)},+ },+ }+}