Skip to content

Commit

Permalink
Get client stats through the server agent
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Feb 26, 2018
1 parent 67b99d4 commit 39f9914
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 49 deletions.
12 changes: 4 additions & 8 deletions ui/app/models/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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()),
});
}),

Expand Down
53 changes: 29 additions & 24 deletions ui/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

Expand Down
20 changes: 3 additions & 17 deletions ui/tests/acceptance/task-group-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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, {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 39f9914

Please sign in to comment.