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.

Attach mock availability checks to services

rcourtman9dc43863187f
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 2d7908a2b5..389ccfe231 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -1466,16 +1466,18 @@ records with the saved target id, probe address, protocol, cadence, last check,
failure count, and threshold in `AvailabilityData`. Registry merge policy must
preserve that payload and incident state. An availability record attaches as a
facet onto a known resource when (a) the target carries an explicit
-`LinkedResourceID` referencing a resource already in the registry, or (b) the
+`LinkedResourceID` that resolves to a resource already in the registry by exact
+resource id, unique source id, or unique canonical identity alias, or (b) the
probe address unambiguously matches exactly one known resource by IP through
`FindCandidates` with reason `ip` or `hostname+ip` (confidence at or above the
merge threshold). Fuzzy hostname-only correlation (reason `hostname`, confidence
-below threshold) must not attach. When attached, the known resource inherits
-the `AvailabilityData` facet and `SourceAvailability` in its source list, and
-no standalone `network-endpoint` is minted. When no link resolves, the record
-falls back to a standalone `network-endpoint` as before. A second probe must
-not overwrite a facet already attached by a different target; the second probe
-stays standalone in that case.
+below threshold), ambiguous source/canonical references, and references to
+availability-owned resources must not attach. When attached, the known resource
+inherits the `AvailabilityData` facet and `SourceAvailability` in its source
+list, and no standalone `network-endpoint` is minted. When no link resolves, the
+record falls back to a standalone `network-endpoint` as before. A second probe
+must not overwrite a facet already attached by a different target; the second
+probe stays standalone in that case.
Frontend resource adapters must preserve that same availability identity on
both REST and realtime paths: a thin `network-endpoint` update with
availability data is still `platformType=availability`, `sourceType=api`, and
@@ -1788,7 +1790,11 @@ Agentless availability fixtures join that same graph-owned seed contract:
mock UPS, MQTT, ESPHome, HTTP, and controller endpoints must project as
`SourceAvailability` `network-endpoint` resources with real availability
payloads, incidents, and source status rather than as generic host rows or
-settings-only sample data.
+settings-only sample data. Mock service availability fixtures must use
+`LinkedResourceID` source references when the target service row is produced by
+the same graph, so service ping evidence lands as an `AvailabilityData` facet on
+the Docker or Kubernetes service instead of creating a disconnected duplicate
+endpoint.
Callers should therefore consume `CurrentFixtureGraph()` and graph-owned
projections rather than reintroducing platform-only or state-only mock helper
exports.
diff --git a/internal/mock/availability_fixtures.go b/internal/mock/availability_fixtures.go
index 1ad1a42a31..b13e27be27 100644
--- a/internal/mock/availability_fixtures.go
+++ b/internal/mock/availability_fixtures.go
@@ -32,6 +32,7 @@ type AvailabilityTargetFixture struct {
ID string
Name string
TargetKind string
+ LinkedResourceID string
Address string
Protocol string
Port int
@@ -68,6 +69,7 @@ func normalizeAvailabilityTargetFixture(target AvailabilityTargetFixture) Availa
if target.TargetKind == "" {
target.TargetKind = mockAvailabilityTargetService
}
+ target.LinkedResourceID = strings.TrimSpace(target.LinkedResourceID)
target.Protocol = strings.ToLower(strings.TrimSpace(target.Protocol))
if target.Protocol == "" {
target.Protocol = mockAvailabilityProbeICMP
@@ -141,6 +143,44 @@ func normalizeAvailabilityFixtureAddress(raw string) string {
func defaultAvailabilityFixtures(now time.Time) []AvailabilityFixture {
base := normalizeAvailabilityFixtureTime(now)
return []AvailabilityFixture{
+ {
+ Target: normalizeAvailabilityTargetFixture(AvailabilityTargetFixture{
+ ID: "mock-availability-docker-frontend-service",
+ Name: "Frontend Swarm service",
+ TargetKind: mockAvailabilityTargetService,
+ LinkedResourceID: "mock-swarm-cluster-1:service:svc-frontend-0",
+ Address: "https://frontend.demo.pulse.local",
+ Protocol: mockAvailabilityProbeHTTP,
+ Path: "/health",
+ Enabled: true,
+ PollIntervalSecs: 30,
+ TimeoutMillis: 1500,
+ FailureThreshold: 2,
+ }),
+ Available: true,
+ LastChecked: base.Add(-9 * time.Second),
+ LastSuccess: base.Add(-9 * time.Second),
+ LatencyMillis: 9,
+ },
+ {
+ Target: normalizeAvailabilityTargetFixture(AvailabilityTargetFixture{
+ ID: "mock-availability-k8s-checkout-api",
+ Name: "Checkout API service",
+ TargetKind: mockAvailabilityTargetService,
+ LinkedResourceID: "k8s-production-1:service:k8s-production-1-svc-checkout-api",
+ Address: "checkout-api.services.svc.cluster.local",
+ Protocol: mockAvailabilityProbeTCP,
+ Port: 8080,
+ Enabled: true,
+ PollIntervalSecs: 30,
+ TimeoutMillis: 1500,
+ FailureThreshold: 2,
+ }),
+ Available: true,
+ LastChecked: base.Add(-6 * time.Second),
+ LastSuccess: base.Add(-6 * time.Second),
+ LatencyMillis: 5,
+ },
{
Target: normalizeAvailabilityTargetFixture(AvailabilityTargetFixture{
ID: "mock-availability-ups",
@@ -288,6 +328,7 @@ func availabilityFixtureRecord(fixture AvailabilityFixture, now time.Time) (unif
}
data := &unifiedresources.AvailabilityData{
TargetID: target.ID,
+ LinkedResourceID: target.LinkedResourceID,
Name: target.displayName(),
TargetKind: target.TargetKind,
Address: target.Address,
diff --git a/internal/mock/platform_fixtures_test.go b/internal/mock/platform_fixtures_test.go
index b9783e7101..f83700a922 100644
--- a/internal/mock/platform_fixtures_test.go
+++ b/internal/mock/platform_fixtures_test.go
@@ -226,6 +226,71 @@ func TestFixtureGraphProjectsAvailabilityFixturesAsNetworkEndpoints(t *testing.T
}
}
+func TestFixtureGraphAttachesServiceAvailabilityFixturesToServiceResources(t *testing.T) {
+ now := time.Date(2026, time.May, 6, 12, 0, 0, 0, time.UTC)
+
+ graph := buildFixtureGraph(DefaultConfig, now)
+ resources, _ := graph.UnifiedResourceSnapshot()
+
+ var dockerService *unifiedresources.Resource
+ var kubernetesService *unifiedresources.Resource
+ for i := range resources {
+ availability := resources[i].Availability
+ if availability == nil {
+ continue
+ }
+ switch availability.TargetID {
+ case "mock-availability-docker-frontend-service":
+ dockerService = &resources[i]
+ case "mock-availability-k8s-checkout-api":
+ kubernetesService = &resources[i]
+ }
+ if resources[i].Type == unifiedresources.ResourceTypeNetworkEndpoint &&
+ (availability.TargetID == "mock-availability-docker-frontend-service" ||
+ availability.TargetID == "mock-availability-k8s-checkout-api") {
+ t.Fatalf("service availability target %q stayed as standalone network endpoint", availability.TargetID)
+ }
+ }
+
+ if dockerService == nil {
+ t.Fatal("expected Docker service availability facet on curated mock service")
+ }
+ if dockerService.Type != unifiedresources.ResourceTypeDockerService {
+ t.Fatalf("Docker service availability attached to %q, want docker-service", dockerService.Type)
+ }
+ if dockerService.Docker == nil || dockerService.Docker.ServiceID != "svc-frontend-0" {
+ t.Fatalf("Docker service metadata = %+v, want service id svc-frontend-0", dockerService.Docker)
+ }
+ if dockerService.Availability.TargetKind != "service" ||
+ dockerService.Availability.Protocol != "http" ||
+ dockerService.Availability.Path != "/health" ||
+ dockerService.Availability.LatencyMillis != 9 {
+ t.Fatalf("unexpected Docker service availability facet: %+v", dockerService.Availability)
+ }
+ if !slices.Contains(dockerService.Sources, unifiedresources.SourceAvailability) {
+ t.Fatalf("expected Docker service sources to include availability, got %+v", dockerService.Sources)
+ }
+
+ if kubernetesService == nil {
+ t.Fatal("expected Kubernetes service availability facet on curated mock service")
+ }
+ if kubernetesService.Type != unifiedresources.ResourceTypeK8sService {
+ t.Fatalf("Kubernetes service availability attached to %q, want k8s-service", kubernetesService.Type)
+ }
+ if kubernetesService.Name != "checkout-api" {
+ t.Fatalf("Kubernetes service name = %q, want checkout-api", kubernetesService.Name)
+ }
+ if kubernetesService.Availability.TargetKind != "service" ||
+ kubernetesService.Availability.Protocol != "tcp" ||
+ kubernetesService.Availability.Port != 8080 ||
+ kubernetesService.Availability.LatencyMillis != 5 {
+ t.Fatalf("unexpected Kubernetes service availability facet: %+v", kubernetesService.Availability)
+ }
+ if !slices.Contains(kubernetesService.Sources, unifiedresources.SourceAvailability) {
+ t.Fatalf("expected Kubernetes service sources to include availability, got %+v", kubernetesService.Sources)
+ }
+}
+
func TestBuildFixtureGraphRebasesPlatformFixtureTimestampsForDemoRuntime(t *testing.T) {
now := time.Date(2026, time.March, 31, 17, 30, 0, 0, time.UTC)
diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.go
index 3a725f5d75..2d91d3cc77 100644
--- a/internal/unifiedresources/registry.go
+++ b/internal/unifiedresources/registry.go
@@ -2418,9 +2418,8 @@ func (rr *ResourceRegistry) resolveAvailabilityLink(resource Resource) string {
}
if linkedID := strings.TrimSpace(resource.Availability.LinkedResourceID); linkedID != "" {
- existing := rr.resources[linkedID]
- if existing != nil && !isAvailabilityOwnedResource(*existing) && availabilityFacetCompatible(existing, resource) {
- return linkedID
+ if resolved := rr.resolveAvailabilityLinkedResource(linkedID, resource); resolved != "" {
+ return resolved
}
}
@@ -2444,6 +2443,33 @@ func (rr *ResourceRegistry) resolveAvailabilityLink(resource Resource) string {
return matchID
}
+func (rr *ResourceRegistry) resolveAvailabilityLinkedResource(ref string, incoming Resource) string {
+ ref = strings.TrimSpace(ref)
+ if ref == "" {
+ return ""
+ }
+
+ exactID := CanonicalResourceID(ref)
+ if existing := rr.resources[exactID]; existing != nil {
+ if !isAvailabilityOwnedResource(*existing) && availabilityFacetCompatible(existing, incoming) {
+ return exactID
+ }
+ return ""
+ }
+
+ for _, candidateID := range uniqueTrimmed(
+ rr.uniqueSourceResourceIDLocked(ref),
+ rr.uniqueCanonicalIdentityResourceIDLocked(ref),
+ ) {
+ existing := rr.resources[candidateID]
+ if existing != nil && !isAvailabilityOwnedResource(*existing) && availabilityFacetCompatible(existing, incoming) {
+ return candidateID
+ }
+ }
+
+ return ""
+}
+
// isAvailabilityOwnedResource reports whether a resource is itself an
// agentless availability endpoint (a standalone network-endpoint, or any
// resource sourced only from availability), which probes must never fold into.
diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.go
index 26ba944904..098f7319d6 100644
--- a/internal/unifiedresources/registry_test.go
+++ b/internal/unifiedresources/registry_test.go
@@ -103,6 +103,52 @@ func TestResourceRegistry_GetByReferenceResolvesSourceIDAndCanonicalAlias(t *tes
}
}
+func TestResourceRegistryAvailabilityLinkedResourceResolvesSourceReference(t *testing.T) {
+ rr := NewRegistry(nil)
+ now := time.Now().UTC()
+ const serviceSourceID = "swarm-1:service:svc-api"
+ rr.IngestRecords(SourceDocker, []IngestRecord{{
+ SourceID: serviceSourceID,
+ Resource: Resource{
+ Type: ResourceTypeDockerService,
+ Name: "api",
+ Status: StatusOnline,
+ LastSeen: now,
+ },
+ Identity: ResourceIdentity{Hostnames: []string{"api"}},
+ }})
+
+ rr.IngestRecords(SourceAvailability, []IngestRecord{
+ availabilityProbeRecord("probe-service", "api.example.test", &AvailabilityData{
+ LinkedResourceID: serviceSourceID,
+ Address: "api.example.test",
+ Protocol: "tcp",
+ Port: 8443,
+ TargetKind: "service",
+ Enabled: true,
+ Available: true,
+ }),
+ })
+
+ if got := rr.ListByType(ResourceTypeNetworkEndpoint); len(got) != 0 {
+ t.Fatalf("expected source-referenced probe to attach (0 endpoints), got %d", len(got))
+ }
+ services := rr.ListByType(ResourceTypeDockerService)
+ if len(services) != 1 {
+ t.Fatalf("expected 1 docker service, got %d", len(services))
+ }
+ service := services[0]
+ if service.Availability == nil || service.Availability.TargetID != "probe-service" {
+ t.Fatalf("expected availability facet probe-service on docker service, got %+v", service.Availability)
+ }
+ if service.Availability.LinkedResourceID != serviceSourceID {
+ t.Fatalf("linkedResourceId = %q, want %q", service.Availability.LinkedResourceID, serviceSourceID)
+ }
+ if !hasDataSource(service.Sources, SourceAvailability) {
+ t.Fatalf("expected docker service sources to include availability, got %v", service.Sources)
+ }
+}
+
func TestResourceRegistry_ListByType(t *testing.T) {
rr := NewRegistry(nil)