api: add missing AllocDirStats field in Go API (#20261)

The JSON response for the Read Stats client API includes an `AllocDirStats`
field. This field is missing in the `api` package, so consumers of the Go API
can't use it to read the values we're getting back from the HTTP server.

Fixes: https://github.com/hashicorp/nomad/issues/20246
This commit is contained in:
Tim Gross
2024-04-03 08:54:05 -04:00
committed by GitHub
parent 4ce728afbd
commit 78f9f17867
3 changed files with 25 additions and 0 deletions

3
.changelog/20261.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
api: Fixed a bug where `AllocDirStats` field was missing from Read Stats client API
```

View File

@@ -783,6 +783,7 @@ type HostStats struct {
Memory *HostMemoryStats Memory *HostMemoryStats
CPU []*HostCPUStats CPU []*HostCPUStats
DiskStats []*HostDiskStats DiskStats []*HostDiskStats
AllocDirStats *HostDiskStats
DeviceStats []*DeviceGroupStats DeviceStats []*DeviceGroupStats
Uptime uint64 Uptime uint64
CPUTicksConsumed float64 CPUTicksConsumed float64

View File

@@ -153,6 +153,27 @@ func TestNodes_Info(t *testing.T) {
must.GreaterEq(t, 1, len(result.Events)) must.GreaterEq(t, 1, len(result.Events))
} }
func TestNode_Stats(t *testing.T) {
testutil.Parallel(t)
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) {
c.DevMode = true
})
defer s.Stop()
nodesAPI := c.Nodes()
nodeID := oneNodeFromNodeList(t, nodesAPI).ID
stats, err := nodesAPI.Stats(nodeID, nil)
must.NoError(t, err)
// there isn't much we can reliably check here except that the values are
// populated
must.NotNil(t, stats.Memory)
must.NonZero(t, stats.Memory.Available)
must.NotNil(t, stats.AllocDirStats)
must.NonZero(t, stats.AllocDirStats.Size)
}
func TestNodes_NoSecretID(t *testing.T) { func TestNodes_NoSecretID(t *testing.T) {
testutil.Parallel(t) testutil.Parallel(t)