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

Backport of ui: fix alloc memory stats to match CLI output into release/1.3.x #15913

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/15909.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix allocation memory chart to display the same value as the CLI
```
23 changes: 11 additions & 12 deletions ui/app/utils/classes/allocation-stats-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ui/tests/unit/utils/allocation-stats-tracker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down