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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix(truenas): stop one-shot init containers raising permanent CRITICALs
rcourtman8c5c5c0d2f5a
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 9b09e8d981..81baee4edd 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -920,6 +920,27 @@ changes.`TestClusterClient_GetTaskLog` in`pkg/proxmox/cluster_client_api_test.go`.+14. A TrueNAS app container reported as `EXITED` is a completed workload and+ must raise no incident. TrueNAS classifies container exits before Pulse+ sees them: a normal exit code becomes `EXITED`, an abnormal one becomes+ `CRASHED`, and any `CRASHED` container promotes the app itself to+ `CRASHED`. Every SCALE catalog app ships one-shot init containers from+ ixSystems' base images (`permissions`, `postgres_upgrade`,+ `pgvecto_upgrade`) that exit cleanly and stay exited for the life of the+ app, so treating `EXITED` as failure raises a standing critical per+ installed app that can never clear. `incidentsFromAppState` therefore+ raises `truenas_app_container_failed` only for `CRASHED` containers,+ where the per-container incident exists to name the failing service+ behind the app-level `truenas_app_crashed`. The rendered container state+ is likewise a collapse of every workload using the precedence TrueNAS+ applies (`crashed` > `created` > `starting` > `running` > `exited`), not+ the first entry `app.query` happens to return, so an init container+ sorting first cannot make a running app read as exited. Regression+ coverage: `TestRunningTrueNASAppWithCompletedOneShotContainersRaisesNoIncident`,+ `TestCrashedTrueNASAppContainerStillRaisesIncident` and+ `TestStoppedTrueNASAppContainerStateStaysExited` in+ `internal/truenas/provider_oneshot_containers_test.go`.+## Current Statediff --git a/internal/truenas/provider.go b/internal/truenas/provider.goindex dd13930a7b..c763b63f1c 100644--- a/internal/truenas/provider.go+++ b/internal/truenas/provider.go@@ -1488,12 +1488,16 @@ func incidentsFromAppState(app App, observedAt time.Time) []unifiedresources.Rescase "STOPPED":out = append(out, makeIncident("app:"+appID, "truenas_app_stopped", storagehealth.RiskWarning, fmt.Sprintf("TrueNAS app %s is stopped", name)))}- if !strings.EqualFold(strings.TrimSpace(app.State), "RUNNING") {- return out- }+ // TrueNAS already separates a completed workload from a failed one before+ // Pulse sees it: a container that exits with a normal exit code is reported+ // as EXITED, and one that exits abnormally is reported as CRASHED. Catalog+ // apps ship one-shot init containers (permissions, *_upgrade) that exit+ // cleanly and stay EXITED for the life of the app, so EXITED carries no+ // failure signal at all and must never raise an incident. CRASHED is the+ // real failure state, and TrueNAS rolls it up into an app-level CRASHED,+ // so the per-container incident exists to name the failing service.for _, container := range app.Containers {- state := strings.ToUpper(strings.TrimSpace(container.State))- if state != "CRASHED" && state != "EXITED" {+ if !strings.EqualFold(strings.TrimSpace(container.State), "CRASHED") {continue}containerID := firstNonEmptyString(container.ID, container.ServiceName, container.Image)@@ -1505,7 +1509,7 @@ func incidentsFromAppState(app App, observedAt time.Time) []unifiedresources.Res"app:"+appID+":container:"+containerID,"truenas_app_container_failed",storagehealth.RiskCritical,- fmt.Sprintf("Container %s in TrueNAS app %s is %s", containerName, name, state),+ fmt.Sprintf("Container %s in TrueNAS app %s is crashed", containerName, name),))}return out@@ -2413,13 +2417,40 @@ func copyStringLabels(labels map[string]string) map[string]string {return out}+// appContainerState collapses a TrueNAS app's workloads into the single state+// Pulse renders for the app. It mirrors the precedence TrueNAS uses to derive+// the app state itself, so the answer does not depend on the order app.query+// happens to return container_details in. Reading only the first container made+// an app whose init container (permissions, *_upgrade) sorted first read as+// "exited" while TrueNAS reported it RUNNING.func appContainerState(app App) string {- if len(app.Containers) > 0 {- state := strings.ToLower(strings.TrimSpace(app.Containers[0].State))- if state != "" {- return state+ var sawCrashed, sawCreated, sawStarting, sawRunning, sawExited bool+ for _, container := range app.Containers {+ switch strings.ToLower(strings.TrimSpace(container.State)) {+ case "crashed":+ sawCrashed = true+ case "created":+ sawCreated = true+ case "starting":+ sawStarting = true+ case "running":+ sawRunning = true+ case "exited":+ sawExited = true}}+ switch {+ case sawCrashed:+ return "crashed"+ case sawCreated:+ return "created"+ case sawStarting:+ return "starting"+ case sawRunning:+ return "running"+ case sawExited:+ return "exited"+ }return strings.ToLower(strings.TrimSpace(app.State))}diff --git a/internal/truenas/provider_oneshot_containers_test.go b/internal/truenas/provider_oneshot_containers_test.gonew file mode 100644index 0000000000..c796613507--- /dev/null+++ b/internal/truenas/provider_oneshot_containers_test.go@@ -0,0 +1,111 @@+package truenas++import (+ "testing"+ "time"+)++// TrueNAS SCALE catalog apps ship one-shot init containers from ixSystems' own+// base images (permissions, postgres_upgrade, pgvecto_upgrade). They run to+// completion and stay exited for the life of the app. TrueNAS reports them as+// EXITED, which its own state machine reserves for a normal exit code, and+// still reports the app as RUNNING. Pulse used to raise a CRITICAL per exited+// container on exactly those healthy apps, and because the containers never+// restart the alerts never cleared. Refs #1677.+func TestRunningTrueNASAppWithCompletedOneShotContainersRaisesNoIncident(t *testing.T) {+ observedAt := time.Date(2026, 8, 5, 9, 0, 0, 0, time.UTC)++ immich := App{+ ID: "immich",+ Name: "immich",+ State: "RUNNING",+ Containers: []AppContainer{+ {ID: "immich-server-1", ServiceName: "server", Image: "ghcr.io/immich-app/immich-server:v3.0.3", State: "running"},+ {ID: "immich-pgvecto-1", ServiceName: "pgvecto", Image: "ghcr.io/immich-app/postgres:18", State: "running"},+ {ID: "immich-ml-1", ServiceName: "machine-learning", Image: "ghcr.io/immich-app/immich-ml:v3.0.3-cuda", State: "running"},+ {ID: "immich-redis-1", ServiceName: "redis", Image: "valkey/valkey:9.1.1", State: "running"},+ {ID: "immich-pgvecto-upgrade-1", ServiceName: "pgvecto_upgrade", Image: "ixsystems/postgres-upgrade:1.2.13", State: "exited"},+ {ID: "immich-permissions-1", ServiceName: "permissions", Image: "ixsystems/container-utils:1.0.2", State: "exited"},+ },+ }+ if incidents := incidentsFromAppState(immich, observedAt); len(incidents) != 0 {+ t.Fatalf("running app with completed one-shots must raise nothing, got %+v", incidents)+ }++ // The init container sorting first must not decide the app's rendered state.+ backrest := App{+ ID: "backrest",+ Name: "backrest",+ State: "RUNNING",+ Containers: []AppContainer{+ {ID: "backrest-permissions-1", ServiceName: "permissions", Image: "ixsystems/container-utils:1.0.2", State: "exited"},+ {ID: "backrest-1", ServiceName: "backrest", Image: "ghcr.io/garethgeorge/backrest:v1.14.1", State: "running"},+ },+ }+ if incidents := incidentsFromAppState(backrest, observedAt); len(incidents) != 0 {+ t.Fatalf("init container ordering must not raise an incident, got %+v", incidents)+ }+ if got := appContainerState(backrest); got != "running" {+ t.Fatalf("appContainerState = %q, want \"running\"", got)+ }+}++// A container that exits with an abnormal code is reported by TrueNAS as+// CRASHED, not EXITED, and TrueNAS rolls that up into an app-level CRASHED.+// Pulse must keep naming the failing service so the app-level incident is+// actionable.+func TestCrashedTrueNASAppContainerStillRaisesIncident(t *testing.T) {+ observedAt := time.Date(2026, 8, 5, 9, 0, 0, 0, time.UTC)++ app := App{+ ID: "mealie",+ Name: "mealie",+ State: "CRASHED",+ Containers: []AppContainer{+ {ID: "mealie-permissions-1", ServiceName: "permissions", State: "exited"},+ {ID: "mealie-1", ServiceName: "mealie", State: "crashed"},+ },+ }+ incidents := incidentsFromAppState(app, observedAt)+ if len(incidents) != 2 {+ t.Fatalf("expected app-level and container-level incidents, got %+v", incidents)+ }+ var sawApp, sawContainer bool+ for _, incident := range incidents {+ switch incident.Code {+ case "truenas_app_crashed":+ sawApp = true+ case "truenas_app_container_failed":+ sawContainer = true+ if incident.NativeID != "app:mealie:container:mealie-1" {+ t.Fatalf("container incident must key on the crashed service, got %q", incident.NativeID)+ }+ if incident.Summary != "Container mealie in TrueNAS app mealie is crashed" {+ t.Fatalf("container incident summary = %q", incident.Summary)+ }+ }+ }+ if !sawApp || !sawContainer {+ t.Fatalf("expected both incident codes, got %+v", incidents)+ }+ if got := appContainerState(app); got != "crashed" {+ t.Fatalf("appContainerState = %q, want \"crashed\"", got)+ }+}++// A stopped app has every container exited, and that must still read as exited+// rather than falling through to the app state.+func TestStoppedTrueNASAppContainerStateStaysExited(t *testing.T) {+ app := App{+ ID: "adguard-home",+ Name: "AdGuard Home",+ State: "STOPPED",+ Containers: []AppContainer{{ID: "adguard-home-1", ServiceName: "adguard-home", State: "exited"}},+ }+ if got := appContainerState(app); got != "exited" {+ t.Fatalf("appContainerState = %q, want \"exited\"", got)+ }+ if got := appContainerState(App{ID: "bare", Name: "bare", State: "DEPLOYING"}); got != "deploying" {+ t.Fatalf("appContainerState with no containers = %q, want \"deploying\"", got)+ }+}diff --git a/internal/truenas/provider_pool_health_contract_test.go b/internal/truenas/provider_pool_health_contract_test.goindex 5f515bebe0..be4d1faa25 100644--- a/internal/truenas/provider_pool_health_contract_test.go+++ b/internal/truenas/provider_pool_health_contract_test.go@@ -51,7 +51,13 @@ func TestProviderProjectsFullZFSHealthAndActionableDatasetAppIncidents(t *testinApps: []App{{ID: "crashed", Name: "crashed", State: "CRASHED"},{ID: "stopped", Name: "stopped", State: "STOPPED"},- {ID: "partial", Name: "partial", State: "RUNNING", Containers: []AppContainer{{ID: "worker", ServiceName: "worker", State: "exited"}}},+ {ID: "partial", Name: "partial", State: "CRASHED", Containers: []AppContainer{{ID: "worker", ServiceName: "worker", State: "crashed"}}},+ // One-shot init containers exit cleanly and stay EXITED for the life+ // of a healthy app, so they must project no incident at all.+ {ID: "oneshot", Name: "oneshot", State: "RUNNING", Containers: []AppContainer{+ {ID: "oneshot-permissions", ServiceName: "permissions", State: "exited"},+ {ID: "oneshot-web", ServiceName: "web", State: "running"},+ }},},})@@ -109,6 +115,17 @@ func TestProviderProjectsFullZFSHealthAndActionableDatasetAppIncidents(t *testint.Fatalf("%s incidents = %+v", name, record.Resource.Incidents)}}++ oneshot := requireRecordByNameAndType(t, records, "oneshot", unifiedresources.ResourceTypeAppContainer)+ if len(oneshot.Resource.Incidents) != 0 {+ t.Fatalf("healthy app with a completed one-shot container must raise nothing, got %+v", oneshot.Resource.Incidents)+ }+ if oneshot.Resource.Status != unifiedresources.StatusOnline {+ t.Fatalf("oneshot status = %q, want online", oneshot.Resource.Status)+ }+ if oneshot.Resource.Docker == nil || oneshot.Resource.Docker.ContainerState != "running" {+ t.Fatalf("oneshot container state must not follow an arbitrary init container: %+v", oneshot.Resource.Docker)+ }}func TestNativeTrueNASPoolAlertSuppressesEquivalentSyntheticSignalsOnly(t *testing.T) {