From d63e371e574dd429d4704dd97b453dcea8676315 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Thu, 26 Jan 2023 15:56:37 -0500 Subject: [PATCH 1/2] ui: fix alloc memory stats to match CLI output --- .../utils/classes/allocation-stats-tracker.js | 23 +++++++++---------- .../utils/allocation-stats-tracker-test.js | 8 +++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ui/app/utils/classes/allocation-stats-tracker.js b/ui/app/utils/classes/allocation-stats-tracker.js index 869eed0009a1..c8f28f3ac36b 100644 --- a/ui/app/utils/classes/allocation-stats-tracker.js +++ b/ui/app/utils/classes/allocation-stats-tracker.js @@ -29,6 +29,13 @@ const sortMap = [ const taskPrioritySort = (a, b) => sortMap[a.lifecycleName] - sortMap[b.lifecycleName]; +// Select the value for memory usage. +// Must match logic in command/alloc_status.go. +const memoryUsed = (frame) => + frame.ResourceUsage.MemoryStats.RSS || + frame.ResourceUsage.MemoryStats.Usage || + 0; + @classic class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) { // Set via the stats computed property macro @@ -49,15 +56,11 @@ class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) { percent: percent(cpuUsed, this.reservedCPU), }); - const memoryUsed = - frame.ResourceUsage.MemoryStats.Usage || - frame.ResourceUsage.MemoryStats.RSS || - 0; - + const memUsed = memoryUsed(frame); this.memory.pushObject({ timestamp, - used: memoryUsed, - percent: percent(memoryUsed / 1024 / 1024, this.reservedMemory), + used: memUsed, + percent: percent(memUsed / 1024 / 1024, this.reservedMemory), }); let aggregateCpu = 0; @@ -84,11 +87,7 @@ class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) { percentStack: percentCpuTotal + aggregateCpu, }); - const taskMemoryUsed = - taskFrame.ResourceUsage.MemoryStats.Usage || - taskFrame.ResourceUsage.MemoryStats.RSS || - 0; - + const taskMemoryUsed = memoryUsed(taskFrame); const percentMemoryTotal = percent( taskMemoryUsed / 1024 / 1024, this.reservedMemory diff --git a/ui/tests/unit/utils/allocation-stats-tracker-test.js b/ui/tests/unit/utils/allocation-stats-tracker-test.js index e4f373108154..02cd7c10fa12 100644 --- a/ui/tests/unit/utils/allocation-stats-tracker-test.js +++ b/ui/tests/unit/utils/allocation-stats-tracker-test.js @@ -54,7 +54,7 @@ module('Unit | Util | AllocationStatsTracker', function () { }, MemoryStats: { RSS: (step + 400) * 1024 * 1024, - Usage: (step + 400) * 1024 * 1024, + Usage: (step + 800) * 1024 * 1024, }, }, Tasks: { @@ -65,7 +65,7 @@ module('Unit | Util | AllocationStatsTracker', function () { }, MemoryStats: { RSS: (step + 100) * 1024 * 1024, - Usage: (step + 100) * 1024 * 1024, + Usage: (step + 200) * 1024 * 1024, }, }, Timestamp: refDate + step, @@ -77,7 +77,7 @@ module('Unit | Util | AllocationStatsTracker', function () { }, MemoryStats: { RSS: (step + 50) * 1024 * 1024, - Usage: (step + 50) * 1024 * 1024, + Usage: (step + 100) * 1024 * 1024, }, }, Timestamp: refDate + step * 10, @@ -89,7 +89,7 @@ module('Unit | Util | AllocationStatsTracker', function () { }, MemoryStats: { RSS: (step + 51) * 1024 * 1024, - Usage: (step + 51) * 1024 * 1024, + Usage: (step + 101) * 1024 * 1024, }, }, Timestamp: refDate + step * 100, From 02e53902f0e319be976d48231b99c92292e71291 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Thu, 26 Jan 2023 15:59:59 -0500 Subject: [PATCH 2/2] changelog: add entry for #15909 --- .changelog/15909.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/15909.txt diff --git a/.changelog/15909.txt b/.changelog/15909.txt new file mode 100644 index 000000000000..f0aef43dcf29 --- /dev/null +++ b/.changelog/15909.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fix allocation memory chart to display the same value as the CLI +```