mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Get client stats through the server agent
This commit is contained in:
@@ -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()),
|
||||
});
|
||||
}),
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user