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.

Preserve related resources in all timeline changes

rcourtmane1071d2ae073
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index f47800a766..c618ce92bf 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -143,6 +143,10 @@ That same shared facet bundle now also carries grouped `recentChangeKinds`
counts by canonical change kind, so the lifecycle-adjacent detail surfaces can
report restart, anomaly, relationship, and capability distribution without
rebuilding timeline math in the browser.
+Timeline entries surfaced through that same boundary also preserve
+`relatedResources` graph context for non-relationship changes, so adjacent
+fleet and install surfaces can link the affected neighbors without trying to
+reconstruct graph context from the raw resource payload alone.
That same shared `internal/api/` boundary now also assumes tenant AI services
stay on canonical Patrol runtime wiring: adjacent fleet and install surfaces
must not revive tenant snapshot-provider bridges through shared AI handler
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index dbd4fb36c8..d5bab325f9 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -131,10 +131,11 @@ The same facet bundle contract now also returns grouped `recentChangeKinds`
counts by canonical `ChangeKind`, so the shared drawer and summary chips can
show the distribution of restarts, anomalies, state transitions, and other
timeline classes without guessing from the loaded slice.
-Relationship-change timeline entries also preserve the affected graph endpoints
-in `relatedResources`, so the canonical history keeps enough context for the
-detail drawer and audit views to explain which neighboring resources moved with
-the change.
+Canonical timeline entries now also preserve graph context in
+`relatedResources`, so the history surface can explain which neighboring
+resources moved with restart, anomaly, config, state transition, and
+relationship changes instead of only exposing graph endpoints when the edge
+itself changed.
Restart timeline entries are also a first-class contract now: `restart` change
kinds can serialize Docker and Kubernetes restart metadata instead of being
folded into generic state transitions.
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 42134b28b8..e04cc6fc32 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -120,6 +120,10 @@ consume now also carries grouped `recentChangeKinds` counts by canonical change
kind, so storage and recovery surfaces can show the distribution of restarts,
anomalies, relationships, and capability changes without re-deriving their own
timeline breakdowns.
+Those same resource timeline records also preserve `relatedResources` graph
+context for non-relationship changes, so storage and recovery views can still
+link neighboring resources when the timeline entry is a restart, anomaly, or
+config update rather than only when the edge itself changes.
Those unified audit list endpoints also clamp oversized `limit` requests to
the governed maximum, so adjacent recovery and storage workflows do not turn
bounded history reads into unbounded collection scans.
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 79d26fbefd..356616fc7c 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -84,10 +84,11 @@ registry rebuilds and supplemental ingest into `ResourceChange` records, and
`internal/unifiedresources/store.go` persists those changes so `RecentChanges`
can round-trip through the SQLite-backed resource store instead of living only
in memory or adapter-local state.
-Relationship-change timeline records now keep the affected graph endpoints in
-`relatedResources`, so the durable history preserves the same graph context the
-detail drawer can surface later instead of collapsing relationship changes down
-to parent-only hints.
+Timeline records now keep graph context in `relatedResources` for every
+meaningful canonical change kind, so the durable history preserves the same
+cross-resource context the detail drawer can surface later instead of
+collapsing state, restart, anomaly, or config changes down to resource-only
+hints.
Those same relationship changes now summarize the actual edge(s) in `from` and
`to`, so the canonical timeline keeps the graph transition readable without
needing the drawer to reconstruct an edge summary from raw endpoints.
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 20fd35572c..9763d58e4f 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -3818,17 +3818,18 @@ func TestContract_ResourceTimelineRestartJSONSnapshot(t *testing.T) {
ResourceID: "container:7",
RecentChanges: []unifiedresources.ResourceChange{
{
- ID: "chg-restart-7",
- ObservedAt: now,
- OccurredAt: &now,
- ResourceID: "container:7",
- Kind: unifiedresources.ChangeRestart,
- From: "online|docker.restartCount=1|docker.uptimeSeconds=3600",
- To: "online|docker.restartCount=2|docker.uptimeSeconds=120",
- SourceType: unifiedresources.SourcePlatformEvent,
- SourceAdapter: unifiedresources.AdapterDocker,
- Confidence: unifiedresources.ConfidenceHigh,
- Reason: "resource restart detected",
+ ID: "chg-restart-7",
+ ObservedAt: now,
+ OccurredAt: &now,
+ ResourceID: "container:7",
+ Kind: unifiedresources.ChangeRestart,
+ From: "online|docker.restartCount=1|docker.uptimeSeconds=3600",
+ To: "online|docker.restartCount=2|docker.uptimeSeconds=120",
+ SourceType: unifiedresources.SourcePlatformEvent,
+ SourceAdapter: unifiedresources.AdapterDocker,
+ Confidence: unifiedresources.ConfidenceHigh,
+ RelatedResources: []string{"node:1", "service:api"},
+ Reason: "resource restart detected",
Metadata: map[string]any{
"changedFields": []string{"docker.restartCount", "docker.uptimeSeconds"},
},
@@ -3856,6 +3857,7 @@ func TestContract_ResourceTimelineRestartJSONSnapshot(t *testing.T) {
"sourceType":"platform_event",
"sourceAdapter":"docker_adapter",
"confidence":"high",
+ "relatedResources":["node:1","service:api"],
"reason":"resource restart detected",
"metadata":{"changedFields":["docker.restartCount","docker.uptimeSeconds"]}
}
@@ -3876,17 +3878,18 @@ func TestContract_ResourceTimelineAnomalyJSONSnapshot(t *testing.T) {
ResourceID: "storage:1",
RecentChanges: []unifiedresources.ResourceChange{
{
- ID: "chg-anomaly-1",
- ObservedAt: now,
- OccurredAt: &now,
- ResourceID: "storage:1",
- Kind: unifiedresources.ChangeAnomaly,
- From: "none",
- To: "capacity_runway_low[warning]:PBS datastore archive is READ_ONLY",
- SourceType: unifiedresources.SourcePulseDiff,
- SourceAdapter: unifiedresources.AdapterProxmox,
- Confidence: unifiedresources.ConfidenceHigh,
- Reason: "resource incident changed",
+ ID: "chg-anomaly-1",
+ ObservedAt: now,
+ OccurredAt: &now,
+ ResourceID: "storage:1",
+ Kind: unifiedresources.ChangeAnomaly,
+ From: "none",
+ To: "capacity_runway_low[warning]:PBS datastore archive is READ_ONLY",
+ SourceType: unifiedresources.SourcePulseDiff,
+ SourceAdapter: unifiedresources.AdapterProxmox,
+ Confidence: unifiedresources.ConfidenceHigh,
+ RelatedResources: []string{"node-2", "service:db"},
+ Reason: "resource incident changed",
Metadata: map[string]any{
"changedFields": []string{"incidents"},
},
@@ -3914,6 +3917,7 @@ func TestContract_ResourceTimelineAnomalyJSONSnapshot(t *testing.T) {
"sourceType":"pulse_diff",
"sourceAdapter":"proxmox_adapter",
"confidence":"high",
+ "relatedResources":["node-2","service:db"],
"reason":"resource incident changed",
"metadata":{"changedFields":["incidents"]}
}
@@ -3965,16 +3969,17 @@ func TestContract_ResourceFacetsJSONSnapshot(t *testing.T) {
},
RecentChanges: []unifiedresources.ResourceChange{
{
- ID: "chg-42",
- ResourceID: "vm:42",
- ObservedAt: now,
- OccurredAt: &now,
- Kind: unifiedresources.ChangeStateTransition,
- From: "offline",
- To: "online",
- SourceType: unifiedresources.SourcePlatformEvent,
- SourceAdapter: unifiedresources.AdapterProxmox,
- Confidence: unifiedresources.ConfidenceHigh,
+ ID: "chg-42",
+ ResourceID: "vm:42",
+ ObservedAt: now,
+ OccurredAt: &now,
+ Kind: unifiedresources.ChangeStateTransition,
+ From: "offline",
+ To: "online",
+ SourceType: unifiedresources.SourcePlatformEvent,
+ SourceAdapter: unifiedresources.AdapterProxmox,
+ Confidence: unifiedresources.ConfidenceHigh,
+ RelatedResources: []string{"node-1"},
Metadata: map[string]any{
"source": "snapshot",
"ticket": "INC-1234",
@@ -4034,6 +4039,7 @@ func TestContract_ResourceFacetsJSONSnapshot(t *testing.T) {
"sourceType":"platform_event",
"sourceAdapter":"proxmox_adapter",
"confidence":"high",
+ "relatedResources":["node-1"],
"metadata":{"source":"snapshot","ticket":"INC-1234"}
}
],
diff --git a/internal/api/resources_test.go b/internal/api/resources_test.go
index 3950366f91..ab93b15951 100644
--- a/internal/api/resources_test.go
+++ b/internal/api/resources_test.go
@@ -959,14 +959,15 @@ func TestResourceGetFacetsAndTimeline(t *testing.T) {
sourceAdapter = unified.AdapterDocker
}
if err := store.RecordChange(unified.ResourceChange{
- ID: fmt.Sprintf("chg-42-extra-%d", i+1),
- ResourceID: "vm:42",
- ObservedAt: now.Add(-offset),
- Kind: unified.ChangeAnomaly,
- SourceType: unified.SourcePulseDiff,
- SourceAdapter: sourceAdapter,
- Confidence: unified.ConfidenceMedium,
- Reason: "history backfill",
+ ID: fmt.Sprintf("chg-42-extra-%d", i+1),
+ ResourceID: "vm:42",
+ ObservedAt: now.Add(-offset),
+ Kind: unified.ChangeAnomaly,
+ SourceType: unified.SourcePulseDiff,
+ SourceAdapter: sourceAdapter,
+ Confidence: unified.ConfidenceMedium,
+ Reason: "history backfill",
+ RelatedResources: []string{"node-1"},
}); err != nil {
t.Fatalf("RecordChange extra %d: %v", i+1, err)
}
@@ -1078,6 +1079,9 @@ func TestResourceGetFacetsAndTimeline(t *testing.T) {
if got := payload.RecentChanges[0].Metadata["ticket"]; got != "INC-1234" {
t.Fatalf("unexpected timeline metadata: %#v", payload.RecentChanges[0].Metadata)
}
+ if got := payload.RecentChanges[0].RelatedResources; len(got) != 1 || got[0] != "node-1" {
+ t.Fatalf("unexpected timeline related resources: %#v", got)
+ }
})
t.Run("filtered timeline", func(t *testing.T) {
@@ -1124,6 +1128,9 @@ func TestResourceGetFacetsAndTimeline(t *testing.T) {
if payload.RecentChanges[0].ID != "chg-42-extra-2" {
t.Fatalf("unexpected adapter-filtered change: %#v", payload.RecentChanges[0])
}
+ if got := payload.RecentChanges[0].RelatedResources; len(got) != 1 || got[0] != "node-1" {
+ t.Fatalf("unexpected adapter-filtered related resources: %#v", got)
+ }
})
t.Run("filtered facets", func(t *testing.T) {
diff --git a/internal/unifiedresources/change_emission.go b/internal/unifiedresources/change_emission.go
index 2891794c79..b6c24847e7 100644
--- a/internal/unifiedresources/change_emission.go
+++ b/internal/unifiedresources/change_emission.go
@@ -85,6 +85,7 @@ func buildResourceChange(before Resource, beforeOK bool, after Resource, afterOK
if change.SourceAdapter == "" {
change.SourceAdapter = resourceChangeSourceAdapter(&after)
}
+ change.RelatedResources = relatedResourceIDs(change.ResourceID, before, after)
return change
}
@@ -97,6 +98,7 @@ func buildResourceChange(before Resource, beforeOK bool, after Resource, afterOK
if change.SourceAdapter == "" {
change.SourceAdapter = resourceChangeSourceAdapter(&before)
}
+ change.RelatedResources = relatedResourceIDs(change.ResourceID, before, after)
return change
}
@@ -128,7 +130,6 @@ func buildResourceChange(before Resource, beforeOK bool, after Resource, afterOK
change.From = resourceRelationSummary(before)
change.To = resourceRelationSummary(after)
change.Reason = "resource relationship changed"
- change.RelatedResources = relatedResourceIDs(change.ResourceID, before, after)
case !reflect.DeepEqual(before.Capabilities, after.Capabilities):
change.Kind = ChangeCapability
change.From = fmt.Sprintf("%d", len(before.Capabilities))
@@ -144,6 +145,7 @@ func buildResourceChange(before Resource, beforeOK bool, after Resource, afterOK
if change.SourceAdapter == "" {
change.SourceAdapter = resourceChangeSourceAdapter(&after)
}
+ change.RelatedResources = relatedResourceIDs(change.ResourceID, before, after)
return change
}
diff --git a/internal/unifiedresources/change_emission_test.go b/internal/unifiedresources/change_emission_test.go
index 894e3f5f24..39bb8e65d8 100644
--- a/internal/unifiedresources/change_emission_test.go
+++ b/internal/unifiedresources/change_emission_test.go
@@ -43,6 +43,56 @@ func TestBuildResourceChange_ClassifiesStateTransition(t *testing.T) {
}
}
+func TestBuildResourceChange_IncludesRelatedResourcesOnCreation(t *testing.T) {
+ parentID := "node:1"
+ after := Resource{
+ ID: "vm:1",
+ Type: ResourceTypeVM,
+ Name: "vm-1",
+ Status: StatusOnline,
+ ParentID: &parentID,
+ Relationships: []ResourceRelationship{
+ {SourceID: "vm:1", TargetID: "db:1", Type: RelDependsOn, Confidence: 1},
+ },
+ }
+
+ change := buildResourceChange(Resource{}, false, after, true, time.Now().UTC(), nil, SourcePlatformEvent, "")
+ if change == nil {
+ t.Fatal("expected creation change, got nil")
+ }
+ if change.Kind != ChangeStateTransition {
+ t.Fatalf("Kind = %q, want %q", change.Kind, ChangeStateTransition)
+ }
+ if !sameStringSet(change.RelatedResources, []string{"node:1", "db:1"}) {
+ t.Fatalf("RelatedResources = %+v, want node:1 and db:1", change.RelatedResources)
+ }
+}
+
+func TestBuildResourceChange_IncludesRelatedResourcesOnRemoval(t *testing.T) {
+ parentID := "node:1"
+ before := Resource{
+ ID: "vm:1",
+ Type: ResourceTypeVM,
+ Name: "vm-1",
+ Status: StatusOnline,
+ ParentID: &parentID,
+ Relationships: []ResourceRelationship{
+ {SourceID: "vm:1", TargetID: "db:1", Type: RelDependsOn, Confidence: 1},
+ },
+ }
+
+ change := buildResourceChange(before, true, Resource{}, false, time.Now().UTC(), nil, SourcePlatformEvent, "")
+ if change == nil {
+ t.Fatal("expected removal change, got nil")
+ }
+ if change.Kind != ChangeStateTransition {
+ t.Fatalf("Kind = %q, want %q", change.Kind, ChangeStateTransition)
+ }
+ if !sameStringSet(change.RelatedResources, []string{"node:1", "db:1"}) {
+ t.Fatalf("RelatedResources = %+v, want node:1 and db:1", change.RelatedResources)
+ }
+}
+
func TestBuildResourceChange_ClassifiesRelationshipChangeAndIncludesEndpoints(t *testing.T) {
before := Resource{
ID: "vm:1",
@@ -224,11 +274,17 @@ func TestBuildResourceChange_ClassifiesIncidentAnomalyChange(t *testing.T) {
}
func TestBuildResourceChange_ClassifiesConfigUpdate(t *testing.T) {
+ parentID := "node:1"
before := Resource{
- ID: "vm:1",
- Type: ResourceTypeVM,
- Name: "vm-1",
- Status: StatusOnline,
+ ID: "vm:1",
+ Type: ResourceTypeVM,
+ Name: "vm-1",
+ Status: StatusOnline,
+ ParentID: &parentID,
+ Relationships: []ResourceRelationship{
+ {SourceID: "vm:1", TargetID: "db:1", Type: RelDependsOn, Confidence: 1},
+ {SourceID: "vm:1", TargetID: "service:1", Type: RelDependsOn, Confidence: 1},
+ },
}
after := before
after.Name = "vm-1-renamed"
@@ -247,6 +303,14 @@ func TestBuildResourceChange_ClassifiesConfigUpdate(t *testing.T) {
if !sameStringSet(mustChangedFields(t, change), []string{"name", "customUrl"}) {
t.Fatalf("changedFields = %+v, want name and customUrl", mustChangedFields(t, change))
}
+ if !sameStringSet(change.RelatedResources, []string{"node:1", "db:1", "service:1"}) {
+ t.Fatalf("RelatedResources = %+v, want node:1, db:1, and service:1", change.RelatedResources)
+ }
+ for _, id := range change.RelatedResources {
+ if id == change.ResourceID {
+ t.Fatalf("RelatedResources unexpectedly included primary resource ID %q", id)
+ }
+ }
}
func mustChangedFields(t *testing.T, change *ResourceChange) []string {
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index fce49ccd69..0347e9488f 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -289,7 +289,7 @@ func TestResourceChangeEmissionCoversRelationshipAndCapabilityChanges(t *testing
}
source := string(data)
requiredSnippets := []string{
- "relatedResourceIDs(change.ResourceID, before, after)",
+ "change.RelatedResources = relatedResourceIDs(change.ResourceID, before, after)",
"case resourceRestartChanged(before, after):",
"case resourceIncidentChanged(before, after):",
"if !reflect.DeepEqual(before.Relationships, after.Relationships) {",