Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fingerprint: add node attr for reserverable cores #14694

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/14694.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
fingerprint: Add node attribute for number of reservable cores: `cpu.num_reservable_cores`
```
4 changes: 3 additions & 1 deletion client/fingerprint/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fingerprint

import (
"fmt"
"strconv"

"github.com/hashicorp/nomad/lib/cpuset"

Expand Down Expand Up @@ -62,7 +63,7 @@ func (f *CPUFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintR

var numCores int
if numCores = stats.CPUNumCores(); numCores > 0 {
resp.AddAttribute("cpu.numcores", fmt.Sprintf("%d", numCores))
resp.AddAttribute("cpu.numcores", strconv.Itoa(numCores))
f.logger.Debug("detected core count", "cores", numCores)
}

Expand All @@ -80,6 +81,7 @@ func (f *CPUFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintR
f.logger.Debug("detected reservable cores", "cpuset", reservableCores)
}
}
resp.AddAttribute("cpu.reservablecores", strconv.Itoa(len(reservableCores)))

tt := int(stats.TotalTicksAvailable())
if cfg.CpuCompute > 0 {
Expand Down
12 changes: 11 additions & 1 deletion client/fingerprint/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func TestCPUFingerprint_OverrideCompute(t *testing.T) {
node := &structs.Node{
Attributes: make(map[string]string),
}
cfg := &config.Config{}
cfg := &config.Config{
ReservableCores: []uint16{0, 1, 2},
}
var originalCPU int

{
Expand All @@ -82,6 +84,10 @@ func TestCPUFingerprint_OverrideCompute(t *testing.T) {
t.Fatalf("expected response to be applicable")
}

if attr := response.Attributes["cpu.reservablecores"]; attr != "3" {
t.Fatalf("expected cpu.reservablecores == 3 but found %s", attr)
}

if response.Resources.CPU == 0 {
t.Fatalf("expected fingerprint of cpu of but found 0")
}
Expand Down Expand Up @@ -111,5 +117,9 @@ func TestCPUFingerprint_OverrideCompute(t *testing.T) {
if response.Attributes["cpu.totalcompute"] != strconv.Itoa(cfg.CpuCompute) {
t.Fatalf("expected override cpu.totalcompute of %d but found %s", cfg.CpuCompute, response.Attributes["cpu.totalcompute"])
}

if attr := response.Attributes["cpu.reservablecores"]; attr != "3" {
t.Fatalf("expected cpu.reservablecores == 3 but found %s", attr)
}
}
}
8 changes: 7 additions & 1 deletion website/content/docs/runtime/interpolation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ Below is a table documenting common node properties:
<td>
<code>{'${attr.cpu.numcores}'}</code>
</td>
<td>Number of CPU cores on the client</td>
<td>Number of CPU cores on the client. May differ from how many cores are available for reservation due to OS or configuration. See <code>cpu.reservablecores</code>.</td>
</tr>
<tr>
<td>
<code>{'${attr.cpu.reservablecores}'}</code>
</td>
<td>Number of CPU cores on the client avaible for scheduling. Number of cores used by the scheduler when placing work with <code>resources.cores</code> set.</td>
</tr>
<tr>
<td>
Expand Down