From 39f9914733b16afe7f09059ec6b893638056c981 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 23 Feb 2018 15:36:38 -0800 Subject: [PATCH] Get client stats through the server agent --- ui/app/models/allocation.js | 12 ++--- ui/mirage/config.js | 53 ++++++++++--------- ui/tests/acceptance/task-group-detail-test.js | 20 ++----- 3 files changed, 36 insertions(+), 49 deletions(-) diff --git a/ui/app/models/allocation.js b/ui/app/models/allocation.js index 617c1d3f7..fe6cd2d62 100644 --- a/ui/app/models/allocation.js +++ b/ui/app/models/allocation.js @@ -7,7 +7,6 @@ import attr from 'ember-data/attr'; import { belongsTo } from 'ember-data/relationships'; import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes'; import PromiseObject from '../utils/classes/promise-object'; -import timeout from '../utils/timeout'; import shortUUIDProperty from '../utils/properties/short-uuid'; const STATUS_ORDER = { @@ -92,14 +91,11 @@ export default Model.extend({ }); } - const url = `//${this.get('node.httpAddr')}/v1/client/allocation/${this.get('id')}/stats`; + const url = `/v1/client/allocation/${this.get('id')}/stats`; return PromiseObject.create({ - promise: RSVP.Promise.race([ - this.get('token') - .authorizedRequest(url) - .then(res => res.json()), - timeout(2000), - ]), + promise: this.get('token') + .authorizedRequest(url) + .then(res => res.json()), }); }), diff --git a/ui/mirage/config.js b/ui/mirage/config.js index c17c7d3e5..b760fb673 100644 --- a/ui/mirage/config.js +++ b/ui/mirage/config.js @@ -178,37 +178,42 @@ export default function() { return new Response(403, {}, null); }); + const clientAllocationStatsHandler = function({ clientAllocationStats }, { params }) { + return this.serialize(clientAllocationStats.find(params.id)); + }; + + const clientAllocationLog = function(server, { params, queryParams }) { + const allocation = server.allocations.find(params.allocation_id); + const tasks = allocation.taskStateIds.map(id => server.taskStates.find(id)); + + if (!tasks.mapBy('name').includes(queryParams.task)) { + return new Response(400, {}, 'must include task name'); + } + + if (queryParams.plain) { + return logFrames.join(''); + } + + return logEncode(logFrames, logFrames.length - 1); + }; + + // Client requests are available on the server and the client + this.get('/client/allocation/:id/stats', clientAllocationStatsHandler); + this.get('/client/fs/logs/:allocation_id', clientAllocationLog); + + this.get('/client/v1/client/stats', function({ clientStats }, { queryParams }) { + return this.serialize(clientStats.find(queryParams.node_id)); + }); + // TODO: in the future, this hack may be replaceable with dynamic host name // support in pretender: https://github.com/pretenderjs/pretender/issues/210 HOSTS.forEach(host => { - this.get(`http://${host}/v1/client/allocation/:id/stats`, function( - { clientAllocationStats }, - { params } - ) { - return this.serialize(clientAllocationStats.find(params.id)); - }); + this.get(`http://${host}/v1/client/allocation/:id/stats`, clientAllocationStatsHandler); + this.get(`http://${host}/v1/client/fs/logs/:allocation_id`, clientAllocationLog); this.get(`http://${host}/v1/client/stats`, function({ clientStats }) { return this.serialize(clientStats.find(host)); }); - - this.get(`http://${host}/v1/client/fs/logs/:allocation_id`, function( - server, - { params, queryParams } - ) { - const allocation = server.allocations.find(params.allocation_id); - const tasks = allocation.taskStateIds.map(id => server.taskStates.find(id)); - - if (!tasks.mapBy('name').includes(queryParams.task)) { - return new Response(400, {}, 'must include task name'); - } - - if (queryParams.plain) { - return logFrames.join(''); - } - - return logEncode(logFrames, logFrames.length - 1); - }); }); } diff --git a/ui/tests/acceptance/task-group-detail-test.js b/ui/tests/acceptance/task-group-detail-test.js index c9665b966..d6b293573 100644 --- a/ui/tests/acceptance/task-group-detail-test.js +++ b/ui/tests/acceptance/task-group-detail-test.js @@ -101,9 +101,7 @@ test('/jobs/:id/:task-group first breadcrumb should link to jobs', function(asse }); }); -test('/jobs/:id/:task-group second breadcrumb should link to the job for the task group', function( - assert -) { +test('/jobs/:id/:task-group second breadcrumb should link to the job for the task group', function(assert) { click(`[data-test-breadcrumb="${job.name}"]`); andThen(() => { assert.equal( @@ -114,9 +112,7 @@ test('/jobs/:id/:task-group second breadcrumb should link to the job for the tas }); }); -test('/jobs/:id/:task-group should list one page of allocations for the task group', function( - assert -) { +test('/jobs/:id/:task-group should list one page of allocations for the task group', function(assert) { const pageSize = 10; server.createList('allocation', 10, { @@ -185,9 +181,7 @@ test('each allocation should show basic information about the allocation', funct }); }); -test('each allocation should show stats about the allocation, retrieved directly from the node', function( - assert -) { +test('each allocation should show stats about the allocation', function(assert) { const allocation = allocations.sortBy('name')[0]; const allocationRow = find('[data-test-allocation]'); const allocStats = server.db.clientAllocationStats.find(allocation.id); @@ -219,14 +213,6 @@ test('each allocation should show stats about the allocation, retrieved directly `${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`, 'Detailed memory information is in a tooltip' ); - - const node = server.db.nodes.find(allocation.nodeId); - const nodeStatsUrl = `//${node.httpAddr}/v1/client/allocation/${allocation.id}/stats`; - - assert.ok( - server.pretender.handledRequests.some(req => req.url === nodeStatsUrl), - `Requests ${nodeStatsUrl}` - ); }); test('when the allocation search has no matches, there is an empty message', function(assert) {