1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 23:30:05 +02:00

fix(cp-frontend): handle no data in metrics loop

This commit is contained in:
Sérgio Ramos 2017-08-30 14:02:27 +01:00
parent 3db2cfaea5
commit d08a8b00a9
3 changed files with 19 additions and 6 deletions

View File

@ -12,7 +12,7 @@ import {
const ServiceScale = ({ const ServiceScale = ({
service, service,
handleSubmit = () => {}, handleSubmit = () => {},
onCancelClick = () => {}, onCancel = () => {},
invalid, invalid,
pristine pristine
}) => ( }) => (
@ -32,7 +32,7 @@ const ServiceScale = ({
<FormMeta /> <FormMeta />
<NumberInput minValue={1} /> <NumberInput minValue={1} />
</FormGroup> </FormGroup>
<Button secondary onClick={onCancelClick}> <Button type="button" secondary onClick={onCancel}>
Cancel Cancel
</Button> </Button>
<Button type="submit" disabled={pristine || invalid} secondary> <Button type="submit" disabled={pristine || invalid} secondary>

View File

@ -1,7 +1,9 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { compose, graphql } from 'react-apollo'; import { compose, graphql } from 'react-apollo';
import moment from 'moment'; import find from 'lodash.find';
import uniqBy from 'lodash.uniqby'; import uniqBy from 'lodash.uniqby';
import get from 'lodash.get';
import moment from 'moment';
export const MetricNames = [ export const MetricNames = [
'AVG_MEM_BYTES', 'AVG_MEM_BYTES',
@ -53,8 +55,13 @@ export const withServiceMetricsGql = ({
instanceId, instanceId,
metricName metricName
) => { ) => {
return previousResult.deploymentGroup.services const service = find(get(previousResult, 'deploymentGroup.services', []), ['id', serviceId]);
.find(s => s.id === serviceId)
if (!service) {
return [];
}
return service
.instances.find(i => i.id === instanceId) .instances.find(i => i.id === instanceId)
.metrics.find(m => m.name === metricName).metrics; .metrics.find(m => m.name === metricName).metrics;
}; };

View File

@ -184,7 +184,13 @@ export default compose(
return false; return false;
} }
const previousEnd = services const _services = forceArray(services);
if (!_services.length) {
return false;
}
const previousEnd = _services
.map(service => get(service, 'instances[0].metrics[0].end', null)) .map(service => get(service, 'instances[0].metrics[0].end', null))
.filter(Boolean) .filter(Boolean)
.shift(); .shift();