From b0a1a360ba598b60e12ff7458e9cf593fe265eb7 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 1 Nov 2018 22:11:56 -0700 Subject: [PATCH] Improve client stat simulation and add a chance for requests to error --- ui/mirage/config.js | 12 +++++++++++- ui/mirage/factories/client-stats.js | 4 ++-- ui/mirage/factories/node.js | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ui/mirage/config.js b/ui/mirage/config.js index d0b834a42..c98588b5c 100644 --- a/ui/mirage/config.js +++ b/ui/mirage/config.js @@ -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 diff --git a/ui/mirage/factories/client-stats.js b/ui/mirage/factories/client-stats.js index 6924f07f6..8d7b27edd 100644 --- a/ui/mirage/factories/client-stats.js +++ b/ui/mirage/factories/client-stats.js @@ -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, }); diff --git a/ui/mirage/factories/node.js b/ui/mirage/factories/node.js index e8ec62a9d..a7c66cd3a 100644 --- a/ui/mirage/factories/node.js +++ b/ui/mirage/factories/node.js @@ -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 {