Skip to content

Commit

Permalink
fingerprint: Restore support for legacy memory fingerprint
Browse files Browse the repository at this point in the history
  • Loading branch information
endocrimes committed Sep 4, 2019
1 parent 370d147 commit e9a8e9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/fingerprint/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ func (f *MemoryFingerprint) Fingerprint(req *FingerprintRequest, resp *Fingerpri
if totalMemory > 0 {
resp.AddAttribute("memory.totalbytes", fmt.Sprintf("%d", totalMemory))

memoryMB := totalMemory / bytesInMB

resp.Resources = &structs.Resources{
MemoryMB: int(memoryMB),
}

resp.NodeResources = &structs.NodeResources{
Memory: structs.NodeMemoryResources{
MemoryMB: totalMemory / bytesInMB,
MemoryMB: memoryMB,
},
}
}
Expand Down
4 changes: 4 additions & 0 deletions client/fingerprint/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func TestMemoryFingerprint(t *testing.T) {
require.NoError(err)

assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
require.NotNil(response.Resources, "expected response Resources to not be nil")
require.NotZero(response.Resources.MemoryMB, "expected memory 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")
}
Expand All @@ -44,6 +46,8 @@ func TestMemoryFingerprint_Override(t *testing.T) {

assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
require := require.New(t)
require.NotNil(response.Resources)
require.EqualValues(response.Resources.MemoryMB, memoryMB)
require.NotNil(response.NodeResources)
require.EqualValues(response.NodeResources.Memory.MemoryMB, memoryMB)
}

0 comments on commit e9a8e9e

Please sign in to comment.