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
Scope app-container registry keys to their docker host
rcourtman3d500b5af2e6
diff --git a/internal/unifiedresources/metrics_targets.go b/internal/unifiedresources/metrics_targets.goindex c0fb9df36b..1895d8fd01 100644--- a/internal/unifiedresources/metrics_targets.go+++ b/internal/unifiedresources/metrics_targets.go@@ -50,7 +50,19 @@ func BuildMetricsTarget(resource Resource, sourceTargets []SourceTarget) *Metric}case ResourceTypeAppContainer:if st, ok := bySource[SourceDocker]; ok {- return &MetricsTarget{ResourceType: "app-container", ResourceID: st.SourceID}+ // The bySource source key for docker containers is now+ // host-scoped (see dockerContainerSourceID), but metrics+ // writes still key by the raw container ID. Prefer the+ // container ID surfaced on the canonical resource so the+ // metrics target the API hands out resolves the same+ // records the metrics store writes.+ targetID := st.SourceID+ if resource.Docker != nil {+ if ctID := strings.TrimSpace(resource.Docker.ContainerID); ctID != "" {+ targetID = ctID+ }+ }+ return &MetricsTarget{ResourceType: "app-container", ResourceID: targetID}}if st, ok := bySource[SourceTrueNAS]; ok {if resourceID := canonicalAppContainerMetricID(st.SourceID); resourceID != "" {diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.goindex 6996ae5291..586fe79b71 100644--- a/internal/unifiedresources/registry.go+++ b/internal/unifiedresources/registry.go@@ -425,7 +425,22 @@ func (rr *ResourceRegistry) seedSourceIDForResourceLocked(resource *Resource, socase ResourceTypeAgent:return strings.TrimSpace(resource.Docker.HostSourceID)case ResourceTypeAppContainer:- return strings.TrimSpace(resource.Docker.ContainerID)+ // Match the host-scoped key shape produced by+ // ingestDockerContainer so records-path ingests resolve to+ // the same registry entries as inventory-path ingests.+ hostSourceID := strings.TrimSpace(resource.Docker.HostSourceID)+ containerID := strings.TrimSpace(resource.Docker.ContainerID)+ if hostSourceID == "" {+ return containerID+ }+ if containerID == "" {+ name := strings.TrimSpace(resource.Name)+ if name == "" {+ return ""+ }+ containerID = "name:" + name+ }+ return hostSourceID + "/container/" + containerIDcase ResourceTypeDockerService:clusterKey := dockerSwarmClusterKeyFromMeta(resource.Docker.Swarm)if clusterKey == "" {@@ -1008,7 +1023,35 @@ func (rr *ResourceRegistry) ingestDockerContainer(ct models.DockerContainer, hosif parentID, ok := rr.bySource[SourceDocker][host.ID]; ok {resource.ParentID = &parentID}- rr.ingest(SourceDocker, ct.ID, resource, identity)+ // Scope the source key to the docker host so that two containers+ // reported by different docker hosts can never collapse into a+ // single registry entry. Without host scoping, anything that+ // produces a colliding container source ID (a docker ps that+ // briefly returns an empty ID and falls back to the container+ // name in parseDockerInventoryContainerLine, a future short-ID+ // truncation, or a daemon-side identifier reset across recreate+ // cycles) would route both containers to the same resource ID,+ // and mergeInto would overwrite the Docker payload — including+ // HostSourceID and ParentID — with whichever ingest ran second.+ // That race surfaced as the "frigate@141" host re-attribution+ // flicker on the Docker page.+ rr.ingest(SourceDocker, dockerContainerSourceID(host, ct), resource, identity)+}++// dockerContainerSourceID produces a stable per-(host, container) key for+// the bySource[SourceDocker] mapping. The hashed resource ID derives from+// this same string via sourceSpecificID, so it must remain stable across+// projection rebuilds for a given container under a given docker host.+func dockerContainerSourceID(host models.DockerHost, ct models.DockerContainer) string {+ hostID := strings.TrimSpace(host.ID)+ ctID := strings.TrimSpace(ct.ID)+ if hostID == "" {+ return ctID+ }+ if ctID == "" {+ ctID = "name:" + strings.TrimSpace(ct.Name)+ }+ return hostID + "/container/" + ctID}func (rr *ResourceRegistry) ingestDockerService(service models.DockerService, host models.DockerHost) {diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.goindex 78ef4b1d4f..504a5ff364 100644--- a/internal/unifiedresources/registry_test.go+++ b/internal/unifiedresources/registry_test.go@@ -3607,3 +3607,69 @@ func TestResourceRegistry_WorkloadsIncludeCanonicalAppContainers(t *testing.T) {t.Fatalf("expected app-container workload for Nextcloud, got %q", got)}}++// TestRegistryIngestKeepsDockerContainersScopedToTheirHost pins the fix for the+// "frigate@141" host re-attribution flicker on the Docker page. The bug was+// that app-container source keys did not include the docker host, so any+// scenario producing a colliding container source ID (a docker ps that+// briefly returns an empty ID and parseDockerInventoryContainerLine falls+// back to the container name, a future short-ID truncation, daemon-side+// identifier reset across recreate cycles, ...) routed two containers+// reported by different hosts to the same registry resource. mergeInto+// then overwrote one host's Docker payload with the other's, flipping+// HostSourceID and ParentID on every projection rebuild until the colliding+// inputs diverged again.+func TestRegistryIngestKeepsDockerContainersScopedToTheirHost(t *testing.T) {+ rr := NewRegistry(nil)+ // Two distinct docker hosts each reporting a container whose docker+ // source ID happens to collide (here: both fell back to the "frigate"+ // name because their docker ps lines were missing an ID).+ rr.IngestSnapshot(models.StateSnapshot{+ DockerHosts: []models.DockerHost{+ {+ ID: "proxmox-lxc-docker:pve-a:node-a:105",+ Hostname: "frigate.lab",+ Status: "online",+ Containers: []models.DockerContainer{{+ ID: "frigate",+ Name: "frigate",+ State: "running",+ }},+ },+ {+ ID: "proxmox-lxc-docker:pve-a:node-a:141",+ Hostname: "homepage-docker.lab",+ Status: "online",+ Containers: []models.DockerContainer{{+ ID: "frigate",+ Name: "frigate",+ State: "running",+ }},+ },+ },+ })++ resources := rr.ListByType(ResourceTypeAppContainer)+ if len(resources) != 2 {+ t.Fatalf("expected two distinct docker container resources (one per host); got %d", len(resources))+ }++ hostsSeen := make(map[string]struct{}, len(resources))+ for _, resource := range resources {+ if resource.Docker == nil {+ t.Fatalf("docker container resource missing Docker payload: %#v", resource)+ }+ if resource.Name != "frigate" {+ t.Fatalf("unexpected container name: %q", resource.Name)+ }+ hostsSeen[strings.TrimSpace(resource.Docker.HostSourceID)] = struct{}{}+ }+ for _, want := range []string{+ "proxmox-lxc-docker:pve-a:node-a:105",+ "proxmox-lxc-docker:pve-a:node-a:141",+ } {+ if _, ok := hostsSeen[want]; !ok {+ t.Fatalf("expected a container attributed to host %q; got hosts %v", want, hostsSeen)+ }+ }+}