From 9008694ab7b62097e5f5fe1d8cc02db4f4128e4e Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 27 Jul 2020 21:29:22 -0700 Subject: [PATCH] Make scale event properties more conditional and serialized correctly --- ui/mirage/config.js | 1 - ui/mirage/factories/scale-event.js | 15 +++++++++------ ui/mirage/factories/task-group-scale.js | 4 +++- ui/mirage/serializers/job-scale.js | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ui/mirage/config.js b/ui/mirage/config.js index c76fa2e4e..c85d4c15c 100644 --- a/ui/mirage/config.js +++ b/ui/mirage/config.js @@ -161,7 +161,6 @@ export default function() { '/job/:id/scale', withBlockingSupport(function({ jobScales }, { params }) { const obj = jobScales.findBy({ jobId: params.id }); - console.log('Job Scale Object', obj); return this.serialize(jobScales.findBy({ jobId: params.id })); }) ); diff --git a/ui/mirage/factories/scale-event.js b/ui/mirage/factories/scale-event.js index 8532c4ec2..eeb7399d3 100644 --- a/ui/mirage/factories/scale-event.js +++ b/ui/mirage/factories/scale-event.js @@ -7,11 +7,14 @@ export default Factory.extend({ time: () => faker.date.past(2 / 365, REF_TIME) * 1000000, count: () => faker.random.number(10), previousCount: () => faker.random.number(10), - error: () => faker.random.number(10) > 9, + error: () => faker.random.number(10) > 8, message: 'Sample message for a job scale event', - meta: () => ({ - 'nomad_autoscaler.count.capped': true, - 'nomad_autoscaler.count.original': 0, - 'nomad_autoscaler.reason_history': ['scaling down because factor is 0.000000'], - }), + meta: () => + faker.random.number(10) < 8 + ? { + 'nomad_autoscaler.count.capped': true, + 'nomad_autoscaler.count.original': 0, + 'nomad_autoscaler.reason_history': ['scaling down because factor is 0.000000'], + } + : {}, }); diff --git a/ui/mirage/factories/task-group-scale.js b/ui/mirage/factories/task-group-scale.js index 98160b49d..a7f20fc61 100644 --- a/ui/mirage/factories/task-group-scale.js +++ b/ui/mirage/factories/task-group-scale.js @@ -2,7 +2,9 @@ import { Factory, trait } from 'ember-cli-mirage'; import faker from 'nomad-ui/mirage/faker'; export default Factory.extend({ - name: id => id, + name() { + return this.id; + }, desired: 1, placed: 1, diff --git a/ui/mirage/serializers/job-scale.js b/ui/mirage/serializers/job-scale.js index 83abf7011..e01e3df70 100644 --- a/ui/mirage/serializers/job-scale.js +++ b/ui/mirage/serializers/job-scale.js @@ -1,6 +1,21 @@ import ApplicationSerializer from './application'; +import { arrToObj } from '../utils'; export default ApplicationSerializer.extend({ embed: true, include: ['taskGroupScales'], + + serialize() { + var json = ApplicationSerializer.prototype.serialize.apply(this, arguments); + if (json instanceof Array) { + json.forEach(serializeJobScale); + } else { + serializeJobScale(json); + } + return json; + }, }); + +function serializeJobScale(jobScale) { + jobScale.TaskGroups = jobScale.TaskGroupScales.reduce(arrToObj('Name'), {}); +}