Commit a82f553b authored by Clement Ho's avatar Clement Ho

Merge branch 'adriel-fix-cluster-metrics-regression' into 'master'

Resolve cluster metrics regression

Closes gitlab-ee#11168

See merge request gitlab-org/gitlab-ce!27442
parents e9bf3672 d753db3f
...@@ -45,14 +45,13 @@ function removeTimeSeriesNoData(queries) { ...@@ -45,14 +45,13 @@ function removeTimeSeriesNoData(queries) {
// ] // ]
function groupQueriesByChartInfo(metrics) { function groupQueriesByChartInfo(metrics) {
const metricsByChart = metrics.reduce((accumulator, metric) => { const metricsByChart = metrics.reduce((accumulator, metric) => {
const { id, queries, ...chart } = metric; const { queries, ...chart } = metric;
const metricId = chart.id ? chart.id.toString() : null;
const chartKey = `${chart.title}|${chart.y_label}`; const chartKey = `${chart.title}|${chart.y_label}`;
accumulator[chartKey] = accumulator[chartKey] || { ...chart, queries: [] }; accumulator[chartKey] = accumulator[chartKey] || { ...chart, queries: [] };
queries.forEach(queryAttrs => queries.forEach(queryAttrs => accumulator[chartKey].queries.push({ metricId, ...queryAttrs }));
accumulator[chartKey].queries.push({ metricId: id.toString(), ...queryAttrs }),
);
return accumulator; return accumulator;
}, {}); }, {});
......
...@@ -32,4 +32,28 @@ describe('MonitoringStore', () => { ...@@ -32,4 +32,28 @@ describe('MonitoringStore', () => {
it('removes the data if all the values from a query are not defined', () => { it('removes the data if all the values from a query are not defined', () => {
expect(store.groups[1].metrics[0].queries[0].result.length).toEqual(0); expect(store.groups[1].metrics[0].queries[0].result.length).toEqual(0);
}); });
it('assigns queries a metric id', () => {
expect(store.groups[1].metrics[0].queries[0].metricId).toEqual('100');
});
it('assigns metric id of null if metric has no id', () => {
const noId = MonitoringMock.data.map(group => ({
...group,
...{
metrics: group.metrics.map(metric => {
const { id, ...metricWithoutId } = metric;
return metricWithoutId;
}),
},
}));
store.storeMetrics(noId);
store.groups.forEach(group => {
group.metrics.forEach(metric => {
expect(metric.queries.every(query => query.metricId === null)).toBe(true);
});
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment