Skip to content

Commit

Permalink
Backport of ui: fix zero memory utilization bug on systems using cgro…
Browse files Browse the repository at this point in the history
…ups v2 into release/1.3.x (#13990)

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-nomad-core authored Aug 3, 2022
1 parent abf21b8 commit 767d47b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/13670.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fixed a bug where task memory was reported as zero on systems using cgroups v2
```
12 changes: 10 additions & 2 deletions ui/app/utils/classes/allocation-stats-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) {
percent: percent(cpuUsed, this.reservedCPU),
});

const memoryUsed = frame.ResourceUsage.MemoryStats.RSS;
const memoryUsed =
frame.ResourceUsage.MemoryStats.Usage ||
frame.ResourceUsage.MemoryStats.RSS ||
0;

this.memory.pushObject({
timestamp,
used: memoryUsed,
Expand Down Expand Up @@ -80,7 +84,11 @@ class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) {
percentStack: percentCpuTotal + aggregateCpu,
});

const taskMemoryUsed = taskFrame.ResourceUsage.MemoryStats.RSS;
const taskMemoryUsed =
taskFrame.ResourceUsage.MemoryStats.Usage ||
taskFrame.ResourceUsage.MemoryStats.RSS ||
0;

const percentMemoryTotal = percent(
taskMemoryUsed / 1024 / 1024,
this.reservedMemory
Expand Down
5 changes: 4 additions & 1 deletion ui/tests/unit/utils/allocation-stats-tracker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module('Unit | Util | AllocationStatsTracker', function () {
},
MemoryStats: {
RSS: (step + 400) * 1024 * 1024,
Usage: (step + 400) * 1024 * 1024,
},
},
Tasks: {
Expand All @@ -64,6 +65,7 @@ module('Unit | Util | AllocationStatsTracker', function () {
},
MemoryStats: {
RSS: (step + 100) * 1024 * 1024,
Usage: (step + 100) * 1024 * 1024,
},
},
Timestamp: refDate + step,
Expand All @@ -75,6 +77,7 @@ module('Unit | Util | AllocationStatsTracker', function () {
},
MemoryStats: {
RSS: (step + 50) * 1024 * 1024,
Usage: (step + 50) * 1024 * 1024,
},
},
Timestamp: refDate + step * 10,
Expand All @@ -86,6 +89,7 @@ module('Unit | Util | AllocationStatsTracker', function () {
},
MemoryStats: {
RSS: (step + 51) * 1024 * 1024,
Usage: (step + 51) * 1024 * 1024,
},
},
Timestamp: refDate + step * 100,
Expand Down Expand Up @@ -251,7 +255,6 @@ module('Unit | Util | AllocationStatsTracker', function () {
],
'One frame of memory'
);

assert.deepEqual(
tracker.get('tasks'),
[
Expand Down

0 comments on commit 767d47b

Please sign in to comment.