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 resource cluster/IP presentation helpers

rcourtman65c39cb8a470
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 3f2fa7eed0..ccf4de93f1 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -207,7 +207,10 @@ and unified adapter presentation.
The unified resource context's IP summaries now also route through the shared
policy redaction helper, so the local "IPs" line follows the same governed
redaction decision and label vocabulary as the rest of the policy-aware
-resource presentation layer.
+resource presentation layer. Cluster labels for AI resource context now also
+come from the shared unified-resource presentation helper, so the same policy
+rules govern cluster names and IP summaries instead of leaving the fallback
+logic in the AI package.
The policy-posture aggregate itself now also comes from
`internal/unifiedresources/policy_posture.go`, so AI summaries and resource
context reuse the same canonical sensitivity, routing, and redaction counts
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 296500760c..69badcb864 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -481,6 +481,10 @@ The AI runtime now also uses the canonical policy presentation helpers to
surface those routing and redaction labels in shared context output, so the
same policy model is reflected in prompt summaries instead of being
re-described independently per surface.
+That same shared presentation layer now also owns governed cluster-name and
+IP-summary rendering for AI resource context, so topology labels and address
+lists stay aligned with the same redaction vocabulary instead of being
+formatted in AI-local helpers.
The AI correlation root-cause engine also consumes the canonical unified-
resource relationship model directly, so graph reasoning and relationship
scoring stay on the same owned edge vocabulary instead of keeping a separate
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index f1244e080e..71729f72de 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -187,7 +187,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
clusterInfo := ""
- if name := unifiedResourceContextClusterName(node); name != "" {
+ if name := unifiedresources.ResourceClusterName(node); name != "" {
clusterInfo = fmt.Sprintf(" [cluster: %s]", name)
}
@@ -210,7 +210,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
if len(standaloneHosts) > 0 {
sections = append(sections, "\n**Standalone Hosts (via Host Agent):**")
for _, host := range standaloneHosts {
- ips := unifiedResourceContextIPSummary(host, 0)
+ ips := unifiedresources.ResourceIPSummary(host, 0)
metrics := ""
cpuPercent := 0.0
@@ -279,7 +279,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
clusterInfo := ""
- if name := unifiedResourceContextClusterName(cluster); name != "" {
+ if name := unifiedresources.ResourceClusterName(cluster); name != "" {
clusterInfo = fmt.Sprintf(" [cluster: %s]", name)
}
sections = append(sections, fmt.Sprintf("- **%s** (Cluster%s, %d nodes) [%s]",
@@ -293,7 +293,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
clusterInfo := ""
- if name := unifiedResourceContextClusterName(node); name != "" {
+ if name := unifiedresources.ResourceClusterName(node); name != "" {
clusterInfo = fmt.Sprintf(" [cluster: %s]", name)
}
@@ -366,7 +366,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
vmidInfo = fmt.Sprintf(" %d", workload.Proxmox.VMID)
}
- ips := unifiedResourceContextIPSummary(workload, 2)
+ ips := unifiedresources.ResourceIPSummary(workload, 2)
sections = append(sections, fmt.Sprintf(" - **%s** (%s%s)%s [%s]",
unifiedresources.ResourcePolicyLabel(workload.Name, workload.AISafeSummary, workload.Policy), typeLabel, vmidInfo, ips, workload.Status))
@@ -379,7 +379,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
})
sections = append(sections, "\n**Other workloads:**")
for _, workload := range noParent {
- ips := unifiedResourceContextIPSummary(workload, 2)
+ ips := unifiedresources.ResourceIPSummary(workload, 2)
sections = append(sections, fmt.Sprintf(" - **%s** (%s)%s [%s]",
unifiedresources.ResourcePolicyLabel(workload.Name, workload.AISafeSummary, workload.Policy), workload.Type, ips, workload.Status))
}
@@ -546,37 +546,6 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
return ""
}
-func unifiedResourceContextClusterName(r unifiedresources.Resource) string {
- name := ""
- switch {
- case strings.TrimSpace(r.Identity.ClusterName) != "":
- name = strings.TrimSpace(r.Identity.ClusterName)
- case r.Proxmox != nil && strings.TrimSpace(r.Proxmox.ClusterName) != "":
- name = strings.TrimSpace(r.Proxmox.ClusterName)
- case r.Kubernetes != nil && strings.TrimSpace(r.Kubernetes.ClusterName) != "":
- name = strings.TrimSpace(r.Kubernetes.ClusterName)
- }
- if name == "" {
- return ""
- }
- return unifiedresources.ResourcePolicyRedactedValue(name, r.Policy,
- unifiedresources.ResourceRedactionAlias,
- unifiedresources.ResourceRedactionHostname,
- unifiedresources.ResourceRedactionPlatformID,
- )
-}
-
-func unifiedResourceContextIPSummary(r unifiedresources.Resource, limit int) string {
- ips := r.Identity.IPAddresses
- if len(ips) == 0 {
- return ""
- }
- if limit > 0 && len(ips) > limit {
- ips = ips[:limit]
- }
- return " - IPs " + unifiedresources.ResourcePolicyRedactedValue(strings.Join(ips, ", "), r.Policy, unifiedresources.ResourceRedactionIPAddress)
-}
-
func unifiedMetricPercent(m *unifiedresources.MetricValue) float64 {
if m == nil {
return 0
diff --git a/internal/ai/resource_context_test.go b/internal/ai/resource_context_test.go
index 46edf4923b..332471276c 100644
--- a/internal/ai/resource_context_test.go
+++ b/internal/ai/resource_context_test.go
@@ -407,35 +407,6 @@ func TestUnifiedResourceDisplayNameUsesSharedHelper(t *testing.T) {
}
}
-func TestUnifiedResourceContextIPSummaryUsesSharedHelper(t *testing.T) {
- sensitive := unifiedresources.Resource{
- Policy: &unifiedresources.ResourcePolicy{
- Sensitivity: unifiedresources.ResourceSensitivitySensitive,
- Routing: unifiedresources.ResourceRoutingPolicy{
- Scope: unifiedresources.ResourceRoutingScopeLocalFirst,
- Redact: []unifiedresources.ResourceRedactionHint{
- unifiedresources.ResourceRedactionIPAddress,
- },
- },
- },
- Identity: unifiedresources.ResourceIdentity{
- IPAddresses: []string{"10.0.0.10", "10.0.0.11"},
- },
- }
- if got := unifiedResourceContextIPSummary(sensitive, 10); got != " - IPs redacted by policy" {
- t.Fatalf("unifiedResourceContextIPSummary() = %q, want redacted summary", got)
- }
-
- public := unifiedresources.Resource{
- Identity: unifiedresources.ResourceIdentity{
- IPAddresses: []string{"10.0.0.10", "10.0.0.11"},
- },
- }
- if got := unifiedResourceContextIPSummary(public, 10); got != " - IPs 10.0.0.10, 10.0.0.11" {
- t.Fatalf("unifiedResourceContextIPSummary() = %q, want IP list", got)
- }
-}
-
func TestBuildUnifiedResourceContext_UnifiedPath(t *testing.T) {
clusterID := "k8s-cluster-1"
k8sCluster := unifiedresources.Resource{
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index fd29a5cfae..798f89faa5 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -415,8 +415,9 @@ func TestResourcePolicyLabelHelpersUsedByAIConsumers(t *testing.T) {
},
filepath.Join("..", "ai", "resource_context.go"): {
"unifiedresources.ResourcePolicyLabel(",
- "unifiedresources.ResourcePolicyRedactedValue(",
"unifiedresources.ResourceDisplayName(",
+ "unifiedresources.ResourceClusterName(",
+ "unifiedresources.ResourceIPSummary(",
},
filepath.Join("..", "unifiedresources", "unified_ai_adapter.go"): {
"ResourceDisplayName(results[i])",
@@ -427,6 +428,8 @@ func TestResourcePolicyLabelHelpersUsedByAIConsumers(t *testing.T) {
"func ResourcePolicyRedactedValue(value string, policy *ResourcePolicy, hints ...ResourceRedactionHint) string",
"const ResourcePolicyRedactedLabel = \"redacted by policy\"",
"func ResourceRedactionLabelsFromHints(hints []ResourceRedactionHint) []string",
+ "func ResourceClusterName(resource Resource) string",
+ "func ResourceIPSummary(resource Resource, limit int) string",
"func ResourcePolicyRequiresGovernedSummary(policy *ResourcePolicy) bool",
"func ResourcePolicyGovernedSummaryPreamble() string",
"func ResourcePolicyGovernedSummaryFooter() string",
diff --git a/internal/unifiedresources/policy_metadata_test.go b/internal/unifiedresources/policy_metadata_test.go
index 17b9f1149f..65dca3ac68 100644
--- a/internal/unifiedresources/policy_metadata_test.go
+++ b/internal/unifiedresources/policy_metadata_test.go
@@ -160,6 +160,56 @@ func TestResourcePolicyPresentationLabels(t *testing.T) {
}
}
+func TestResourceClusterName(t *testing.T) {
+ public := Resource{
+ Identity: ResourceIdentity{
+ ClusterName: " cluster-a ",
+ },
+ }
+ if got := ResourceClusterName(public); got != "cluster-a" {
+ t.Fatalf("ResourceClusterName() = %q, want cluster-a", got)
+ }
+
+ governed := Resource{
+ Policy: &ResourcePolicy{
+ Routing: ResourceRoutingPolicy{
+ Redact: []ResourceRedactionHint{ResourceRedactionHostname},
+ },
+ },
+ Kubernetes: &K8sData{
+ ClusterName: "k8s-prod",
+ },
+ }
+ if got := ResourceClusterName(governed); got != ResourcePolicyRedactedLabel {
+ t.Fatalf("ResourceClusterName() with governed policy = %q, want redacted label", got)
+ }
+}
+
+func TestResourceIPSummary(t *testing.T) {
+ public := Resource{
+ Identity: ResourceIdentity{
+ IPAddresses: []string{"10.0.0.1", "10.0.0.2", "10.0.0.3"},
+ },
+ }
+ if got := ResourceIPSummary(public, 2); got != " - IPs 10.0.0.1, 10.0.0.2" {
+ t.Fatalf("ResourceIPSummary() = %q, want truncated IP list", got)
+ }
+
+ governed := Resource{
+ Policy: &ResourcePolicy{
+ Routing: ResourceRoutingPolicy{
+ Redact: []ResourceRedactionHint{ResourceRedactionIPAddress},
+ },
+ },
+ Identity: ResourceIdentity{
+ IPAddresses: []string{"10.0.0.10", "10.0.0.11"},
+ },
+ }
+ if got := ResourceIPSummary(governed, 10); got != " - IPs redacted by policy" {
+ t.Fatalf("ResourceIPSummary() with governed policy = %q, want redacted summary", got)
+ }
+}
+
func TestResourcePolicyRedactionLabelsUseCanonicalOrder(t *testing.T) {
policy := &ResourcePolicy{
Routing: ResourceRoutingPolicy{
diff --git a/internal/unifiedresources/policy_presentation.go b/internal/unifiedresources/policy_presentation.go
index 601daf7bac..8dca922c0b 100644
--- a/internal/unifiedresources/policy_presentation.go
+++ b/internal/unifiedresources/policy_presentation.go
@@ -276,6 +276,41 @@ func ResourceDisplayName(resource Resource) string {
return strings.TrimSpace(resource.ID)
}
+// ResourceClusterName returns the canonical cluster or topology name for a resource.
+func ResourceClusterName(resource Resource) string {
+ var name string
+ switch {
+ case strings.TrimSpace(resource.Identity.ClusterName) != "":
+ name = strings.TrimSpace(resource.Identity.ClusterName)
+ case resource.Proxmox != nil && strings.TrimSpace(resource.Proxmox.ClusterName) != "":
+ name = strings.TrimSpace(resource.Proxmox.ClusterName)
+ case resource.Kubernetes != nil && strings.TrimSpace(resource.Kubernetes.ClusterName) != "":
+ name = strings.TrimSpace(resource.Kubernetes.ClusterName)
+ case resource.Kubernetes != nil && strings.TrimSpace(resource.Kubernetes.SourceName) != "":
+ name = strings.TrimSpace(resource.Kubernetes.SourceName)
+ }
+ if name == "" {
+ return ""
+ }
+ return ResourcePolicyRedactedValue(name, resource.Policy,
+ ResourceRedactionAlias,
+ ResourceRedactionHostname,
+ ResourceRedactionPlatformID,
+ )
+}
+
+// ResourceIPSummary returns the canonical governed IP summary line for a resource.
+func ResourceIPSummary(resource Resource, limit int) string {
+ ips := resource.Identity.IPAddresses
+ if len(ips) == 0 {
+ return ""
+ }
+ if limit > 0 && len(ips) > limit {
+ ips = ips[:limit]
+ }
+ return " - IPs " + ResourcePolicyRedactedValue(strings.Join(ips, ", "), resource.Policy, ResourceRedactionIPAddress)
+}
+
// ResourcePolicyUsesAISafeSummary reports whether the canonical aiSafeSummary
// should be used instead of raw resource labels for governed output.
func ResourcePolicyUsesAISafeSummary(summary string, policy *ResourcePolicy) bool {