mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
client: Fix memory fingerprinting on 32bit
Also introduce regression ci for 32 bit fingerprinting
This commit is contained in:
@@ -54,6 +54,11 @@ workflows:
|
||||
name: "test-shared-exec"
|
||||
test_packages: "./drivers/shared/executor"
|
||||
<<: *IGNORE_FOR_UI_BRANCHES
|
||||
- test-container:
|
||||
name: "test-32bit-fingerprinting"
|
||||
test_packages: "./client/fingerprint"
|
||||
goarch: "386"
|
||||
<<: *IGNORE_FOR_UI_BRANCHES
|
||||
- test-rkt:
|
||||
<<: *IGNORE_FOR_UI_BRANCHES
|
||||
- test-e2e:
|
||||
@@ -118,11 +123,15 @@ jobs:
|
||||
exclude_packages:
|
||||
type: string
|
||||
default: ""
|
||||
goarch:
|
||||
type: string
|
||||
default: "amd64"
|
||||
environment:
|
||||
<<: *COMMON_ENVS
|
||||
GOTEST_PKGS: "<< parameters.test_packages >>"
|
||||
GOTEST_PKGS_EXCLUDE: "<< parameters.exclude_packages >>"
|
||||
GOPATH: /go
|
||||
GOARCH: "<< parameters.goarch >>"
|
||||
steps:
|
||||
- checkout
|
||||
- run: make deps
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
const bytesInMB = 1024 * 1024
|
||||
const bytesInMB int64 = 1024 * 1024
|
||||
|
||||
// MemoryFingerprint is used to fingerprint the available memory on the node
|
||||
type MemoryFingerprint struct {
|
||||
@@ -25,10 +25,10 @@ func NewMemoryFingerprint(logger log.Logger) Fingerprint {
|
||||
}
|
||||
|
||||
func (f *MemoryFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
|
||||
var totalMemory int
|
||||
var totalMemory int64
|
||||
cfg := req.Config
|
||||
if cfg.MemoryMB != 0 {
|
||||
totalMemory = cfg.MemoryMB * bytesInMB
|
||||
totalMemory = int64(cfg.MemoryMB) * bytesInMB
|
||||
} else {
|
||||
memInfo, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
@@ -36,21 +36,16 @@ func (f *MemoryFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerpri
|
||||
return err
|
||||
}
|
||||
if memInfo.Total > 0 {
|
||||
totalMemory = int(memInfo.Total)
|
||||
totalMemory = int64(memInfo.Total)
|
||||
}
|
||||
}
|
||||
|
||||
if totalMemory > 0 {
|
||||
resp.AddAttribute("memory.totalbytes", fmt.Sprintf("%d", totalMemory))
|
||||
|
||||
// COMPAT(0.10): Remove in 0.10
|
||||
resp.Resources = &structs.Resources{
|
||||
MemoryMB: totalMemory / bytesInMB,
|
||||
}
|
||||
|
||||
resp.NodeResources = &structs.NodeResources{
|
||||
Memory: structs.NodeMemoryResources{
|
||||
MemoryMB: int64(totalMemory / bytesInMB),
|
||||
MemoryMB: totalMemory / bytesInMB,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
)
|
||||
|
||||
func TestMemoryFingerprint(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
f := NewMemoryFingerprint(testlog.HCLogger(t))
|
||||
node := &structs.Node{
|
||||
Attributes: make(map[string]string),
|
||||
@@ -19,24 +21,11 @@ func TestMemoryFingerprint(t *testing.T) {
|
||||
request := &FingerprintRequest{Config: &config.Config{}, Node: node}
|
||||
var response FingerprintResponse
|
||||
err := f.Fingerprint(request, &response)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
|
||||
|
||||
if response.Resources == nil {
|
||||
t.Fatalf("response resources should not be nil")
|
||||
}
|
||||
|
||||
// COMPAT(0.10): Remove in 0.10
|
||||
if response.Resources.MemoryMB == 0 {
|
||||
t.Fatalf("Expected node.Resources.MemoryMB to be non-zero")
|
||||
}
|
||||
|
||||
if response.NodeResources.Memory.MemoryMB == 0 {
|
||||
t.Fatalf("Expected node.Resources.MemoryMB to be non-zero")
|
||||
}
|
||||
require.NotNil(response.NodeResources, "expected response NodeResources to not be nil")
|
||||
require.NotZero(response.NodeResources.Memory.MemoryMB, "expected memory to be non-zero")
|
||||
}
|
||||
|
||||
func TestMemoryFingerprint_Override(t *testing.T) {
|
||||
@@ -55,7 +44,6 @@ func TestMemoryFingerprint_Override(t *testing.T) {
|
||||
|
||||
assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
|
||||
require := require.New(t)
|
||||
require.NotNil(response.Resources)
|
||||
require.Equal(response.Resources.MemoryMB, memoryMB)
|
||||
require.NotNil(response.NodeResources)
|
||||
require.EqualValues(response.NodeResources.Memory.MemoryMB, memoryMB)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user