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.

Classify canonical restart changes

rcourtman9e99193efd77
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 59217a79bd..f742d494ac 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -131,6 +131,9 @@ 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.
+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.
For relationship changes, the `from` and `to` fields now summarize the actual
edge(s) rather than only the parent pointer, so the API contract keeps the
graph transition legible even before the frontend expands the related-resource
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index c8f3c92dc8..e36bc9e944 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -91,6 +91,10 @@ to parent-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.
+The change emitter now also classifies canonical restart changes for Docker
+and Kubernetes resources when restart counters increase or uptime resets, so
+the timeline can distinguish restarts from generic state transitions instead
+of flattening them into status-only noise.
That store also now migrates legacy `resource_changes` tables that still carry
the pre-v6 `timestamp` column by backfilling canonical `observed_at` values,
adding the newer `occurred_at` field, and preserving the legacy timestamp on
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 4d8a42a0a1..ebd55889a1 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -3808,6 +3808,64 @@ func TestContract_ResourceTimelineRelationshipJSONSnapshot(t *testing.T) {
assertJSONSnapshot(t, got, want)
}
+func TestContract_ResourceTimelineRestartJSONSnapshot(t *testing.T) {
+ now := time.Date(2026, 3, 18, 17, 10, 0, 0, time.UTC)
+ payload := struct {
+ ResourceID string `json:"resourceId"`
+ RecentChanges []unifiedresources.ResourceChange `json:"recentChanges"`
+ Count int `json:"count"`
+ }{
+ 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",
+ Metadata: map[string]any{
+ "changedFields": []string{"docker.restartCount", "docker.uptimeSeconds"},
+ },
+ },
+ },
+ Count: 1,
+ }
+
+ got, err := json.Marshal(payload)
+ if err != nil {
+ t.Fatalf("marshal resource timeline restart response: %v", err)
+ }
+
+ const want = `{
+ "resourceId":"container:7",
+ "recentChanges":[
+ {
+ "id":"chg-restart-7",
+ "observedAt":"2026-03-18T17:10:00Z",
+ "occurredAt":"2026-03-18T17:10:00Z",
+ "resourceId":"container:7",
+ "kind":"restart",
+ "from":"online|docker.restartCount=1|docker.uptimeSeconds=3600",
+ "to":"online|docker.restartCount=2|docker.uptimeSeconds=120",
+ "sourceType":"platform_event",
+ "sourceAdapter":"docker_adapter",
+ "confidence":"high",
+ "reason":"resource restart detected",
+ "metadata":{"changedFields":["docker.restartCount","docker.uptimeSeconds"]}
+ }
+ ],
+ "count":1
+ }`
+
+ assertJSONSnapshot(t, got, want)
+}
+
func TestContract_ResourceFacetsJSONSnapshot(t *testing.T) {
now := time.Date(2026, 3, 18, 17, 0, 0, 0, time.UTC)
payload := struct {
diff --git a/internal/unifiedresources/change_emission.go b/internal/unifiedresources/change_emission.go
index 141a5ecb6b..7bd12fd6cd 100644
--- a/internal/unifiedresources/change_emission.go
+++ b/internal/unifiedresources/change_emission.go
@@ -108,6 +108,11 @@ func buildResourceChange(before Resource, beforeOK bool, after Resource, afterOK
change.Metadata = map[string]any{"changedFields": changedFields}
switch {
+ case resourceRestartChanged(before, after):
+ change.Kind = ChangeRestart
+ change.From = resourceRestartSummary(before)
+ change.To = resourceRestartSummary(after)
+ change.Reason = "resource restart detected"
case before.Status != after.Status || dockerCommandChanged(before, after) || dockerUpdateStatusChanged(before, after) || proxmoxLifecycleChanged(before, after):
change.Kind = ChangeStateTransition
change.From = resourceStateSummary(before)
@@ -171,6 +176,12 @@ func resourceChangedFields(before, after Resource) []string {
if !reflect.DeepEqual(before.Identity, after.Identity) {
changed = append(changed, "identity")
}
+ if dockerRestartChanged(before, after) {
+ changed = append(changed, "docker.restartCount", "docker.uptimeSeconds")
+ }
+ if kubernetesRestartChanged(before, after) {
+ changed = append(changed, "kubernetes.restarts", "kubernetes.uptimeSeconds")
+ }
if dockerCommandChanged(before, after) {
changed = append(changed, "docker.command")
}
@@ -206,6 +217,30 @@ func dockerUpdateStatusChanged(before, after Resource) bool {
return !reflect.DeepEqual(beforeStatus, afterStatus)
}
+func dockerRestartChanged(before, after Resource) bool {
+ if before.Docker == nil || after.Docker == nil {
+ return false
+ }
+ if after.Docker.RestartCount > before.Docker.RestartCount {
+ return true
+ }
+ return before.Docker.UptimeSeconds > 0 && after.Docker.UptimeSeconds > 0 && after.Docker.UptimeSeconds < before.Docker.UptimeSeconds
+}
+
+func resourceRestartChanged(before, after Resource) bool {
+ return dockerRestartChanged(before, after) || kubernetesRestartChanged(before, after)
+}
+
+func kubernetesRestartChanged(before, after Resource) bool {
+ if before.Kubernetes == nil || after.Kubernetes == nil {
+ return false
+ }
+ if after.Kubernetes.Restarts > before.Kubernetes.Restarts {
+ return true
+ }
+ return before.Kubernetes.UptimeSeconds > 0 && after.Kubernetes.UptimeSeconds > 0 && after.Kubernetes.UptimeSeconds < before.Kubernetes.UptimeSeconds
+}
+
func proxmoxLifecycleChanged(before, after Resource) bool {
var beforeProxmox, afterProxmox *struct {
ClusterName string
@@ -250,6 +285,23 @@ func resourceStateSummary(resource Resource) string {
return status
}
+func resourceRestartSummary(resource Resource) string {
+ parts := []string{resourceStateSummary(resource)}
+ if resource.Docker != nil {
+ parts = append(parts, fmt.Sprintf("docker.restartCount=%d", resource.Docker.RestartCount))
+ if resource.Docker.UptimeSeconds > 0 {
+ parts = append(parts, fmt.Sprintf("docker.uptimeSeconds=%d", resource.Docker.UptimeSeconds))
+ }
+ }
+ if resource.Kubernetes != nil {
+ parts = append(parts, fmt.Sprintf("kubernetes.restarts=%d", resource.Kubernetes.Restarts))
+ if resource.Kubernetes.UptimeSeconds > 0 {
+ parts = append(parts, fmt.Sprintf("kubernetes.uptimeSeconds=%d", resource.Kubernetes.UptimeSeconds))
+ }
+ }
+ return strings.Join(parts, "|")
+}
+
func resourceRelationSummary(resource Resource) string {
if summary := resourceRelationshipSummary(resource.Relationships); summary != "" {
return summary
diff --git a/internal/unifiedresources/change_emission_test.go b/internal/unifiedresources/change_emission_test.go
index cc7d716b55..eb73c99436 100644
--- a/internal/unifiedresources/change_emission_test.go
+++ b/internal/unifiedresources/change_emission_test.go
@@ -106,6 +106,90 @@ func TestBuildResourceChange_ClassifiesCapabilityChange(t *testing.T) {
}
}
+func TestBuildResourceChange_ClassifiesDockerRestartChange(t *testing.T) {
+ before := Resource{
+ ID: "container:1",
+ Type: ResourceTypeAppContainer,
+ Name: "container-1",
+ Status: StatusOnline,
+ Docker: &DockerData{
+ RestartCount: 1,
+ UptimeSeconds: 3600,
+ Image: "example/app:1",
+ UpdateStatus: &DockerUpdateStatusMeta{UpdateAvailable: false},
+ },
+ }
+ after := before
+ after.Docker = &DockerData{
+ RestartCount: 2,
+ UptimeSeconds: 120,
+ Image: "example/app:1",
+ UpdateStatus: &DockerUpdateStatusMeta{UpdateAvailable: false},
+ }
+
+ change := buildResourceChange(before, true, after, true, time.Now().UTC(), nil, SourcePlatformEvent, "")
+ if change == nil {
+ t.Fatal("expected docker restart change, got nil")
+ }
+ if change.Kind != ChangeRestart {
+ t.Fatalf("Kind = %q, want %q", change.Kind, ChangeRestart)
+ }
+ if change.From != "online|docker.restartCount=1|docker.uptimeSeconds=3600" || change.To != "online|docker.restartCount=2|docker.uptimeSeconds=120" {
+ t.Fatalf("From/To = %q/%q, want docker restart summaries", change.From, change.To)
+ }
+ if !sameStringSet(mustChangedFields(t, change), []string{"docker.restartCount", "docker.uptimeSeconds"}) {
+ t.Fatalf("changedFields = %+v, want docker restart counters", mustChangedFields(t, change))
+ }
+}
+
+func TestBuildResourceChange_ClassifiesKubernetesRestartChange(t *testing.T) {
+ before := Resource{
+ ID: "pod:1",
+ Type: ResourceTypePod,
+ Name: "pod-1",
+ Status: StatusOnline,
+ Kubernetes: &K8sData{
+ PodPhase: "Running",
+ Restarts: 1,
+ UptimeSeconds: 1800,
+ Namespace: "default",
+ PodUID: "pod-uid-1",
+ PodReason: "Running",
+ PodMessage: "",
+ OwnerKind: "Deployment",
+ OwnerName: "app",
+ ContainerRuntimeVersion: "containerd://1.7.0",
+ },
+ }
+ after := before
+ after.Kubernetes = &K8sData{
+ PodPhase: "Running",
+ Restarts: 2,
+ UptimeSeconds: 75,
+ Namespace: "default",
+ PodUID: "pod-uid-1",
+ PodReason: "Running",
+ PodMessage: "",
+ OwnerKind: "Deployment",
+ OwnerName: "app",
+ ContainerRuntimeVersion: "containerd://1.7.0",
+ }
+
+ change := buildResourceChange(before, true, after, true, time.Now().UTC(), nil, SourcePlatformEvent, "")
+ if change == nil {
+ t.Fatal("expected kubernetes restart change, got nil")
+ }
+ if change.Kind != ChangeRestart {
+ t.Fatalf("Kind = %q, want %q", change.Kind, ChangeRestart)
+ }
+ if change.From != "online|kubernetes.restarts=1|kubernetes.uptimeSeconds=1800" || change.To != "online|kubernetes.restarts=2|kubernetes.uptimeSeconds=75" {
+ t.Fatalf("From/To = %q/%q, want kubernetes restart summaries", change.From, change.To)
+ }
+ if !sameStringSet(mustChangedFields(t, change), []string{"kubernetes.restarts", "kubernetes.uptimeSeconds"}) {
+ t.Fatalf("changedFields = %+v, want kubernetes restart counters", mustChangedFields(t, change))
+ }
+}
+
func TestBuildResourceChange_ClassifiesConfigUpdate(t *testing.T) {
before := Resource{
ID: "vm:1",
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index fa6f69ce84..8f6710ac0e 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -289,11 +289,17 @@ func TestResourceChangeEmissionCoversRelationshipAndCapabilityChanges(t *testing
source := string(data)
requiredSnippets := []string{
"relatedResourceIDs(change.ResourceID, before, after)",
+ "case resourceRestartChanged(before, after):",
"if !reflect.DeepEqual(before.Relationships, after.Relationships) {",
"changed = append(changed, \"relationships\")",
+ "if dockerRestartChanged(before, after) {",
+ "changed = append(changed, \"docker.restartCount\", \"docker.uptimeSeconds\")",
+ "if kubernetesRestartChanged(before, after) {",
+ "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",
}
for _, snippet := range requiredSnippets {
if !strings.Contains(source, snippet) {