Improve client stat simulation and add a chance for requests to error

This commit is contained in:
Michael Lange
2018-11-01 22:11:56 -07:00
parent 9f98029898
commit b0a1a360ba
3 changed files with 16 additions and 4 deletions

View File

@@ -307,7 +307,17 @@ export default function() {
this.get('/client/fs/logs/:allocation_id', clientAllocationLog);
this.get('/client/stats', function({ clientStats }, { queryParams }) {
return this.serialize(clientStats.find(queryParams.node_id));
const seed = Math.random();
if (seed > 0.8) {
const stats = clientStats.find(queryParams.node_id);
stats.update({
timestamp: Date.now() * 1000000,
CPUTicksConsumed: stats.CPUTicksConsumed + (Math.random() * 20 - 10),
});
return this.serialize(stats);
} else {
return new Response(500, {}, null);
}
});
// TODO: in the future, this hack may be replaceable with dynamic host name

View File

@@ -23,7 +23,7 @@ export default Factory.extend({
})),
],
CPUTicksConsumed: 1000000,
CPUTicksConsumed: faker.random.number({ min: 100, max: 1000 }),
diskStats: () => [
Array(faker.random.number({ min: 1, max: 5 }))
@@ -46,6 +46,6 @@ export default Factory.extend({
Used: 10000000000,
}),
timestamp: 149000000000,
timestamp: Date.now() * 1000000,
uptime: 193838,
});

View File

@@ -1,6 +1,6 @@
import { Factory, faker, trait } from 'ember-cli-mirage';
import { provide } from '../utils';
import { DATACENTERS, HOSTS } from '../common';
import { DATACENTERS, HOSTS, generateResources } from '../common';
import moment from 'moment';
const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
@@ -65,6 +65,8 @@ export default Factory.extend({
drivers: makeDrivers,
resources: generateResources,
attributes() {
// TODO add variability to these
return {