From 20b8e39842f4555e5dcaf73a5ef1bdd3609966a5 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 19 Oct 2017 10:43:33 -0700 Subject: [PATCH] Don't rely on CpuStats.Percent Just do the math client-side with TotalTicks and Reserved --- ui/app/models/allocation.js | 9 +++++++-- ui/tests/acceptance/client-detail-test.js | 2 +- ui/tests/acceptance/task-group-detail-test.js | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ui/app/models/allocation.js b/ui/app/models/allocation.js index 81d27a79b..889265317 100644 --- a/ui/app/models/allocation.js +++ b/ui/app/models/allocation.js @@ -57,8 +57,13 @@ export default Model.extend({ return used / total; }), - percentCPU: computed('stats.ResourceUsage.CpuStats.Percent', function() { - return this.get('stats.ResourceUsage.CpuStats.Percent') || 0; + percentCPU: computed('cpuUsed', 'taskGroup.reservedCPU', function() { + const used = this.get('cpuUsed'); + const total = this.get('taskGroup.reservedCPU'); + if (!total || !used) { + return 0; + } + return used / total; }), stats: computed('node.{isPartial,httpAddr}', function() { diff --git a/ui/tests/acceptance/client-detail-test.js b/ui/tests/acceptance/client-detail-test.js index 37518ae5d..189b3bf92 100644 --- a/ui/tests/acceptance/client-detail-test.js +++ b/ui/tests/acceptance/client-detail-test.js @@ -172,7 +172,7 @@ test('each allocation should have high-level details for the allocation', functi .find('td:eq(6)') .text() .trim(), - allocStats.resourceUsage.CpuStats.Percent, + Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed, 'CPU %' ); assert.equal( diff --git a/ui/tests/acceptance/task-group-detail-test.js b/ui/tests/acceptance/task-group-detail-test.js index dbd49a230..98c5eef85 100644 --- a/ui/tests/acceptance/task-group-detail-test.js +++ b/ui/tests/acceptance/task-group-detail-test.js @@ -217,7 +217,7 @@ test('each allocation should show stats about the allocation, retrieved directly .find('td:eq(6)') .text() .trim(), - allocStats.resourceUsage.CpuStats.Percent, + Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed, 'CPU %' );