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.

Align TrueNAS apps with native app.query

rcourtmane189733434ad
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 129db76d04..b765d2c29b 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -109,11 +109,13 @@ truth for live infrastructure data.
config paths, bind mounts, ports, or suggested URLs.
16. Add or change TrueNAS supplemental inventory only through the native
TrueNAS provider path and unified-resource projection. TrueNAS apps are
- API-owned application records: the provider may preserve Docker-compatible
- runtime metadata for shared container tooling, but it must also publish the
- native app identity, state, version, update availability, workload
- containers, ports, images, volumes, networks, and stat collection metadata
- through `TrueNASData.App` on the canonical `app-container` resource.
+ API-owned application records: `app.query` is the preferred live inventory
+ source, with legacy REST allowed only as a compatibility fallback. The
+ provider may preserve Docker-compatible runtime metadata for shared
+ container tooling, but it must also publish the native app identity, state,
+ version, update availability, workload containers, ports, images, volumes,
+ networks, and stat collection metadata through `TrueNASData.App` on the
+ canonical `app-container` resource.
Monitoring must not rebuild a second Docker-only TrueNAS app inventory or
make the Docker fallback the source of truth for the TrueNAS platform page.
TrueNAS child source identities are appliance-local and must be scoped under
diff --git a/internal/truenas/client.go b/internal/truenas/client.go
index 77207d48d2..d27e3db62c 100644
--- a/internal/truenas/client.go
+++ b/internal/truenas/client.go
@@ -626,13 +626,38 @@ func (c *Client) queryRPC(ctx context.Context, method string, result any) error
}
// 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.
+// candidates. TrueNAS 25.04+ documents app.query on the JSON-RPC API, with
+// the legacy REST endpoint kept as a compatibility fallback for older
+// deployments and existing tests.
func (c *Client) GetApps(ctx context.Context) ([]App, error) {
+ apps, err := c.getAppsRPC(ctx)
+ if err == nil {
+ return apps, nil
+ }
+ restApps, restErr := c.getAppsREST(ctx)
+ if restErr != nil {
+ return nil, fmt.Errorf("fetch truenas apps via rpc and rest: rpc=%w rest=%v", err, restErr)
+ }
+ return restApps, nil
+}
+
+func (c *Client) getAppsRPC(ctx context.Context) ([]App, error) {
+ var response []map[string]any
+ if err := c.queryRPC(ctx, "app.query", &response); err != nil {
+ return nil, err
+ }
+ return c.parseAppsWithStats(ctx, response), nil
+}
+
+func (c *Client) getAppsREST(ctx context.Context) ([]App, error) {
var response []map[string]any
if err := c.getJSON(ctx, http.MethodGet, "/app", &response); err != nil {
return nil, err
}
+ return c.parseAppsWithStats(ctx, response), nil
+}
+
+func (c *Client) parseAppsWithStats(ctx context.Context, response []map[string]any) []App {
statsByApp, err := c.GetAppStats(ctx)
if err != nil {
statsByApp = nil
@@ -686,7 +711,7 @@ func (c *Client) GetApps(ctx context.Context) ([]App, error) {
apps = append(apps, app)
}
- return apps, nil
+ return apps
}
// GetAppStats retrieves live TrueNAS app workload telemetry from the modern
diff --git a/internal/truenas/client_test.go b/internal/truenas/client_test.go
index dcc3eed97d..b35c4bc678 100644
--- a/internal/truenas/client_test.go
+++ b/internal/truenas/client_test.go
@@ -353,6 +353,55 @@ func TestGetVMsParsesNativeVMQueryShape(t *testing.T) {
}
}
+func TestGetAppsParsesNativeAppQueryShape(t *testing.T) {
+ server := newMockServerWithRPC(t, map[string]apiResponse{
+ "/api/v2.0/app": {status: http.StatusInternalServerError, body: `{"error":"legacy app endpoint should not be used"}`},
+ }, nil, func(t *testing.T, conn *websocket.Conn) {
+ authReq := readRPCRequest(t, conn)
+ if authReq.Method != "auth.login_with_api_key" {
+ t.Fatalf("expected api-key auth method, got %q", authReq.Method)
+ }
+ writeRPCResult(t, conn, authReq.ID, true)
+
+ request := readRPCRequest(t, conn)
+ switch request.Method {
+ case "app.query":
+ params, ok := request.Params.([]any)
+ if !ok || len(params) != 2 {
+ t.Fatalf("expected app.query filters/options params, got %#v", request.Params)
+ }
+ writeRPCResult(t, conn, request.ID, defaultAppQueryPayload(t))
+ case "core.subscribe":
+ writeRPCError(t, conn, request.ID, 1, "stats unavailable")
+ default:
+ t.Fatalf("unexpected rpc method %q", request.Method)
+ }
+ })
+ t.Cleanup(server.Close)
+
+ client := mustClientForServer(t, server.URL, ClientConfig{APIKey: "api-key"})
+ apps, err := client.GetApps(context.Background())
+ if err != nil {
+ t.Fatalf("GetApps() error = %v", err)
+ }
+ if len(apps) != 1 {
+ t.Fatalf("expected 1 app, got %d", len(apps))
+ }
+ app := apps[0]
+ if app.ID != "nextcloud" || app.Name != "Nextcloud" || app.State != "RUNNING" {
+ t.Fatalf("unexpected app identity/status: %+v", app)
+ }
+ if app.ContainerCount != 2 || len(app.Containers) != 2 {
+ t.Fatalf("unexpected app container mapping: %+v", app)
+ }
+ if len(app.UsedPorts) != 1 || len(app.UsedPorts[0].HostPorts) != 1 || app.UsedPorts[0].HostPorts[0].HostPort != 30443 {
+ t.Fatalf("unexpected app port mapping: %+v", app.UsedPorts)
+ }
+ if len(app.Volumes) != 2 || len(app.Images) != 2 || len(app.Networks) != 1 {
+ t.Fatalf("unexpected app runtime shape: volumes=%d images=%d networks=%d", len(app.Volumes), len(app.Images), len(app.Networks))
+ }
+}
+
func TestGetAppsEnrichesStatsFromRPC(t *testing.T) {
server := newMockServerWithRPC(t, defaultAPIResponses(), nil, func(t *testing.T, conn *websocket.Conn) {
authReq := readRPCRequest(t, conn)
@@ -361,11 +410,16 @@ func TestGetAppsEnrichesStatsFromRPC(t *testing.T) {
}
writeRPCResult(t, conn, authReq.ID, true)
- subscribeReq := readRPCRequest(t, conn)
- if subscribeReq.Method != "core.subscribe" {
- t.Fatalf("expected core.subscribe, got %q", subscribeReq.Method)
+ request := readRPCRequest(t, conn)
+ switch request.Method {
+ case "app.query":
+ writeRPCResult(t, conn, request.ID, defaultAppQueryPayload(t))
+ return
+ case "core.subscribe":
+ default:
+ t.Fatalf("expected app.query or core.subscribe, got %q", request.Method)
}
- writeRPCResult(t, conn, subscribeReq.ID, "sub-1")
+ writeRPCResult(t, conn, request.ID, "sub-1")
writeRPCNotification(t, conn, "collection_update", map[string]any{
"collection": "app.stats:{\"interval\":2}",
"fields": []map[string]any{
@@ -1241,6 +1295,16 @@ func TestClientCloseNilSafe(t *testing.T) {
(&Client{httpClient: &http.Client{}}).Close()
}
+func defaultAppQueryPayload(t *testing.T) []map[string]any {
+ t.Helper()
+
+ var payload []map[string]any
+ if err := json.Unmarshal([]byte(defaultAPIResponses()["/api/v2.0/app"].body), &payload); err != nil {
+ t.Fatalf("unmarshal default app fixture: %v", err)
+ }
+ return payload
+}
+
func defaultAPIResponses() map[string]apiResponse {
return map[string]apiResponse{
"/api/v2.0/system/info": {