Skip to content

Commit

Permalink
Allow client.cpu_total_compute to override attr.cpu.totalcompute
Browse files Browse the repository at this point in the history
  • Loading branch information
joel0 committed Dec 5, 2020
1 parent d76340f commit 726c08b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/fingerprint/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (f *CPUFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintR
}

if cfg.CpuCompute != 0 {
resp.AddAttribute("cpu.totalcompute", fmt.Sprintf("%d", cfg.CpuCompute))
setResourcesCPU(cfg.CpuCompute)
resp.Detected = true
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions client/fingerprint/cpu_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fingerprint

import (
"strconv"
"testing"

"github.com/hashicorp/nomad/client/config"
Expand Down Expand Up @@ -102,5 +103,8 @@ func TestCPUFingerprint_OverrideCompute(t *testing.T) {
if response.NodeResources.Cpu.CpuShares != int64(cfg.CpuCompute) {
t.Fatalf("expected override cpu of %d but found %d", cfg.CpuCompute, response.NodeResources.Cpu.CpuShares)
}
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"])
}
}
}
2 changes: 2 additions & 0 deletions client/fingerprint/env_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func (f *EnvAWSFingerprint) Fingerprint(request *FingerprintRequest, response *F
nodeResources = new(structs.NodeResources)
}
nodeResources.Cpu = structs.NodeCpuResources{CpuShares: int64(ticks)}
} else {
response.AddAttribute("cpu.totalcompute", fmt.Sprintf("%d", request.Config.CpuCompute))
}
} else {
f.logger.Warn("failed to find the cpu specification for this instance type")
Expand Down
2 changes: 1 addition & 1 deletion client/fingerprint/env_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestCPUFingerprint_AWS_OverrideCompute(t *testing.T) {
require.True(t, response.Detected)
require.Equal(t, "2200", response.Attributes["cpu.frequency"])
require.Equal(t, "8", response.Attributes["cpu.numcores"])
require.NotContains(t, response.Attributes, "cpu.totalcompute")
require.Equal(t, "99999", response.Attributes["cpu.totalcompute"])
require.Nil(t, response.Resources) // defaults in cpu fingerprinter
require.Zero(t, response.NodeResources.Cpu) // defaults in cpu fingerprinter
}
Expand Down

0 comments on commit 726c08b

Please sign in to comment.