From 7e42ad869aefd4bec4c5a5855f07b7757db53293 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Thu, 9 May 2024 11:55:22 +0200 Subject: [PATCH] client: fix unallocated CPU metric when reserved cpu is set. (#20543) --- .changelog/20543.txt | 3 +++ client/client.go | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changelog/20543.txt 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)