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.

Read CORE pool capacity from top-level vdev stats

rcourtmanf38a369bf00e
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index a0d0c16dcf..5cc1ad375a 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -5755,12 +5755,26 @@ or background refreshes during JSON decoding.
### TrueNAS pool capacity is an observation, not a default zero
`internal/truenas/pool_capacity.go` owns validation of the existing pool-specific
-byte sources. Legacy REST consumes only its flat `size`, `allocated`, and
+byte sources. Legacy REST consumes its flat `size`, `allocated`, and
optional `free` fields. RPC retains its existing pool-state/property envelope;
the property envelope is also used by the separate boot-pool reader. Neither
that boot source nor a hypothetical nested REST shape establishes a supported
CORE data-pool capacity fallback. Missing native capacity remains unavailable;
-datasets, quotas, physical disks, and vdevs must not be summed to invent it.
+datasets, quotas, physical disks, and leaf vdevs must not be summed to invent it.
+
+The one supported CORE data-pool source is the pool's own vdev space accounting
+(#2510). CORE 13 `pool.query` (REST `GET /pool`) returns neither flat bytes nor
+zpool properties; its `pool_extend` attaches the libzfs vdev groups, and
+py-libzfs gives every vdev a `stats` object whose `size`/`allocated` are
+`vs_space`/`vs_alloc`. OpenZFS maintains those on top-level vdevs only, and
+zpool's own `size`/`allocated` properties are the sum of the normal, special
+and dedup classes. Pool capacity therefore falls back, last after flat fields
+and properties, to the sum of the top-level `data`, `special` and `dedup` vdev
+stats. Log, cache and spare vdevs and leaf children are never counted. Any
+counted top-level vdev without exact valid stats, an empty data group, an
+overflowing sum, or allocated above size leaves the pool unavailable rather
+than reporting a partial total, and an explicitly null flat field never
+triggers the fallback. REST topology is decoded number-preserving.
A usable reading requires exact non-negative integer total and allocated bytes,
with a positive total and allocated no greater than total. Optional free bytes
@@ -5784,6 +5798,10 @@ remain intact, and a later valid poll resumes at that poll's observation time.
`internal/truenas/pool_capacity_test.go` covers the TLS legacy snapshot through
provider/registry ingestion, real empty/full pools, absent/malformed fields,
exact RPC bytes, source separation and incomplete/overflowing aggregates.
+`internal/truenas/core_pool_capacity_test.go` drives a CORE 13 `pool_extend`
+row (mirror, special, log, cache and spare vdevs) and the CORE boot state
+through the legacy client, snapshot, provider and registry, plus the
+fail-closed topology cases.
`internal/monitoring/truenas_pool_capacity_test.go` connects TLS collection,
provider refresh, two same-named connection-scoped estates, canonical ingestion,
memory and persistent History over known/unknown/malformed/recovered polls.
diff --git a/internal/truenas/client.go b/internal/truenas/client.go
index 38817f03db..561d59d3fe 100644
--- a/internal/truenas/client.go
+++ b/internal/truenas/client.go
@@ -619,7 +619,7 @@ func parsePoolState(item map[string]any, isBoot bool) (Pool, bool) {
}
vdevs, diskMembers := poolTopologyFromTopology(topology)
readErrors, writeErrors, checksumErrors := poolErrorTotals(topology)
- total, used, free := poolCapacity(item, properties)
+ total, used, free := poolCapacity(item, properties, topology)
pool := Pool{
ID: id,
@@ -951,12 +951,7 @@ func (c *Client) getPoolsREST(ctx context.Context) ([]Pool, error) {
if id == "0" && strings.TrimSpace(item.Name) != "" {
id = strings.TrimSpace(item.Name)
}
- var topology any
- if len(item.Topology) > 0 {
- if err := json.Unmarshal(item.Topology, &topology); err != nil {
- topology = nil
- }
- }
+ topology := decodePoolTopology(item.Topology)
var scan any
if len(item.Scan) > 0 {
if err := json.Unmarshal(item.Scan, &scan); err != nil {
@@ -965,7 +960,7 @@ func (c *Client) getPoolsREST(ctx context.Context) ([]Pool, error) {
}
vdevs, diskMembers := poolTopologyFromTopology(topology)
readErrors, writeErrors, checksumErrors := poolErrorTotals(topology)
- total, used, free := poolRESTCapacity(item)
+ total, used, free := poolRESTCapacity(item, topology)
pools = append(pools, Pool{
ID: id,
diff --git a/internal/truenas/core_pool_capacity_test.go b/internal/truenas/core_pool_capacity_test.go
new file mode 100644
index 0000000000..88da088288
--- /dev/null
+++ b/internal/truenas/core_pool_capacity_test.go
@@ -0,0 +1,204 @@
+package truenas
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
+)
+
+// CORE 13 pool.query (REST GET /pool) carries no flat size/allocated/free and
+// no zpool properties. Its only pool-capacity source is the libzfs vdev
+// topology that pool_extend attaches: py-libzfs ZFSVdev.__getstate__ gives
+// every vdev a "stats" object whose size/allocated are vdev_stat_t
+// vs_space/vs_alloc. OpenZFS maintains those only on top-level vdevs
+// (vdev_space_update), and zpool's own size/allocated properties sum the
+// normal, special and dedup classes (spa_prop_get_config). Separate log, cache
+// and spare vdevs are not pool capacity. Leaf children of a mirror/raidz
+// report zero space. See truenas/middleware truenas/13.0-stable
+// plugins/pool.py pool_extend and truenas/py-libzfs truenas/13.0-stable
+// libzfs.pyx ZFSVdevStats (#2510).
+
+const (
+ coreMirrorSize = int64(3985729650688)
+ coreMirrorAllocated = int64(127817449472)
+ coreSpecialSize = int64(495926132736)
+ coreSpecialAlloc = int64(2147483648)
+)
+
+func coreVdevStats(size, allocated int64) string {
+ return fmt.Sprintf(`{"timestamp":1760650000000000,"read_errors":0,"write_errors":0,"checksum_errors":0,"ops":[0,120,340,0,0,9,0],"bytes":[0,4096,8192,0,0,1024,0],"size":%d,"allocated":%d,"fragmentation":3,"self_healed":0,"configured_ashift":12,"logical_ashift":9,"physical_ashift":12}`, size, allocated)
+}
+
+func coreLeaf(name, gptid, guid string) string {
+ return fmt.Sprintf(`{"type":"DISK","path":"/dev/gptid/%s","guid":"%s","status":"ONLINE","stats":%s,"children":[],"device":"%sp2","disk":"%s","unavail_disk":null}`, gptid, guid, coreVdevStats(0, 0), name, name)
+}
+
+// corePoolRow mirrors a CORE 13.0-U6 pool_extend row: datastore columns,
+// zpool status/scan/healthy, transformed topology, autotrim, encryption.
+func corePoolRow(topology string) string {
+ return `{"id":1,"name":"Intenso","guid":"4421337198572811350","encrypt":0,"encryptkey":"","path":"/mnt/Intenso","status":"ONLINE","scan":{"function":"SCRUB","state":"FINISHED","start_time":{"$date":1760140800000},"end_time":{"$date":1760144400000},"percentage":100.0,"bytes_to_process":127817449472,"bytes_processed":127817449472,"bytes_issued":127817449472,"pause":null,"errors":0,"total_secs_left":null},"topology":` + topology + `,"healthy":true,"status_detail":null,"autotrim":{"value":"off","rawvalue":"off","parsed":"off","source":"DEFAULT"},"is_decrypted":true,"encryptkey_path":null}`
+}
+
+func coreTopology(dataStats, specialStats string) string {
+ mirror := `{"type":"MIRROR","path":null,"guid":"9182736455463728190","status":"ONLINE","stats":` + dataStats + `,"children":[` +
+ coreLeaf("da1", "3f1c0e3a-aa11-11ee-9c1d-0cc47a1b2c3d", "1111") + `,` +
+ coreLeaf("da2", "3f2d1f4b-aa11-11ee-9c1d-0cc47a1b2c3d", "2222") + `],"unavail_disk":null}`
+ special := `[]`
+ if specialStats != "" {
+ special = `[{"type":"DISK","path":"/dev/gptid/5a6b7c8d-aa11-11ee-9c1d-0cc47a1b2c3d","guid":"3333","status":"ONLINE","stats":` + specialStats + `,"children":[],"device":"nvd0p1","disk":"nvd0","unavail_disk":null}]`
+ }
+ // The log, cache and spare vdevs carry their own non-zero space and must
+ // not enter pool capacity.
+ log := `[{"type":"DISK","path":"/dev/gptid/6b7c8d9e-aa11-11ee-9c1d-0cc47a1b2c3d","guid":"4444","status":"ONLINE","stats":` + coreVdevStats(15032385536, 1048576) + `,"children":[],"device":"nvd1p1","disk":"nvd1","unavail_disk":null}]`
+ cache := `[{"type":"DISK","path":"/dev/gptid/7c8d9e0f-aa11-11ee-9c1d-0cc47a1b2c3d","guid":"5555","status":"ONLINE","stats":` + coreVdevStats(250059350016, 0) + `,"children":[],"device":"nvd2p1","disk":"nvd2","unavail_disk":null}]`
+ spare := `[{"type":"DISK","path":"/dev/gptid/8d9e0f1a-aa11-11ee-9c1d-0cc47a1b2c3d","guid":"6666","status":"AVAIL","stats":` + coreVdevStats(0, 0) + `,"children":[],"device":"da3p2","disk":"da3","unavail_disk":null}]`
+ return `{"data":[` + mirror + `],"log":` + log + `,"cache":` + cache + `,"spare":` + spare + `,"special":` + special + `,"dedup":[]}`
+}
+
+// boot.get_state on CORE is zfs.pool.query: capacity lives in properties.
+const coreBootState = `{"name":"boot-pool","id":"boot-pool","guid":"7766554433221100","hostname":"core","status":"ONLINE","healthy":true,"warning":false,"status_detail":null,"error_count":0,"properties":{"size":{"value":"15.5G","rawvalue":"16642998272","parsed":16642998272,"source":"NONE"},"allocated":{"value":"2.31G","rawvalue":"2480377856","parsed":2480377856,"source":"NONE"},"free":{"value":"13.2G","rawvalue":"14162620416","parsed":14162620416,"source":"NONE"}},"groups":{"data":[{"type":"disk","path":"/dev/da0p2","guid":"7777","status":"ONLINE","stats":{"size":16642998272,"allocated":2480377856},"children":[]}],"log":[],"cache":[],"spare":[],"special":[],"dedup":[]},"scan":null}`
+
+func coreCapacityServer(t *testing.T, poolBody string) *httptest.Server {
+ t.Helper()
+ responses := defaultAPIResponses()
+ responses["/api/v2.0/system/info"] = apiResponse{body: `{"hostname":"core","version":"TrueNAS-13.0-U6.8","cores":4,"physmem":4096}`}
+ responses["/api/v2.0/pool"] = apiResponse{body: poolBody}
+ responses["/api/v2.0/boot/get_state"] = apiResponse{body: coreBootState}
+ responses["/api/v2.0/pool/dataset"] = apiResponse{body: `[{"id":"Intenso","name":"Intenso","pool":"Intenso","used":{"rawvalue":"119000000000","parsed":119000000000},"available":{"rawvalue":"2780000000000","parsed":2780000000000},"mountpoint":"/mnt/Intenso","readonly":{"rawvalue":"off","parsed":false}}]`}
+ responses["/api/v2.0/disk"] = apiResponse{body: `[{"identifier":"{serial}DA1","name":"da1","serial":"DA1","size":4000787030016,"model":"QEMU HARDDISK","type":"HDD","pool":"Intenso","bus":"SCSI","rotationrate":"unknown","status":"ONLINE"},{"identifier":"{serial}DA2","name":"da2","serial":"DA2","size":4000787030016,"model":"QEMU HARDDISK","type":"HDD","pool":"Intenso","bus":"SCSI","rotationrate":"unknown","status":"ONLINE"}]`}
+ server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path == "/api/current" {
+ http.NotFound(w, r)
+ return
+ }
+ response, ok := responses[r.URL.Path]
+ if !ok {
+ http.NotFound(w, r)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(response.body))
+ }))
+ t.Cleanup(server.Close)
+ return server
+}
+
+func TestTrueNASCOREPoolCapacityFromTopologyStats(t *testing.T) {
+ enableTrueNASFeatureFlag(t)
+ wantTotal := coreMirrorSize + coreSpecialSize
+ wantUsed := coreMirrorAllocated + coreSpecialAlloc
+ server := coreCapacityServer(t, `[`+corePoolRow(coreTopology(coreVdevStats(coreMirrorSize, coreMirrorAllocated), coreVdevStats(coreSpecialSize, coreSpecialAlloc)))+`]`)
+ client := protocolFixtureClient(t, server.URL, ClientConfig{APIKey: "synthetic-key"})
+
+ snapshot, err := client.FetchSnapshot(context.Background())
+ if err != nil {
+ t.Fatalf("FetchSnapshot: %v", err)
+ }
+ var data, boot *Pool
+ for i := range snapshot.Pools {
+ switch snapshot.Pools[i].Name {
+ case "Intenso":
+ data = &snapshot.Pools[i]
+ case "boot-pool":
+ boot = &snapshot.Pools[i]
+ }
+ }
+ if data == nil || boot == nil || len(snapshot.Pools) != 2 {
+ t.Fatalf("pools = %+v", snapshot.Pools)
+ }
+ if data.TotalBytes != wantTotal || data.UsedBytes != wantUsed || data.FreeBytes != wantTotal-wantUsed {
+ t.Fatalf("CORE data-pool capacity = %d/%d/%d, want %d/%d/%d", data.TotalBytes, data.UsedBytes, data.FreeBytes, wantTotal, wantUsed, wantTotal-wantUsed)
+ }
+ if data.GUID != "4421337198572811350" || data.Status != "ONLINE" || data.Scan == nil || data.Scan.Function != "SCRUB" {
+ t.Fatalf("capacity source lost pool identity/health/scan: %+v", data)
+ }
+ if len(data.DiskMembers) != 6 || len(data.VDevs) != 7 {
+ t.Fatalf("capacity source lost topology: members=%d vdevs=%d", len(data.DiskMembers), len(data.VDevs))
+ }
+ if !boot.IsBoot || boot.TotalBytes != 16642998272 || boot.UsedBytes != 2480377856 {
+ t.Fatalf("boot-pool capacity changed: %+v", boot)
+ }
+
+ registry := unifiedresources.NewRegistry(unifiedresources.NewMemoryStore())
+ registry.IngestRecords(unifiedresources.SourceTrueNAS, NewProvider(*snapshot).Records())
+ foundPool, foundHost := false, false
+ for _, resource := range registry.List() {
+ if resource.Type == unifiedresources.ResourceTypeAgent {
+ foundHost = true
+ metric := resource.Metrics.Disk
+ if metric == nil || metric.Total == nil || *metric.Total != wantTotal+16642998272 {
+ t.Fatalf("host storage subtotal = %+v", metric)
+ }
+ }
+ if resource.Storage == nil || resource.Storage.Type != "zfs-pool" || resource.Name != "Intenso" {
+ continue
+ }
+ foundPool = true
+ metric := resource.Metrics.Disk
+ if metric == nil || metric.Total == nil || *metric.Total != wantTotal || metric.Used == nil || *metric.Used != wantUsed {
+ t.Fatalf("CORE pool capacity lost at ingestion: %+v", metric)
+ }
+ }
+ if !foundPool || !foundHost {
+ t.Fatal("snapshot/provider/registry path lost the CORE pool or host")
+ }
+}
+
+func TestTrueNASCOREPoolTopologyCapacityFailsClosed(t *testing.T) {
+ enableTrueNASFeatureFlag(t)
+ good := coreVdevStats(coreMirrorSize, coreMirrorAllocated)
+ const huge = int64(9007199254740993) // Above float64's exact integer range.
+ for _, tc := range []struct {
+ name string
+ row string
+ total int64
+ used int64
+ }{
+ {"data only", corePoolRow(coreTopology(good, "")), coreMirrorSize, coreMirrorAllocated},
+ {"exact bytes above 2^53", corePoolRow(coreTopology(coreVdevStats(huge, 1), "")), huge, 1},
+ {"flat bytes win over topology", strings.Replace(corePoolRow(coreTopology(good, "")), `"id":1,`, `"id":1,"size":1000,"allocated":400,"free":600,`, 1), 1000, 400},
+ {"null flat bytes stay unknown", strings.Replace(corePoolRow(coreTopology(good, "")), `"id":1,`, `"id":1,"size":null,"allocated":null,"free":null,`, 1), 0, 0},
+ {"top-level vdev without stats", corePoolRow(coreTopology(`null`, "")), 0, 0},
+ {"one counted vdev without stats", corePoolRow(coreTopology(good, `{"read_errors":0}`)), 0, 0},
+ {"unknown size", corePoolRow(coreTopology(`{"size":"unknown","allocated":1}`, "")), 0, 0},
+ {"fractional size", corePoolRow(coreTopology(`{"size":1000.5,"allocated":1}`, "")), 0, 0},
+ {"allocated above size", corePoolRow(coreTopology(coreVdevStats(1000, 1001), "")), 0, 0},
+ {"zero size", corePoolRow(coreTopology(coreVdevStats(0, 0), "")), 0, 0},
+ {"overflowing sum", corePoolRow(coreTopology(coreVdevStats(9223372036854775000, 0), coreVdevStats(9223372036854775000, 0))), 0, 0},
+ {"offline pool without topology", strings.Replace(corePoolRow(`null`), `"status":"ONLINE"`, `"status":"OFFLINE"`, 1), 0, 0},
+ {"log and cache alone are not a pool", corePoolRow(`{"data":[],"log":[{"type":"DISK","stats":` + good + `}],"cache":[{"type":"DISK","stats":` + good + `}]}`), 0, 0},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ server := coreCapacityServer(t, `[`+tc.row+`]`)
+ client := protocolFixtureClient(t, server.URL, ClientConfig{APIKey: "synthetic-key"})
+ pools, err := client.GetPools(context.Background())
+ if err != nil || len(pools) != 1 {
+ t.Fatalf("GetPools = %+v, %v", pools, err)
+ }
+ pool := pools[0]
+ if pool.TotalBytes != tc.total || pool.UsedBytes != tc.used || pool.FreeBytes != tc.total-tc.used {
+ t.Fatalf("capacity = %d/%d/%d, want %d/%d/%d", pool.TotalBytes, pool.UsedBytes, pool.FreeBytes, tc.total, tc.used, tc.total-tc.used)
+ }
+ })
+ }
+}
+
+// The zfs.pool.query shape (boot.get_state) keeps reading its properties;
+// topology is consulted only when neither flat bytes nor properties exist.
+func TestTrueNASPoolStateTopologyCapacityIsLastSource(t *testing.T) {
+ groups := map[string]any{"data": []any{map[string]any{"type": "disk", "stats": map[string]any{"size": int64(5000), "allocated": int64(100)}}}}
+ properties := map[string]any{"size": map[string]any{"parsed": int64(2000)}, "allocated": map[string]any{"parsed": int64(900)}}
+ pool, ok := parseBootPoolState(map[string]any{"name": "boot-pool", "groups": groups, "properties": properties})
+ if !ok || pool.TotalBytes != 2000 || pool.UsedBytes != 900 {
+ t.Fatalf("properties lost to topology: %+v", pool)
+ }
+ pool, ok = parsePoolState(map[string]any{"name": "tank", "topology": groups}, false)
+ if !ok || pool.TotalBytes != 5000 || pool.UsedBytes != 100 || pool.FreeBytes != 4900 {
+ t.Fatalf("topology-only pool state = %+v", pool)
+ }
+}
diff --git a/internal/truenas/pool_capacity.go b/internal/truenas/pool_capacity.go
index 6ea9fb6dd3..7d38b1f58d 100644
--- a/internal/truenas/pool_capacity.go
+++ b/internal/truenas/pool_capacity.go
@@ -23,15 +23,33 @@ var poolTotalKeys = []string{"size", "total", "total_bytes", "totalBytes"}
var poolUsedKeys = []string{"allocated", "used", "used_bytes", "usedBytes"}
var poolFreeKeys = []string{"free", "free_bytes", "freeBytes", "available"}
+// poolCapacityTopologyGroups are the top-level vdev classes that zpool's own
+// size/allocated properties count. OpenZFS spa_prop_get_config sums the
+// normal, special, dedup and embedded-log metaslab classes (embedded-log
+// metaslabs live on normal vdevs); separate log, cache and spare vdevs are
+// not pool capacity.
+var poolCapacityTopologyGroups = []string{"data", "special", "dedup"}
+
// poolCapacity accepts a coherent pool-specific reading, not a dataset/disk
// sum. Missing or invalid total/allocated bytes mean unknown usage, not an
// empty pool. Free may be derived from those two pool bytes only when absent;
-// a supplied free reading must agree. Never mix flat and property sources,
-// or replace an explicitly supplied zero/null/invalid field via a fallback.
-func poolCapacity(item, properties map[string]any) (total, used, free int64) {
+// a supplied free reading must agree. Never mix flat, property and topology
+// sources, or replace an explicitly supplied zero/null/invalid field via a
+// fallback.
+//
+// Sources in order: flat pool.query fields (SCALE), zpool properties
+// (zfs.pool.query, which boot.get_state returns), then the top-level vdev
+// stats of the pool topology. CORE 13's pool.query (REST GET /pool) returns
+// neither flat bytes nor properties; its pool_extend only attaches the
+// libzfs vdev groups, whose top-level stats carry vs_space/vs_alloc as
+// size/allocated (#2510).
+func poolCapacity(item, properties map[string]any, topology any) (total, used, free int64) {
source := item
nested := false
if !hasPoolCapacityFields(item) {
+ if !hasPoolCapacityFields(properties) {
+ return poolTopologyCapacity(topology)
+ }
source = properties
nested = true
}
@@ -107,7 +125,69 @@ func poolByteValue(value any) (int64, bool) {
return parsed, parsed >= 0
}
-func poolRESTCapacity(item poolResponse) (int64, int64, int64) {
+// poolTopologyCapacity sums the size/allocated stats of the top-level data,
+// special and dedup vdevs, which equals zpool's size/allocated properties.
+// Leaf vdevs carry no space accounting and are never read. Every counted
+// top-level vdev must supply both readings: a partial sum would understate
+// the pool, so it is reported as unknown instead.
+func poolTopologyCapacity(topology any) (int64, int64, int64) {
+ groups, ok := topology.(map[string]any)
+ if !ok {
+ return 0, 0, 0
+ }
+ if data, ok := groups["data"].([]any); !ok || len(data) == 0 {
+ return 0, 0, 0
+ }
+ var total, used int64
+ for _, groupName := range poolCapacityTopologyGroups {
+ raw, present := groups[groupName]
+ if !present || raw == nil {
+ continue
+ }
+ nodes, ok := raw.([]any)
+ if !ok {
+ return 0, 0, 0
+ }
+ for _, node := range nodes {
+ vdev, ok := node.(map[string]any)
+ if !ok {
+ return 0, 0, 0
+ }
+ stats, ok := vdev["stats"].(map[string]any)
+ if !ok {
+ return 0, 0, 0
+ }
+ size, sizeOK, _ := poolByteField(stats, []string{"size"}, false)
+ allocated, allocatedOK, _ := poolByteField(stats, []string{"allocated"}, false)
+ if !sizeOK || !allocatedOK || total > math.MaxInt64-size || used > math.MaxInt64-allocated {
+ return 0, 0, 0
+ }
+ total += size
+ used += allocated
+ }
+ }
+ if total <= 0 || used > total {
+ return 0, 0, 0
+ }
+ return total, used, total - used
+}
+
+// decodePoolTopology keeps native integer bytes exact; an intermediate
+// float64 cannot represent every vdev size above 2^53.
+func decodePoolTopology(raw json.RawMessage) any {
+ if len(raw) == 0 {
+ return nil
+ }
+ var topology any
+ decoder := json.NewDecoder(bytes.NewReader(raw))
+ decoder.UseNumber()
+ if err := decoder.Decode(&topology); err != nil {
+ return nil
+ }
+ return topology
+}
+
+func poolRESTCapacity(item poolResponse, topology any) (int64, int64, int64) {
fields := make(map[string]any, 3)
for key, raw := range map[string]json.RawMessage{"size": item.Size, "allocated": item.Allocated, "free": item.Free} {
if len(raw) == 0 {
@@ -123,5 +203,5 @@ func poolRESTCapacity(item poolResponse) (int64, int64, int64) {
}
fields[key] = value
}
- return poolCapacity(fields, nil)
+ return poolCapacity(fields, nil, topology)
}
diff --git a/internal/truenas/pool_capacity_test.go b/internal/truenas/pool_capacity_test.go
index ed82548faf..dda192f56c 100644
--- a/internal/truenas/pool_capacity_test.go
+++ b/internal/truenas/pool_capacity_test.go
@@ -13,8 +13,9 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
)
-// These are declared protocol controls, not an alternative native CORE
-// capacity source. #2510's absent pool bytes must still remain unavailable.
+// These are declared flat-field protocol controls. The native CORE source,
+// top-level vdev stats, is covered in core_pool_capacity_test.go; a pool with
+// neither flat bytes nor vdev stats must still remain unavailable.
func TestTrueNASPoolCapacitySnapshot(t *testing.T) {
enableTrueNASFeatureFlag(t)
for _, tc := range []struct {