diff --git a/.changelog/20543.txt b/.changelog/20543.txt new file mode 100644 index 000000000..f77da2c23 --- /dev/null +++ b/.changelog/20543.txt @@ -0,0 +1,3 @@ +```release-note:bug +client: Fix unallocated CPU metric calculation when client reserved CPU is set +``` diff --git a/client/client.go b/client/client.go index 88df8d7d9..b6d9d4833 100644 --- a/client/client.go +++ b/client/client.go @@ -3252,7 +3252,11 @@ func (c *Client) setGaugeForAllocationStats(nodeID string, baseLabels []metrics. // Emit unallocated unallocatedMem := total.Memory.MemoryMB - res.Memory.MemoryMB - allocated.Flattened.Memory.MemoryMB unallocatedDisk := total.Disk.DiskMB - res.Disk.DiskMB - allocated.Shared.DiskMB - unallocatedCpu := int64(total.Processors.Topology.UsableCompute()) - res.Cpu.CpuShares - allocated.Flattened.Cpu.CpuShares + + // The UsableCompute function call already subtracts and accounts for any + // reserved CPU within the client configuration. Therefore, we do not need + // to subtract that here. + unallocatedCpu := int64(total.Processors.Topology.UsableCompute()) - allocated.Flattened.Cpu.CpuShares metrics.SetGaugeWithLabels([]string{"client", "unallocated", "memory"}, float32(unallocatedMem), baseLabels) metrics.SetGaugeWithLabels([]string{"client", "unallocated", "disk"}, float32(unallocatedDisk), baseLabels)