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.

feat(truenas): ingest apps as canonical workloads

rcourtman0de0245ea1a6
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 55921ba825..64510b0852 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -143,6 +143,12 @@ name, and type context from canonical `ReadState` instead of from
snapshot-owned VM/container arrays, so storage backup polling, guest snapshot
polling, timeout sizing, PBS recovery candidate assembly, and Proxmox recovery
ingest all follow unified runtime truth when a live resource registry exists.
+That same monitoring-owned workload boundary now includes canonical app
+workloads projected through unified resources, not only VM/LXC-style guests.
+Consumers that need runtime workload truth must treat `ReadState.Workloads()`
+as the cross-platform workload surface for VMs, system containers, docker
+containers, and API-backed app containers such as TrueNAS apps instead of
+assuming workload views stop at traditional guest types.
Typed unified-resource views also need to present canonical monitoring truth,
not raw ingest formatting. Linked topology accessors exposed through
`internal/unifiedresources/views.go` must trim outer whitespace before
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index ea1640fffa..f091f3b3ca 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -164,6 +164,13 @@ populate canonical `physicalDisk.temperature` and reuse the shared
physical-disk risk semantics, so infrastructure, storage, charts, and AI read
the same disk-health contract instead of inventing a provider-local temperature
surface.
+TrueNAS-managed applications now follow the same canonical workload rule. One
+TrueNAS app instance from `app.query` must project as one canonical
+`app-container` resource under `SourceTrueNAS`, reusing the shared workload and
+Docker payload contracts instead of inventing a `truenas-app` resource type or
+lane-local workload UI. Until Pulse ingests a real TrueNAS app stats/history
+path, those resources must keep metrics-history targets unset rather than
+pretending Docker memory-store history exists for them.
The canonical resource timeline now also owns durable incident-response facts
that materially changed resource investigation state. `ResourceChange` kinds
such as `alert_fired`, `alert_acknowledged`, `alert_unacknowledged`,
diff --git a/internal/api/resources_test.go b/internal/api/resources_test.go
index 6006843dbc..7d916a2590 100644
--- a/internal/api/resources_test.go
+++ b/internal/api/resources_test.go
@@ -2935,6 +2935,71 @@ func TestResourceListIncludesTrueNASPhysicalDiskTemperature(t *testing.T) {
}
}
+func TestResourceListIncludesTrueNASAppsAsAppContainers(t *testing.T) {
+ previous := truenas.IsFeatureEnabled()
+ truenas.SetFeatureEnabled(true)
+ t.Cleanup(func() {
+ truenas.SetFeatureEnabled(previous)
+ })
+
+ cfg := &config.Config{DataPath: t.TempDir()}
+ h := NewResourceHandlers(cfg)
+ h.SetStateProvider(resourceStateProvider{snapshot: models.StateSnapshot{LastUpdate: time.Now().UTC()}})
+ h.SetSupplementalRecordsProvider(unified.SourceTrueNAS, mockSupplementalRecordsProvider{
+ records: truenas.NewProvider(truenas.DefaultFixtures()).Records(),
+ ownedSources: []unified.DataSource{unified.SourceTrueNAS},
+ })
+
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, "/api/resources?type=app-container&source=truenas", nil)
+ h.HandleListResources(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
+ }
+
+ var resp ResourcesResponse
+ if err := json.NewDecoder(rec.Body).Decode(&resp); err != nil {
+ t.Fatalf("decode response: %v", err)
+ }
+ if len(resp.Data) != 2 {
+ t.Fatalf("expected 2 TrueNAS app-container resources, got %d", len(resp.Data))
+ }
+
+ var nextcloud *unified.Resource
+ for i := range resp.Data {
+ resource := &resp.Data[i]
+ if resource.Name == "Nextcloud" {
+ nextcloud = resource
+ break
+ }
+ }
+ if nextcloud == nil {
+ t.Fatalf("expected Nextcloud in TrueNAS app-container response, got %+v", resp.Data)
+ }
+ if !containsSource(nextcloud.Sources, unified.SourceTrueNAS) {
+ t.Fatalf("expected TrueNAS source, got %+v", nextcloud.Sources)
+ }
+ if nextcloud.ParentName != "truenas-main" {
+ t.Fatalf("expected Nextcloud parentName truenas-main, got %q", nextcloud.ParentName)
+ }
+ if nextcloud.Docker == nil {
+ t.Fatal("expected docker payload on TrueNAS app resource")
+ }
+ if nextcloud.Docker.ContainerID != "nextcloud" {
+ t.Fatalf("expected canonical app container ID %q, got %q", "nextcloud", nextcloud.Docker.ContainerID)
+ }
+ if nextcloud.Docker.Image != "docker.io/library/nextcloud:29.0.7" {
+ t.Fatalf("expected Nextcloud image %q, got %q", "docker.io/library/nextcloud:29.0.7", nextcloud.Docker.Image)
+ }
+ if nextcloud.Docker.Runtime != "docker" {
+ t.Fatalf("expected runtime docker, got %q", nextcloud.Docker.Runtime)
+ }
+ if nextcloud.MetricsTarget != nil {
+ t.Fatalf("expected metrics target to remain unset until TrueNAS app stats are ingested, got %+v", nextcloud.MetricsTarget)
+ }
+}
+
func TestResourceStorageIncidentsGroupsCanonicalSections(t *testing.T) {
now := time.Now().UTC()
cfg := &config.Config{DataPath: t.TempDir()}
diff --git a/internal/truenas/client.go b/internal/truenas/client.go
index 7afabe70ed..3667bcfcf6 100644
--- a/internal/truenas/client.go
+++ b/internal/truenas/client.go
@@ -312,6 +312,57 @@ func (c *Client) GetAlerts(ctx context.Context) ([]Alert, error) {
return alerts, nil
}
+// GetApps returns the best-effort TrueNAS app inventory as canonical workload
+// candidates. The API surface varies across TrueNAS releases, so we parse the
+// documented app.query response shape loosely.
+func (c *Client) GetApps(ctx context.Context) ([]App, error) {
+ var response []map[string]any
+ if err := c.getJSON(ctx, http.MethodGet, "/app", &response); err != nil {
+ return nil, err
+ }
+
+ apps := make([]App, 0, len(response))
+ for _, item := range response {
+ activeWorkloads := readMapAny(item, "active_workloads", "activeWorkloads")
+
+ app := App{
+ ID: strings.TrimSpace(readStringAny(item, "id")),
+ Name: strings.TrimSpace(readStringAny(item, "name")),
+ State: strings.TrimSpace(readStringAny(item, "state")),
+ Version: strings.TrimSpace(readStringAny(item, "version")),
+ HumanVersion: strings.TrimSpace(readStringAny(item, "human_version", "humanVersion")),
+ CustomApp: readBoolAny(item, "custom_app", "customApp"),
+ UpgradeAvailable: readBoolAny(item, "upgrade_available", "upgradeAvailable"),
+ ImageUpdatesAvailable: readBoolAny(item, "image_updates_available", "imageUpdatesAvailable"),
+ Notes: strings.TrimSpace(readStringAny(item, "notes")),
+ ContainerCount: readIntAny(activeWorkloads, "containers"),
+ UsedHostIPs: dedupeStrings(readStringSliceAny(activeWorkloads, "used_host_ips", "usedHostIps")),
+ UsedPorts: parseAppPorts(readSliceAny(activeWorkloads, "used_ports", "usedPorts")),
+ Containers: parseAppContainers(readSliceAny(activeWorkloads, "container_details", "containerDetails")),
+ Volumes: parseAppVolumes(readSliceAny(activeWorkloads, "volumes")),
+ Images: dedupeStrings(readStringSliceAny(activeWorkloads, "images")),
+ Networks: parseAppNetworks(readSliceAny(activeWorkloads, "networks")),
+ }
+
+ if app.Name == "" {
+ app.Name = app.ID
+ }
+ if app.ContainerCount <= 0 {
+ app.ContainerCount = len(app.Containers)
+ }
+ if len(app.Images) == 0 {
+ app.Images = dedupeStrings(appImagesFromContainers(app.Containers))
+ }
+ if len(app.Volumes) == 0 {
+ app.Volumes = dedupeAppVolumes(appVolumesFromContainers(app.Containers))
+ }
+
+ apps = append(apps, app)
+ }
+
+ return apps, nil
+}
+
// GetZFSSnapshots returns a best-effort list of ZFS snapshots.
//
// NOTE: TrueNAS exposes multiple snapshot APIs across versions. We intentionally parse the
@@ -459,6 +510,7 @@ func (c *Client) FetchSnapshot(ctx context.Context) (*FixtureSnapshot, error) {
}
// Recovery artifacts are best-effort: do not fail monitoring if additional endpoints are unavailable.
+ apps, _ := c.GetApps(ctx)
zfsSnapshots, _ := c.GetZFSSnapshots(ctx)
replicationTasks, _ := c.GetReplicationTasks(ctx)
@@ -469,6 +521,7 @@ func (c *Client) FetchSnapshot(ctx context.Context) (*FixtureSnapshot, error) {
Datasets: datasets,
Disks: disks,
Alerts: alerts,
+ Apps: apps,
ZFSSnapshots: zfsSnapshots,
ReplicationTasks: replicationTasks,
}, nil
@@ -586,6 +639,286 @@ func splitSnapshotName(full string) (dataset string, snapshot string) {
return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
}
+func readMapAny(record map[string]any, keys ...string) map[string]any {
+ if record == nil {
+ return nil
+ }
+ for _, key := range keys {
+ value, ok := record[key]
+ if !ok || value == nil {
+ continue
+ }
+ if typed, ok := value.(map[string]any); ok {
+ return typed
+ }
+ }
+ return nil
+}
+
+func readSliceAny(record map[string]any, keys ...string) []any {
+ if record == nil {
+ return nil
+ }
+ for _, key := range keys {
+ value, ok := record[key]
+ if !ok || value == nil {
+ continue
+ }
+ if typed, ok := value.([]any); ok {
+ return typed
+ }
+ }
+ return nil
+}
+
+func readBoolAny(record map[string]any, keys ...string) bool {
+ if record == nil {
+ return false
+ }
+ for _, key := range keys {
+ value, ok := record[key]
+ if !ok || value == nil {
+ continue
+ }
+ switch typed := value.(type) {
+ case bool:
+ return typed
+ case string:
+ switch strings.ToLower(strings.TrimSpace(typed)) {
+ case "1", "true", "yes", "on":
+ return true
+ }
+ case map[string]any:
+ if parsed, ok := firstAny(typed, "parsed", "rawvalue", "value"); ok {
+ if readBoolAny(map[string]any{"value": parsed}, "value") {
+ return true
+ }
+ }
+ }
+ }
+ return false
+}
+
+func readIntAny(record map[string]any, keys ...string) int {
+ if record == nil {
+ return 0
+ }
+ for _, key := range keys {
+ value, ok := record[key]
+ if !ok || value == nil {
+ continue
+ }
+ if parsed, ok := parseInt64Any(value); ok {
+ return int(parsed)
+ }
+ }
+ return 0
+}
+
+func parseAppPorts(entries []any) []AppPort {
+ if len(entries) == 0 {
+ return nil
+ }
+ ports := make([]AppPort, 0, len(entries))
+ for _, entry := range entries {
+ record, ok := entry.(map[string]any)
+ if !ok {
+ continue
+ }
+
+ port := AppPort{
+ ContainerPort: readIntAny(record, "container_port", "containerPort"),
+ Protocol: strings.ToLower(strings.TrimSpace(readStringAny(record, "protocol"))),
+ HostPorts: parseAppHostPorts(readSliceAny(record, "host_ports", "hostPorts")),
+ }
+ if port.ContainerPort == 0 && len(port.HostPorts) == 0 {
+ continue
+ }
+ ports = append(ports, port)
+ }
+ if len(ports) == 0 {
+ return nil
+ }
+ return ports
+}
+
+func parseAppHostPorts(entries []any) []AppHostPort {
+ if len(entries) == 0 {
+ return nil
+ }
+ ports := make([]AppHostPort, 0, len(entries))
+ for _, entry := range entries {
+ record, ok := entry.(map[string]any)
+ if !ok {
+ continue
+ }
+ hostPort := AppHostPort{
+ HostPort: readIntAny(record, "host_port", "hostPort"),
+ HostIP: strings.TrimSpace(readStringAny(record, "host_ip", "hostIp")),
+ }
+ if hostPort.HostPort == 0 && hostPort.HostIP == "" {
+ continue
+ }
+ ports = append(ports, hostPort)
+ }
+ if len(ports) == 0 {
+ return nil
+ }
+ return ports
+}
+
+func parseAppContainers(entries []any) []AppContainer {
+ if len(entries) == 0 {
+ return nil
+ }
+ containers := make([]AppContainer, 0, len(entries))
+ for _, entry := range entries {
+ record, ok := entry.(map[string]any)
+ if !ok {
+ continue
+ }
+ container := AppContainer{
+ ID: strings.TrimSpace(readStringAny(record, "id")),
+ ServiceName: strings.TrimSpace(readStringAny(record, "service_name", "serviceName")),
+ Image: strings.TrimSpace(readStringAny(record, "image")),
+ State: strings.TrimSpace(readStringAny(record, "state")),
+ PortConfig: parseAppPorts(readSliceAny(record, "port_config", "portConfig")),
+ VolumeMounts: parseAppVolumes(readSliceAny(record, "volume_mounts", "volumeMounts")),
+ }
+ if container.ID == "" && container.ServiceName == "" && container.Image == "" {
+ continue
+ }
+ containers = append(containers, container)
+ }
+ if len(containers) == 0 {
+ return nil
+ }
+ return containers
+}
+
+func parseAppVolumes(entries []any) []AppVolume {
+ if len(entries) == 0 {
+ return nil
+ }
+ volumes := make([]AppVolume, 0, len(entries))
+ for _, entry := range entries {
+ record, ok := entry.(map[string]any)
+ if !ok {
+ continue
+ }
+ volume := AppVolume{
+ Source: strings.TrimSpace(readStringAny(record, "source")),
+ Destination: strings.TrimSpace(readStringAny(record, "destination")),
+ Mode: strings.TrimSpace(readStringAny(record, "mode")),
+ Type: strings.TrimSpace(readStringAny(record, "type")),
+ }
+ if volume.Source == "" && volume.Destination == "" {
+ continue
+ }
+ volumes = append(volumes, volume)
+ }
+ return dedupeAppVolumes(volumes)
+}
+
+func parseAppNetworks(entries []any) []AppNetwork {
+ if len(entries) == 0 {
+ return nil
+ }
+ networks := make([]AppNetwork, 0, len(entries))
+ for _, entry := range entries {
+ record, ok := entry.(map[string]any)
+ if !ok {
+ continue
+ }
+ network := AppNetwork{
+ ID: strings.TrimSpace(readStringAny(record, "id")),
+ Name: strings.TrimSpace(readStringAny(record, "name", "Name")),
+ Labels: readStringMapAny(record, "labels", "Labels"),
+ }
+ if network.ID == "" && network.Name == "" {
+ continue
+ }
+ networks = append(networks, network)
+ }
+ if len(networks) == 0 {
+ return nil
+ }
+ return networks
+}
+
+func readStringMapAny(record map[string]any, keys ...string) map[string]string {
+ if record == nil {
+ return nil
+ }
+ for _, key := range keys {
+ value, ok := record[key]
+ if !ok || value == nil {
+ continue
+ }
+ typed, ok := value.(map[string]any)
+ if !ok {
+ continue
+ }
+ out := make(map[string]string, len(typed))
+ for labelKey, labelValue := range typed {
+ out[strings.TrimSpace(labelKey)] = strings.TrimSpace(fmt.Sprintf("%v", labelValue))
+ }
+ if len(out) == 0 {
+ continue
+ }
+ return out
+ }
+ return nil
+}
+
+func appImagesFromContainers(containers []AppContainer) []string {
+ if len(containers) == 0 {
+ return nil
+ }
+ images := make([]string, 0, len(containers))
+ for _, container := range containers {
+ image := strings.TrimSpace(container.Image)
+ if image == "" {
+ continue
+ }
+ images = append(images, image)
+ }
+ return images
+}
+
+func appVolumesFromContainers(containers []AppContainer) []AppVolume {
+ if len(containers) == 0 {
+ return nil
+ }
+ volumes := make([]AppVolume, 0, len(containers))
+ for _, container := range containers {
+ volumes = append(volumes, container.VolumeMounts...)
+ }
+ return volumes
+}
+
+func dedupeAppVolumes(volumes []AppVolume) []AppVolume {
+ if len(volumes) == 0 {
+ return nil
+ }
+ seen := make(map[string]struct{}, len(volumes))
+ out := make([]AppVolume, 0, len(volumes))
+ for _, volume := range volumes {
+ key := strings.Join([]string{
+ strings.TrimSpace(volume.Source),
+ strings.TrimSpace(volume.Destination),
+ strings.TrimSpace(volume.Mode),
+ strings.TrimSpace(volume.Type),
+ }, "|")
+ if _, ok := seen[key]; ok {
+ continue
+ }
+ seen[key] = struct{}{}
+ out = append(out, volume)
+ }
+ return out
+}
+
func dedupeStrings(values []string) []string {
if len(values) == 0 {
return nil
diff --git a/internal/truenas/client_test.go b/internal/truenas/client_test.go
index 2d76f753f4..e4a3c883d9 100644
--- a/internal/truenas/client_test.go
+++ b/internal/truenas/client_test.go
@@ -108,6 +108,26 @@ func TestClientGetters(t *testing.T) {
if alerts[0].Datetime != time.UnixMilli(1707400000000).UTC() {
t.Fatalf("unexpected alert datetime: %s", alerts[0].Datetime)
}
+
+ apps, err := client.GetApps(ctx)
+ if err != nil {
+ t.Fatalf("GetApps() error = %v", err)
+ }
+ if len(apps) != 1 {
+ t.Fatalf("expected 1 app, got %d", len(apps))
+ }
+ if apps[0].ID != "nextcloud" || apps[0].Name != "Nextcloud" {
+ t.Fatalf("unexpected app identity mapping: %+v", apps[0])
+ }
+ if apps[0].ContainerCount != 2 || len(apps[0].Containers) != 2 {
+ t.Fatalf("unexpected app container mapping: %+v", apps[0])
+ }
+ if len(apps[0].UsedPorts) != 1 || apps[0].UsedPorts[0].ContainerPort != 443 {
+ t.Fatalf("unexpected app used ports mapping: %+v", apps[0].UsedPorts)
+ }
+ if len(apps[0].Volumes) != 2 || len(apps[0].Networks) != 1 {
+ t.Fatalf("unexpected app volume/network mapping: volumes=%d networks=%d", len(apps[0].Volumes), len(apps[0].Networks))
+ }
}
func TestClientAuthHeaderAPIKey(t *testing.T) {
@@ -186,13 +206,16 @@ func TestFetchSnapshot(t *testing.T) {
if snapshot.System.Hostname != "truenas-main" {
t.Fatalf("unexpected snapshot system: %+v", snapshot.System)
}
- if len(snapshot.Pools) != 1 || len(snapshot.Datasets) != 1 || len(snapshot.Disks) != 2 || len(snapshot.Alerts) != 1 {
- t.Fatalf("unexpected snapshot counts: pools=%d datasets=%d disks=%d alerts=%d",
- len(snapshot.Pools), len(snapshot.Datasets), len(snapshot.Disks), len(snapshot.Alerts))
+ if len(snapshot.Pools) != 1 || len(snapshot.Datasets) != 1 || len(snapshot.Disks) != 2 || len(snapshot.Alerts) != 1 || len(snapshot.Apps) != 1 {
+ t.Fatalf("unexpected snapshot counts: pools=%d datasets=%d disks=%d alerts=%d apps=%d",
+ len(snapshot.Pools), len(snapshot.Datasets), len(snapshot.Disks), len(snapshot.Alerts), len(snapshot.Apps))
}
if snapshot.Disks[0].Temperature != 34 || snapshot.Disks[1].Temperature != 49 {
t.Fatalf("unexpected snapshot disk temperatures: %+v", snapshot.Disks)
}
+ if snapshot.Apps[0].ID != "nextcloud" || snapshot.Apps[0].ContainerCount != 2 {
+ t.Fatalf("unexpected snapshot apps: %+v", snapshot.Apps)
+ }
}
func TestGetDiskTemperaturesSupportsArrayShape(t *testing.T) {
@@ -437,6 +460,9 @@ func defaultAPIResponses() map[string]apiResponse {
"/api/v2.0/alert/list": {
body: `[{"id":"a1","level":"WARNING","formatted":"Disk temp high","source":"DiskService","dismissed":false,"datetime":{"$date":1707400000000}}]`,
},
+ "/api/v2.0/app": {
+ body: `[{"id":"nextcloud","name":"Nextcloud","state":"RUNNING","version":"1.0.3","human_version":"29.0.7","upgrade_available":true,"image_updates_available":true,"notes":"Team cloud","active_workloads":{"containers":2,"used_host_ips":["0.0.0.0"],"used_ports":[{"container_port":443,"protocol":"tcp","host_ports":[{"host_port":30443,"host_ip":"0.0.0.0"}]}],"container_details":[{"id":"nextcloud-web-1","service_name":"nextcloud","image":"docker.io/library/nextcloud:29.0.7","state":"running","port_config":[{"container_port":443,"protocol":"tcp","host_ports":[{"host_port":30443,"host_ip":"0.0.0.0"}]}],"volume_mounts":[{"source":"/mnt/tank/apps/nextcloud","destination":"/var/www/html","mode":"rw","type":"bind"}]},{"id":"nextcloud-redis-1","service_name":"redis","image":"docker.io/library/redis:7.2","state":"running","port_config":[],"volume_mounts":[{"source":"ix-nextcloud-redis","destination":"/data","mode":"rw","type":"volume"}]}],"volumes":[{"source":"/mnt/tank/apps/nextcloud","destination":"/var/www/html","mode":"rw","type":"bind"},{"source":"ix-nextcloud-redis","destination":"/data","mode":"rw","type":"volume"}],"images":["docker.io/library/nextcloud:29.0.7","docker.io/library/redis:7.2"],"networks":[{"name":"ix-nextcloud_default","id":"net-1","labels":{"com.docker.compose.project":"nextcloud"}}]}}]`,
+ },
}
}
diff --git a/internal/truenas/contract_test.go b/internal/truenas/contract_test.go
index b32e721a7e..c086d7035d 100644
--- a/internal/truenas/contract_test.go
+++ b/internal/truenas/contract_test.go
@@ -40,15 +40,15 @@ func TestRegistryIngestRecordsTreatsTrueNASAsGenericDataSource(t *testing.T) {
registry.IngestRecords(unifiedresources.SourceTrueNAS, records)
resources := registry.List()
- wantCount := 1 + len(fixtures.Pools) + len(fixtures.Datasets) + len(fixtures.Disks)
+ wantCount := 1 + len(fixtures.Pools) + len(fixtures.Datasets) + len(fixtures.Disks) + len(fixtures.Apps)
if len(resources) != wantCount {
t.Fatalf("expected %d resources, got %d", wantCount, len(resources))
}
system := requireResource(t, resources, unifiedresources.ResourceTypeAgent, fixtures.System.Hostname)
assertSourceTracking(t, *system, unifiedresources.SourceTrueNAS)
- if system.ChildCount != len(fixtures.Pools) {
- t.Fatalf("expected system child count %d, got %d", len(fixtures.Pools), system.ChildCount)
+ if system.ChildCount != len(fixtures.Pools)+len(fixtures.Apps) {
+ t.Fatalf("expected system child count %d, got %d", len(fixtures.Pools)+len(fixtures.Apps), system.ChildCount)
}
if system.TrueNAS == nil {
t.Fatal("expected TrueNAS metadata on system record")
@@ -115,6 +115,24 @@ func TestRegistryIngestRecordsTreatsTrueNASAsGenericDataSource(t *testing.T) {
}
assertDiskMetric(t, dataset.Metrics, 18*1024*1024*1024*1024, 5*1024*1024*1024*1024)
+ app := requireResource(t, resources, unifiedresources.ResourceTypeAppContainer, "Nextcloud")
+ assertSourceTracking(t, *app, unifiedresources.SourceTrueNAS)
+ if app.ParentID == nil || *app.ParentID != system.ID {
+ t.Fatalf("expected app parent %q, got %+v", system.ID, app.ParentID)
+ }
+ if app.Docker == nil {
+ t.Fatal("expected DockerData on TrueNAS app resource")
+ }
+ if app.Docker.ContainerID != "nextcloud" {
+ t.Fatalf("expected app container ID nextcloud, got %q", app.Docker.ContainerID)
+ }
+ if app.Docker.Runtime != "docker" {
+ t.Fatalf("expected app runtime docker, got %q", app.Docker.Runtime)
+ }
+ if app.Status != unifiedresources.StatusOnline {
+ t.Fatalf("expected Nextcloud status online, got %q", app.Status)
+ }
+
disk := requireResource(t, resources, unifiedresources.ResourceTypePhysicalDisk, "sda")
assertSourceTracking(t, *disk, unifiedresources.SourceTrueNAS)
if disk.ParentID == nil || *disk.ParentID != pool.ID {
@@ -185,7 +203,7 @@ func TestTrueNASResourcesFlowThroughUnifiedTypesWithoutSpecialCasing(t *testing.
t.Fatalf("expected canonical render type, got truenas-specific type for %s", resource.ID)
}
switch resource.Type {
- case unifiedresources.ResourceTypeAgent, unifiedresources.ResourceTypeStorage, unifiedresources.ResourceTypePhysicalDisk:
+ case unifiedresources.ResourceTypeAgent, unifiedresources.ResourceTypeStorage, unifiedresources.ResourceTypePhysicalDisk, unifiedresources.ResourceTypeAppContainer:
default:
t.Fatalf("unexpected unified type for truenas fixture resource: %s (%s)", resource.Type, resource.ID)
}
@@ -286,7 +304,7 @@ func TestTrueNASDiskRecordsPopulatePhysicalDiskMeta(t *testing.T) {
if meta.Risk.Level != "warning" {
t.Fatalf("expected warning risk for degraded disk %q, got %+v", fixture.Name, meta.Risk)
}
- if len(meta.Risk.Reasons) == 0 || meta.Risk.Reasons[0].Code != "truenas_disk_state" {
+ if !containsRiskReason(meta.Risk.Reasons, "truenas_disk_state") {
t.Fatalf("expected truenas_disk_state reason for %q, got %+v", fixture.Name, meta.Risk.Reasons)
}
if len(record.Resource.Incidents) != 1 || record.Resource.Incidents[0].Code != "truenas_smart" {
@@ -307,6 +325,15 @@ func hasIncidentCode(incidents []unifiedresources.ResourceIncident, code string)
return false
}
+func containsRiskReason(reasons []unifiedresources.PhysicalDiskRiskReason, code string) bool {
+ for _, reason := range reasons {
+ if reason.Code == code {
+ return true
+ }
+ }
+ return false
+}
+
func requireResource(t *testing.T, resources []unifiedresources.Resource, resourceType unifiedresources.ResourceType, name string) *unifiedresources.Resource {
t.Helper()
for i := range resources {
diff --git a/internal/truenas/fixtures.go b/internal/truenas/fixtures.go
index e02248e702..6d8ff77524 100644
--- a/internal/truenas/fixtures.go
+++ b/internal/truenas/fixtures.go
@@ -157,5 +157,119 @@ func DefaultFixtures() FixtureSnapshot {
Datetime: time.Date(2026, 2, 5, 3, 0, 0, 0, time.UTC),
},
},
+ Apps: []App{
+ {
+ ID: "nextcloud",
+ Name: "Nextcloud",
+ State: "RUNNING",
+ Version: "1.0.3",
+ HumanVersion: "29.0.7",
+ UpgradeAvailable: true,
+ ImageUpdatesAvailable: true,
+ Notes: "Team cloud and file sync",
+ ContainerCount: 2,
+ UsedHostIPs: []string{"0.0.0.0"},
+ UsedPorts: []AppPort{
+ {
+ ContainerPort: 443,
+ Protocol: "tcp",
+ HostPorts: []AppHostPort{
+ {HostPort: 30443, HostIP: "0.0.0.0"},
+ },
+ },
+ },
+ Containers: []AppContainer{
+ {
+ ID: "nextcloud-web-1",
+ ServiceName: "nextcloud",
+ Image: "docker.io/library/nextcloud:29.0.7",
+ State: "running",
+ PortConfig: []AppPort{
+ {
+ ContainerPort: 443,
+ Protocol: "tcp",
+ HostPorts: []AppHostPort{
+ {HostPort: 30443, HostIP: "0.0.0.0"},
+ },
+ },
+ },
+ VolumeMounts: []AppVolume{
+ {
+ Source: "/mnt/tank/apps/nextcloud",
+ Destination: "/var/www/html",
+ Mode: "rw",
+ Type: "bind",
+ },
+ },
+ },
+ {
+ ID: "nextcloud-redis-1",
+ ServiceName: "redis",
+ Image: "docker.io/library/redis:7.2",
+ State: "running",
+ VolumeMounts: []AppVolume{
+ {
+ Source: "ix-nextcloud-redis",
+ Destination: "/data",
+ Mode: "rw",
+ Type: "volume",
+ },
+ },
+ },
+ },
+ Volumes: []AppVolume{
+ {
+ Source: "/mnt/tank/apps/nextcloud",
+ Destination: "/var/www/html",
+ Mode: "rw",
+ Type: "bind",
+ },
+ {
+ Source: "ix-nextcloud-redis",
+ Destination: "/data",
+ Mode: "rw",
+ Type: "volume",
+ },
+ },
+ Images: []string{
+ "docker.io/library/nextcloud:29.0.7",
+ "docker.io/library/redis:7.2",
+ },
+ Networks: []AppNetwork{
+ {
+ ID: "ix-nextcloud-default",
+ Name: "ix-nextcloud_default",
+ Labels: map[string]string{
+ "com.docker.compose.project": "nextcloud",
+ },
+ },
+ },
+ },
+ {
+ ID: "adguard-home",
+ Name: "AdGuard Home",
+ State: "STOPPED",
+ Version: "0.1.2",
+ HumanVersion: "0.107.64",
+ CustomApp: true,
+ Containers: []AppContainer{
+ {
+ ID: "adguard-home-1",
+ ServiceName: "adguard-home",
+ Image: "docker.io/adguard/adguardhome:v0.107.64",
+ State: "exited",
+ },
+ },
+ Volumes: []AppVolume{
+ {
+ Source: "/mnt/tank/apps/adguard-home",
+ Destination: "/opt/adguardhome/work",
+ Mode: "rw",
+ Type: "bind",
+ },
+ },
+ Images: []string{"docker.io/adguard/adguardhome:v0.107.64"},
+ },
+ },
}
}
diff --git a/internal/truenas/integration_test.go b/internal/truenas/integration_test.go
index eee7d04444..f96b90253e 100644
--- a/internal/truenas/integration_test.go
+++ b/internal/truenas/integration_test.go
@@ -39,6 +39,7 @@ func TestIntegrationFullLifecycle(t *testing.T) {
}
foundHost := false
+ foundAppWorkload := false
foundPoolStorage := false
foundDatasetStorage := false
foundPoolHealthTag := false
@@ -47,6 +48,9 @@ func TestIntegrationFullLifecycle(t *testing.T) {
if resource.Type == unifiedresources.ResourceTypeAgent && resource.Name == "truenas-main" {
foundHost = true
}
+ if resource.Type == unifiedresources.ResourceTypeAppContainer && resource.Name == "Nextcloud" {
+ foundAppWorkload = true
+ }
if resource.Type != unifiedresources.ResourceTypeStorage {
continue
@@ -73,6 +77,9 @@ func TestIntegrationFullLifecycle(t *testing.T) {
if !foundHost {
t.Fatal("expected host resource named truenas-main")
}
+ if !foundAppWorkload {
+ t.Fatal("expected TrueNAS app-container workload named Nextcloud")
+ }
if !foundPoolStorage {
t.Fatal("expected at least one storage resource with pool tag")
}
diff --git a/internal/truenas/provider.go b/internal/truenas/provider.go
index 66c4fa903c..8134108f38 100644
--- a/internal/truenas/provider.go
+++ b/internal/truenas/provider.go
@@ -179,7 +179,7 @@ func (p *Provider) Records() []unifiedresources.IngestRecord {
systemRisk := unifiedresources.StorageRiskFromAssessment(systemAssessment)
_, protectionReduced, rebuildInProgress, protectionSummary, rebuildSummary := unifiedresources.StorageRiskSemantics(systemRisk)
systemIncidents, poolIncidents, diskIncidents := buildIncidentAssignments(snapshot)
- records := make([]unifiedresources.IngestRecord, 0, 1+len(snapshot.Pools)+len(snapshot.Datasets)+len(snapshot.Disks))
+ records := make([]unifiedresources.IngestRecord, 0, 1+len(snapshot.Pools)+len(snapshot.Datasets)+len(snapshot.Apps)+len(snapshot.Disks))
totalCapacity, totalUsed := aggregatePoolUsage(snapshot.Pools)
records = append(records, unifiedresources.IngestRecord{
@@ -301,6 +301,50 @@ func (p *Provider) Records() []unifiedresources.IngestRecord {
})
}
+ for _, app := range snapshot.Apps {
+ dockerMeta := &unifiedresources.DockerData{
+ ContainerID: appCanonicalID(app),
+ Hostname: strings.TrimSpace(snapshot.System.Hostname),
+ DisplayName: appDisplayName(app),
+ Image: primaryAppImage(app),
+ Runtime: "docker",
+ ContainerState: appContainerState(app),
+ Ports: dockerPortsFromTrueNASApp(app),
+ Mounts: dockerMountsFromTrueNASApp(app),
+ Networks: dockerNetworksFromTrueNASApp(app),
+ Labels: map[string]string{
+ "truenas.app_id": strings.TrimSpace(app.ID),
+ },
+ }
+ if strings.TrimSpace(app.Version) != "" {
+ dockerMeta.Labels["truenas.version"] = strings.TrimSpace(app.Version)
+ }
+ if strings.TrimSpace(app.HumanVersion) != "" {
+ dockerMeta.Labels["truenas.human_version"] = strings.TrimSpace(app.HumanVersion)
+ }
+ if app.CustomApp {
+ dockerMeta.Labels["truenas.custom_app"] = "true"
+ }
+
+ records = append(records, unifiedresources.IngestRecord{
+ SourceID: appSourceID(app.ID),
+ ParentSourceID: systemSourceID,
+ Resource: unifiedresources.Resource{
+ Type: unifiedresources.ResourceTypeAppContainer,
+ Technology: "docker",
+ Name: appDisplayName(app),
+ Status: statusFromApp(app),
+ LastSeen: collectedAt,
+ UpdatedAt: collectedAt,
+ Docker: dockerMeta,
+ Tags: appTags(app),
+ },
+ Identity: unifiedresources.ResourceIdentity{
+ Hostnames: dedupeStrings([]string{appDisplayName(app)}),
+ },
+ })
+ }
+
for _, disk := range snapshot.Disks {
assessment := assessDisk(disk)
incidents := diskIncidents[strings.TrimSpace(disk.Name)]
@@ -612,10 +656,153 @@ func datasetSourceID(dataset string) string {
return "dataset:" + strings.TrimSpace(dataset)
}
+func appSourceID(id string) string {
+ return "app:" + strings.TrimSpace(id)
+}
+
func diskSourceID(name string) string {
return "disk:" + strings.TrimSpace(name)
}
+func appDisplayName(app App) string {
+ if name := strings.TrimSpace(app.Name); name != "" {
+ return name
+ }
+ return strings.TrimSpace(app.ID)
+}
+
+func appCanonicalID(app App) string {
+ if id := strings.TrimSpace(app.ID); id != "" {
+ return id
+ }
+ return appDisplayName(app)
+}
+
+func primaryAppImage(app App) string {
+ if len(app.Images) > 0 {
+ if image := strings.TrimSpace(app.Images[0]); image != "" {
+ return image
+ }
+ }
+ for _, container := range app.Containers {
+ if image := strings.TrimSpace(container.Image); image != "" {
+ return image
+ }
+ }
+ return ""
+}
+
+func appContainerState(app App) string {
+ if len(app.Containers) > 0 {
+ state := strings.ToLower(strings.TrimSpace(app.Containers[0].State))
+ if state != "" {
+ return state
+ }
+ }
+ return strings.ToLower(strings.TrimSpace(app.State))
+}
+
+func statusFromApp(app App) unifiedresources.ResourceStatus {
+ switch strings.ToUpper(strings.TrimSpace(app.State)) {
+ case "RUNNING":
+ return unifiedresources.StatusOnline
+ case "DEPLOYING", "STOPPING", "CRASHED":
+ return unifiedresources.StatusWarning
+ case "STOPPED":
+ return unifiedresources.StatusOffline
+ default:
+ return unifiedresources.StatusUnknown
+ }
+}
+
+func appTags(app App) []string {
+ tags := []string{"truenas", "app"}
+ if state := strings.ToLower(strings.TrimSpace(app.State)); state != "" {
+ tags = append(tags, "state:"+state)
+ }
+ if app.CustomApp {
+ tags = append(tags, "custom-app")
+ }
+ return dedupeStrings(tags)
+}
+
+func dockerPortsFromTrueNASApp(app App) []unifiedresources.DockerPortMeta {
+ if len(app.UsedPorts) == 0 {
+ return nil
+ }
+ ports := make([]unifiedresources.DockerPortMeta, 0, len(app.UsedPorts))
+ for _, port := range app.UsedPorts {
+ if port.ContainerPort == 0 && len(port.HostPorts) == 0 {
+ continue
+ }
+ if len(port.HostPorts) == 0 {
+ ports = append(ports, unifiedresources.DockerPortMeta{
+ PrivatePort: port.ContainerPort,
+ Protocol: strings.ToLower(strings.TrimSpace(port.Protocol)),
+ })
+ continue
+ }
+ for _, hostPort := range port.HostPorts {
+ ports = append(ports, unifiedresources.DockerPortMeta{
+ PrivatePort: port.ContainerPort,
+ PublicPort: hostPort.HostPort,
+ Protocol: strings.ToLower(strings.TrimSpace(port.Protocol)),
+ IP: strings.TrimSpace(hostPort.HostIP),
+ })
+ }
+ }
+ if len(ports) == 0 {
+ return nil
+ }
+ return ports
+}
+
+func dockerMountsFromTrueNASApp(app App) []unifiedresources.DockerMountMeta {
+ if len(app.Volumes) == 0 {
+ return nil
+ }
+ mounts := make([]unifiedresources.DockerMountMeta, 0, len(app.Volumes))
+ for _, volume := range app.Volumes {
+ destination := strings.TrimSpace(volume.Destination)
+ source := strings.TrimSpace(volume.Source)
+ if destination == "" && source == "" {
+ continue
+ }
+ mounts = append(mounts, unifiedresources.DockerMountMeta{
+ Type: strings.TrimSpace(volume.Type),
+ Source: source,
+ Destination: destination,
+ Mode: strings.TrimSpace(volume.Mode),
+ RW: !strings.Contains(strings.ToLower(strings.TrimSpace(volume.Mode)), "ro"),
+ })
+ }
+ if len(mounts) == 0 {
+ return nil
+ }
+ return mounts
+}
+
+func dockerNetworksFromTrueNASApp(app App) []unifiedresources.DockerNetworkMeta {
+ if len(app.Networks) == 0 {
+ return nil
+ }
+ networks := make([]unifiedresources.DockerNetworkMeta, 0, len(app.Networks))
+ for _, network := range app.Networks {
+ name := strings.TrimSpace(network.Name)
+ if name == "" {
+ name = strings.TrimSpace(network.ID)
+ }
+ if name == "" {
+ continue
+ }
+ networks = append(networks, unifiedresources.DockerNetworkMeta{Name: name})
+ }
+ if len(networks) == 0 {
+ return nil
+ }
+ return networks
+}
+
func statusFromDisk(disk Disk) unifiedresources.ResourceStatus {
switch strings.ToUpper(strings.TrimSpace(disk.Status)) {
case "ONLINE":
@@ -674,7 +861,67 @@ func copyFixtureSnapshot(snapshot *FixtureSnapshot) *FixtureSnapshot {
copied.Datasets = append([]Dataset(nil), snapshot.Datasets...)
copied.Disks = append([]Disk(nil), snapshot.Disks...)
copied.Alerts = append([]Alert(nil), snapshot.Alerts...)
+ copied.Apps = cloneApps(snapshot.Apps)
copied.ZFSSnapshots = append([]ZFSSnapshot(nil), snapshot.ZFSSnapshots...)
copied.ReplicationTasks = append([]ReplicationTask(nil), snapshot.ReplicationTasks...)
return &copied
}
+
+func cloneApps(apps []App) []App {
+ if len(apps) == 0 {
+ return nil
+ }
+ out := make([]App, len(apps))
+ for i := range apps {
+ out[i] = apps[i]
+ out[i].UsedHostIPs = append([]string(nil), apps[i].UsedHostIPs...)
+ out[i].UsedPorts = cloneAppPorts(apps[i].UsedPorts)
+ out[i].Containers = cloneAppContainers(apps[i].Containers)
+ out[i].Volumes = append([]AppVolume(nil), apps[i].Volumes...)
+ out[i].Images = append([]string(nil), apps[i].Images...)
+ out[i].Networks = cloneAppNetworks(apps[i].Networks)
+ }
+ return out
+}
+
+func cloneAppPorts(ports []AppPort) []AppPort {
+ if len(ports) == 0 {
+ return nil
+ }
+ out := make([]AppPort, len(ports))
+ for i := range ports {
+ out[i] = ports[i]
+ out[i].HostPorts = append([]AppHostPort(nil), ports[i].HostPorts...)
+ }
+ return out
+}
+
+func cloneAppContainers(containers []AppContainer) []AppContainer {
+ if len(containers) == 0 {
+ return nil
+ }
+ out := make([]AppContainer, len(containers))
+ for i := range containers {
+ out[i] = containers[i]
+ out[i].PortConfig = cloneAppPorts(containers[i].PortConfig)
+ out[i].VolumeMounts = append([]AppVolume(nil), containers[i].VolumeMounts...)
+ }
+ return out
+}
+
+func cloneAppNetworks(networks []AppNetwork) []AppNetwork {
+ if len(networks) == 0 {
+ return nil
+ }
+ out := make([]AppNetwork, len(networks))
+ for i := range networks {
+ out[i] = networks[i]
+ if len(networks[i].Labels) > 0 {
+ out[i].Labels = make(map[string]string, len(networks[i].Labels))
+ for key, value := range networks[i].Labels {
+ out[i].Labels[key] = value
+ }
+ }
+ }
+ return out
+}
diff --git a/internal/truenas/provider_test.go b/internal/truenas/provider_test.go
index 3121a44d0f..c9760b30ef 100644
--- a/internal/truenas/provider_test.go
+++ b/internal/truenas/provider_test.go
@@ -348,6 +348,73 @@ func TestRecordsIncludeDiskResourcesWithCorrectParentChain(t *testing.T) {
}
}
+func TestRecordsIncludeTrueNASAppsAsCanonicalWorkloads(t *testing.T) {
+ previous := IsFeatureEnabled()
+ SetFeatureEnabled(true)
+ t.Cleanup(func() {
+ SetFeatureEnabled(previous)
+ })
+
+ provider := NewProvider(DefaultFixtures())
+ records := provider.Records()
+ if len(records) == 0 {
+ t.Fatal("expected fixture records from provider")
+ }
+
+ var nextcloud *unifiedresources.IngestRecord
+ var adguard *unifiedresources.IngestRecord
+ for i := range records {
+ record := &records[i]
+ if record.Resource.Type != unifiedresources.ResourceTypeAppContainer {
+ continue
+ }
+ switch record.Resource.Name {
+ case "Nextcloud":
+ nextcloud = record
+ case "AdGuard Home":
+ adguard = record
+ }
+ }
+
+ if nextcloud == nil || adguard == nil {
+ t.Fatalf("expected TrueNAS app-container records for Nextcloud and AdGuard Home")
+ }
+ if nextcloud.ParentSourceID != "system:truenas-main" {
+ t.Fatalf("expected Nextcloud parent system:truenas-main, got %q", nextcloud.ParentSourceID)
+ }
+ if nextcloud.Resource.Technology != "docker" {
+ t.Fatalf("expected Nextcloud technology docker, got %q", nextcloud.Resource.Technology)
+ }
+ if nextcloud.Resource.Docker == nil {
+ t.Fatal("expected Nextcloud docker metadata")
+ }
+ if nextcloud.Resource.Docker.ContainerID != "nextcloud" {
+ t.Fatalf("expected Nextcloud canonical container ID %q, got %q", "nextcloud", nextcloud.Resource.Docker.ContainerID)
+ }
+ if nextcloud.Resource.Docker.Image != "docker.io/library/nextcloud:29.0.7" {
+ t.Fatalf("expected Nextcloud image %q, got %q", "docker.io/library/nextcloud:29.0.7", nextcloud.Resource.Docker.Image)
+ }
+ if nextcloud.Resource.Docker.Runtime != "docker" {
+ t.Fatalf("expected Nextcloud runtime docker, got %q", nextcloud.Resource.Docker.Runtime)
+ }
+ if len(nextcloud.Resource.Docker.Ports) != 1 || nextcloud.Resource.Docker.Ports[0].PublicPort != 30443 {
+ t.Fatalf("unexpected Nextcloud published ports: %+v", nextcloud.Resource.Docker.Ports)
+ }
+ if len(nextcloud.Resource.Docker.Mounts) != 2 {
+ t.Fatalf("expected Nextcloud mounts, got %+v", nextcloud.Resource.Docker.Mounts)
+ }
+ if nextcloud.Resource.Status != unifiedresources.StatusOnline {
+ t.Fatalf("expected Nextcloud status online, got %q", nextcloud.Resource.Status)
+ }
+
+ if adguard.Resource.Status != unifiedresources.StatusOffline {
+ t.Fatalf("expected AdGuard Home status offline, got %q", adguard.Resource.Status)
+ }
+ if adguard.Resource.Docker == nil || adguard.Resource.Docker.ContainerState != "exited" {
+ t.Fatalf("expected AdGuard Home container state exited, got %+v", adguard.Resource.Docker)
+ }
+}
+
func TestRecordsElevateOnlineDiskWhenTemperatureCritical(t *testing.T) {
previous := IsFeatureEnabled()
SetFeatureEnabled(true)
diff --git a/internal/truenas/types.go b/internal/truenas/types.go
index 7ce39521fc..0404f0b8b4 100644
--- a/internal/truenas/types.go
+++ b/internal/truenas/types.go
@@ -10,6 +10,7 @@ type FixtureSnapshot struct {
Datasets []Dataset
Disks []Disk
Alerts []Alert
+ Apps []App
ZFSSnapshots []ZFSSnapshot
ReplicationTasks []ReplicationTask
}
@@ -69,6 +70,65 @@ type Alert struct {
Datetime time.Time
}
+// App mirrors the subset of TrueNAS application fields needed for unified
+// workload mapping.
+type App struct {
+ ID string
+ Name string
+ State string
+ Version string
+ HumanVersion string
+ CustomApp bool
+ UpgradeAvailable bool
+ ImageUpdatesAvailable bool
+ Notes string
+ ContainerCount int
+ UsedHostIPs []string
+ UsedPorts []AppPort
+ Containers []AppContainer
+ Volumes []AppVolume
+ Images []string
+ Networks []AppNetwork
+}
+
+// AppPort describes an app-level published port mapping.
+type AppPort struct {
+ ContainerPort int
+ Protocol string
+ HostPorts []AppHostPort
+}
+
+// AppHostPort describes a host-bound port used by a TrueNAS app.
+type AppHostPort struct {
+ HostPort int
+ HostIP string
+}
+
+// AppContainer describes one runtime container inside a TrueNAS app.
+type AppContainer struct {
+ ID string
+ ServiceName string
+ Image string
+ State string
+ PortConfig []AppPort
+ VolumeMounts []AppVolume
+}
+
+// AppVolume describes a bind or named volume mount exposed by a TrueNAS app.
+type AppVolume struct {
+ Source string
+ Destination string
+ Mode string
+ Type string
+}
+
+// AppNetwork describes a Docker network attached to a TrueNAS app.
+type AppNetwork struct {
+ ID string
+ Name string
+ Labels map[string]string
+}
+
// ZFSSnapshot mirrors the subset of snapshot fields needed for recovery-point mapping.
type ZFSSnapshot struct {
ID string
diff --git a/internal/unifiedresources/read_state.go b/internal/unifiedresources/read_state.go
index af1cc250b5..79d640bb08 100644
--- a/internal/unifiedresources/read_state.go
+++ b/internal/unifiedresources/read_state.go
@@ -37,6 +37,6 @@ type ReadState interface {
K8sDeployments() []*K8sDeploymentView
// Polymorphic accessors for mixed-type iteration
- Workloads() []*WorkloadView // VMs + LXC containers
+ Workloads() []*WorkloadView // Canonical runtime workloads (VMs, system containers, app containers)
Infrastructure() []*InfrastructureView // All infrastructure parent resources
}
diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.go
index 95c79df7bb..fcdf8530c9 100644
--- a/internal/unifiedresources/registry.go
+++ b/internal/unifiedresources/registry.go
@@ -1764,6 +1764,8 @@ func (rr *ResourceRegistry) rebuildViews() {
case ResourceTypeAppContainer:
v := NewDockerContainerView(viewResource)
rr.cachedDockerContainers = append(rr.cachedDockerContainers, &v)
+ w := NewWorkloadView(viewResource)
+ rr.cachedWorkload = append(rr.cachedWorkload, &w)
case ResourceTypeAgent:
inf := NewInfrastructureView(viewResource)
rr.cachedInfra = append(rr.cachedInfra, &inf)
@@ -1896,7 +1898,7 @@ func (rr *ResourceRegistry) K8sDeployments() []*K8sDeploymentView {
return withViewCache(rr, func() []*K8sDeploymentView { return rr.cachedK8sDeployments })
}
-// Workloads returns a unified slice of VM + LXC container views sorted by name.
+// Workloads returns a unified slice of canonical workload views sorted by name.
func (rr *ResourceRegistry) Workloads() []*WorkloadView {
return withViewCache(rr, func() []*WorkloadView { return rr.cachedWorkload })
}
diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.go
index 8e97210447..10286beb09 100644
--- a/internal/unifiedresources/registry_test.go
+++ b/internal/unifiedresources/registry_test.go
@@ -1706,3 +1706,70 @@ func TestRegistryHasMatchingMonitoredSystemUsesCanonicalHostIdentity(t *testing.
t.Fatal("expected unrelated candidate not to match existing counted system")
}
}
+
+func TestResourceRegistry_WorkloadsIncludeCanonicalAppContainers(t *testing.T) {
+ rr := NewRegistry(nil)
+ now := time.Date(2026, 3, 29, 12, 0, 0, 0, time.UTC)
+
+ rr.IngestRecords(SourceProxmox, []IngestRecord{
+ {
+ SourceID: "vm-101",
+ Resource: Resource{
+ Type: ResourceTypeVM,
+ Name: "db-01",
+ Status: StatusOnline,
+ LastSeen: now,
+ },
+ },
+ })
+ rr.IngestRecords(SourceDocker, []IngestRecord{
+ {
+ SourceID: "ctr-201",
+ Resource: Resource{
+ Type: ResourceTypeAppContainer,
+ Name: "metrics-sidecar",
+ Status: StatusOnline,
+ LastSeen: now,
+ },
+ },
+ })
+ rr.IngestRecords(SourceTrueNAS, []IngestRecord{
+ {
+ SourceID: "app:nextcloud",
+ Resource: Resource{
+ Type: ResourceTypeAppContainer,
+ Name: "Nextcloud",
+ Status: StatusOnline,
+ LastSeen: now,
+ TrueNAS: &TrueNASData{Hostname: "truenas-main"},
+ Docker: &DockerData{
+ ContainerID: "nextcloud",
+ DisplayName: "Nextcloud",
+ Image: "library/nextcloud:latest",
+ Runtime: "docker",
+ ContainerState: "running",
+ },
+ },
+ },
+ })
+
+ workloads := rr.Workloads()
+ if len(workloads) != 3 {
+ t.Fatalf("Workloads() returned %d records, want 3", len(workloads))
+ }
+
+ typesByName := make(map[string]ResourceType, len(workloads))
+ for _, workload := range workloads {
+ typesByName[workload.Name()] = workload.Type()
+ }
+
+ if got := typesByName["db-01"]; got != ResourceTypeVM {
+ t.Fatalf("expected VM workload for db-01, got %q", got)
+ }
+ if got := typesByName["metrics-sidecar"]; got != ResourceTypeAppContainer {
+ t.Fatalf("expected app-container workload for metrics-sidecar, got %q", got)
+ }
+ if got := typesByName["Nextcloud"]; got != ResourceTypeAppContainer {
+ t.Fatalf("expected app-container workload for Nextcloud, got %q", got)
+ }
+}
diff --git a/internal/unifiedresources/views_test.go b/internal/unifiedresources/views_test.go
index c4e640db2f..aa73acb696 100644
--- a/internal/unifiedresources/views_test.go
+++ b/internal/unifiedresources/views_test.go
@@ -1452,6 +1452,24 @@ func TestView_RegistryCachedAccessors(t *testing.T) {
rr := NewRegistry(nil)
rr.IngestSnapshot(snapshot)
+ rr.IngestRecords(SourceTrueNAS, []IngestRecord{
+ {
+ SourceID: "app:nextcloud",
+ ParentSourceID: "system:truenas-main",
+ Resource: Resource{
+ Type: ResourceTypeAppContainer,
+ Name: "aa-app",
+ Status: StatusOnline,
+ LastSeen: now,
+ UpdatedAt: now,
+ Docker: &DockerData{
+ ContainerID: "nextcloud",
+ Runtime: "docker",
+ Image: "docker.io/library/nextcloud:29.0.7",
+ },
+ },
+ },
+ })
// Access all typed, cached getters and validate counts and deterministic sort by name.
vms := rr.VMs()
@@ -1558,18 +1576,19 @@ func TestView_RegistryCachedAccessors(t *testing.T) {
}
workloads := rr.Workloads()
- if len(workloads) != 4 {
- t.Fatalf("expected 4 workloads (VMs + LXCs), got %d", len(workloads))
+ if len(workloads) != 6 {
+ t.Fatalf("expected 6 workloads (VMs + LXCs + app containers), got %d", len(workloads))
}
- if workloads[0].Name() != "a-ct" || workloads[1].Name() != "a-vm" || workloads[2].Name() != "b-ct" || workloads[3].Name() != "b-vm" {
- t.Fatalf("expected workloads sorted by name across VM+LXC, got: [%q %q %q %q]", workloads[0].Name(), workloads[1].Name(), workloads[2].Name(), workloads[3].Name())
+ if workloads[0].Name() != "a-ct" || workloads[1].Name() != "a-vm" || workloads[2].Name() != "aa-app" || workloads[3].Name() != "b-ct" || workloads[4].Name() != "b-vm" || workloads[5].Name() != "ignored-docker-container" {
+ t.Fatalf("expected workloads sorted by name across canonical workload types, got: [%q %q %q %q %q %q]",
+ workloads[0].Name(), workloads[1].Name(), workloads[2].Name(), workloads[3].Name(), workloads[4].Name(), workloads[5].Name())
}
for _, w := range workloads {
if w == nil || w.r == nil {
t.Fatalf("expected workload view to be non-nil")
}
- if w.r.Type != ResourceTypeVM && w.r.Type != ResourceTypeSystemContainer {
- t.Fatalf("expected workload type vm or lxc, got %q", w.r.Type)
+ if w.r.Type != ResourceTypeVM && w.r.Type != ResourceTypeSystemContainer && w.r.Type != ResourceTypeAppContainer {
+ t.Fatalf("expected canonical workload type, got %q", w.r.Type)
}
}
@@ -1641,6 +1660,24 @@ func TestView_ReadStateInterfaceUsage(t *testing.T) {
})
var rs ReadState = rr
+ rr.IngestRecords(SourceTrueNAS, []IngestRecord{
+ {
+ SourceID: "app:minio",
+ ParentSourceID: "system:truenas-main",
+ Resource: Resource{
+ Type: ResourceTypeAppContainer,
+ Name: "iface-app",
+ Status: StatusOnline,
+ LastSeen: now,
+ UpdatedAt: now,
+ Docker: &DockerData{
+ ContainerID: "minio",
+ Runtime: "docker",
+ Image: "quay.io/minio/minio:latest",
+ },
+ },
+ },
+ })
if got := rs.VMs(); len(got) != 1 || got[0].Name() != "iface-vm" {
t.Fatalf("expected 1 VM via ReadState, got %d", len(got))
@@ -1672,8 +1709,8 @@ func TestView_ReadStateInterfaceUsage(t *testing.T) {
if got := rs.K8sClusters(); len(got) != 1 || got[0].Name() != "iface-k8s" {
t.Fatalf("expected 1 k8s cluster via ReadState, got %d", len(got))
}
- if got := rs.Workloads(); len(got) != 2 {
- t.Fatalf("expected 2 workloads (vm + lxc) via ReadState, got %d", len(got))
+ if got := rs.Workloads(); len(got) != 3 {
+ t.Fatalf("expected 3 workloads (vm + lxc + app container) via ReadState, got %d", len(got))
}
if got := rs.Infrastructure(); len(got) != 3 {
t.Fatalf("expected 3 infrastructure resources (node + host + docker) via ReadState, got %d", len(got))