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.

Centralize relationship change summaries

rcourtman5c0330d7f44e
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 269314239d..0d113f4680 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -161,6 +161,10 @@ The AI correlation root-cause engine also consumes the canonical unified-
resource relationship model directly, so cross-resource reasoning stays aligned
with the same graph edges that back the resource API instead of maintaining a
parallel relationship vocabulary inside AI correlation.
+The canonical relationship-summary helper also feeds resource change records,
+so AI timeline prompts read the same relationship wording and edge labels that
+the unified-resource contract emits instead of building another summary shape
+in AI-local code.
The Patrol-backed correlation endpoint, resource-intelligence payload, and
seed prompt correlations now flow through the shared AI intelligence facade
first, so the detector remains an implementation detail behind one canonical
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 9fa7e601b5..aac2e49999 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -213,6 +213,10 @@ pages.
Those relationship and timeline payloads now also carry `lastSeenAt` freshness
and optional metadata through the same owned contract, so the drawer can
preserve provenance without inventing a separate graph-detail schema.
+Relationship-change timeline entries now also use the canonical relationship
+summary helper for their compact `from` and `to` wording, so the API keeps the
+human-readable edge label aligned with the unified-resource relationship
+presenter instead of reconstructing a local type-token summary.
The same `/api/resources/{id}/timeline` filter contract now also routes its
kinds, source types, and source adapters through the shared unified-resource
change-filter parser, so API validation stays owned by the change model rather
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index e1871dfbde..b9c3ba6ebf 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -121,6 +121,10 @@ That same resource model now also owns the canonical
`FormatResourceGraphContext` helper, so service-layer callers only resolve the
resource and hand the model the relationship list instead of rebuilding the
graph section header, ordering, or freshness wording locally.
+The same shared relationship presenter also owns the compact change-timeline
+relationship summary used by resource change records, so change `from` and
+`to` values stay aligned with the canonical relationship labels instead of
+reconstructing a separate type-token summary in the emitter.
The same AI resource-intelligence payload now also carries canonical
correlation evidence from the shared detector, so the drawer can show learned
edge patterns alongside the dependency graph without rebuilding correlation
diff --git a/internal/unifiedresources/change_emission.go b/internal/unifiedresources/change_emission.go
index b6c24847e7..08f4371e76 100644
--- a/internal/unifiedresources/change_emission.go
+++ b/internal/unifiedresources/change_emission.go
@@ -388,48 +388,6 @@ func resourceRelationSummary(resource Resource) string {
return parentID
}
-func resourceRelationshipSummary(relationships []ResourceRelationship) string {
- if len(relationships) == 0 {
- return ""
- }
-
- summaries := make([]string, 0, len(relationships))
- for _, relationship := range relationships {
- sourceID := CanonicalResourceID(relationship.SourceID)
- targetID := CanonicalResourceID(relationship.TargetID)
- if sourceID == "" && targetID == "" {
- continue
- }
-
- label := sourceID
- if label == "" {
- label = "?"
- }
- label += "->"
- if targetID == "" {
- label += "?"
- } else {
- label += targetID
- }
- if relationship.Type != "" {
- label += fmt.Sprintf("[%s]", relationship.Type)
- }
- summaries = append(summaries, label)
- }
-
- if len(summaries) == 0 {
- return ""
- }
- sort.Strings(summaries)
- if len(summaries) == 1 {
- return summaries[0]
- }
- if len(summaries) <= 3 {
- return strings.Join(summaries, ", ")
- }
- return fmt.Sprintf("%d relationships", len(summaries))
-}
-
func resourceConfigSummary(resource Resource) string {
return fmt.Sprintf("%s|%s|%s|%s", resource.Type, resource.Technology, resource.Name, resource.CustomURL)
}
diff --git a/internal/unifiedresources/change_emission_test.go b/internal/unifiedresources/change_emission_test.go
index 39bb8e65d8..83005f728b 100644
--- a/internal/unifiedresources/change_emission_test.go
+++ b/internal/unifiedresources/change_emission_test.go
@@ -115,8 +115,8 @@ func TestBuildResourceChange_ClassifiesRelationshipChangeAndIncludesEndpoints(t
if change.Kind != ChangeRelationship {
t.Fatalf("Kind = %q, want %q", change.Kind, ChangeRelationship)
}
- if change.From != "vm:1->db:1[depends_on]" || change.To != "vm:1->db:2[depends_on]" {
- t.Fatalf("From/To = %q/%q, want vm:1->db:1[depends_on]/vm:1->db:2[depends_on]", change.From, change.To)
+ if change.From != "vm:1->db:1[Depends on]" || change.To != "vm:1->db:2[Depends on]" {
+ t.Fatalf("From/To = %q/%q, want vm:1->db:1[Depends on]/vm:1->db:2[Depends on]", change.From, change.To)
}
if !sameStringSet(change.RelatedResources, []string{"db:1", "db:2"}) {
t.Fatalf("RelatedResources = %+v, want db:1 and db:2", change.RelatedResources)
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index 075e4532e8..7738b19f04 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -537,7 +537,6 @@ func TestResourceChangeEmissionCoversRelationshipAndCapabilityChanges(t *testing
"changed = append(changed, \"kubernetes.restarts\", \"kubernetes.uptimeSeconds\")",
"if !reflect.DeepEqual(before.Capabilities, after.Capabilities) {",
"changed = append(changed, \"capabilities\")",
- "resourceRelationshipSummary(relationships []ResourceRelationship)",
"resourceRestartSummary(resource Resource) string",
"resourceIncidentSummary(resource Resource) string",
}
@@ -590,6 +589,23 @@ func TestResourceGraphContextUsesCanonicalRelationshipPresentation(t *testing.T)
}
}
+func TestResourceRelationshipSummaryUsesCanonicalRelationshipPresentation(t *testing.T) {
+ data, err := os.ReadFile(filepath.Join("relationship_presentation.go"))
+ if err != nil {
+ t.Fatalf("failed to read relationship_presentation.go: %v", err)
+ }
+ source := string(data)
+ requiredSnippets := []string{
+ "func resourceRelationshipSummary(relationships []ResourceRelationship) string",
+ "label += fmt.Sprintf(\"[%s]\", RelationshipTypeLabel(relationship.Type))",
+ }
+ for _, snippet := range requiredSnippets {
+ if !strings.Contains(source, snippet) {
+ t.Fatalf("internal/unifiedresources/relationship_presentation.go must pin canonical relationship summary snippet %q", snippet)
+ }
+ }
+}
+
func TestPatrolSeedCorrelationContextUsesCanonicalSummaryFormatter(t *testing.T) {
data, err := os.ReadFile(filepath.Join("..", "ai", "patrol_ai.go"))
if err != nil {
diff --git a/internal/unifiedresources/relationship_presentation.go b/internal/unifiedresources/relationship_presentation.go
index 20e267330c..9e6873d2ce 100644
--- a/internal/unifiedresources/relationship_presentation.go
+++ b/internal/unifiedresources/relationship_presentation.go
@@ -2,6 +2,7 @@ package unifiedresources
import (
"fmt"
+ "sort"
"strings"
"time"
@@ -68,6 +69,50 @@ func DescribeRelationship(rel ResourceRelationship) RelationshipPresentation {
return presentation
}
+// resourceRelationshipSummary returns the canonical compact label for a set
+// of relationships used by resource change timelines and related context.
+func resourceRelationshipSummary(relationships []ResourceRelationship) string {
+ if len(relationships) == 0 {
+ return ""
+ }
+
+ summaries := make([]string, 0, len(relationships))
+ for _, relationship := range relationships {
+ sourceID := CanonicalResourceID(relationship.SourceID)
+ targetID := CanonicalResourceID(relationship.TargetID)
+ if sourceID == "" && targetID == "" {
+ continue
+ }
+
+ label := sourceID
+ if label == "" {
+ label = "?"
+ }
+ label += "->"
+ if targetID == "" {
+ label += "?"
+ } else {
+ label += targetID
+ }
+ if relationship.Type != "" {
+ label += fmt.Sprintf("[%s]", RelationshipTypeLabel(relationship.Type))
+ }
+ summaries = append(summaries, label)
+ }
+
+ if len(summaries) == 0 {
+ return ""
+ }
+ sort.Strings(summaries)
+ if len(summaries) == 1 {
+ return summaries[0]
+ }
+ if len(summaries) <= 3 {
+ return strings.Join(summaries, ", ")
+ }
+ return fmt.Sprintf("%d relationships", len(summaries))
+}
+
// FormatResourceGraphContext returns the canonical AI prompt section for a
// resource's learned relationships.
func FormatResourceGraphContext(resource *Resource, limit int) string {
diff --git a/internal/unifiedresources/relationship_presentation_test.go b/internal/unifiedresources/relationship_presentation_test.go
index 2dbbcdc463..2397e21c20 100644
--- a/internal/unifiedresources/relationship_presentation_test.go
+++ b/internal/unifiedresources/relationship_presentation_test.go
@@ -51,6 +51,25 @@ func TestDescribeRelationship(t *testing.T) {
}
}
+func TestResourceRelationshipSummary(t *testing.T) {
+ summary := resourceRelationshipSummary([]ResourceRelationship{
+ {
+ SourceID: "node-1",
+ TargetID: "vm-1",
+ Type: RelRunsOn,
+ },
+ {
+ SourceID: "node-1",
+ TargetID: "storage-1",
+ Type: RelDependsOn,
+ },
+ })
+
+ if want := "node-1->storage-1[Depends on], node-1->vm-1[Runs on]"; summary != want {
+ t.Fatalf("resourceRelationshipSummary() = %q, want %q", summary, want)
+ }
+}
+
func TestFormatResourceGraphContext(t *testing.T) {
resource := &Resource{
Relationships: []ResourceRelationship{