[Infra UI] Fixes #37450 - Add check for empty metrics (#37508)

This commit is contained in:
Chris Cowan 2019-05-31 09:06:03 -07:00 committed by GitHub
parent 9a4e5cff20
commit b4833a3c57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -23,6 +23,15 @@ export const populateSeriesWithTSVBData = (
options: MetricsExplorerRequest,
framework: InfraBackendFrameworkAdapter
) => async (series: MetricsExplorerSeries) => {
// IF there are no metrics selected then we should return an empty result.
if (options.metrics.length === 0) {
return {
...series,
columns: [],
rows: [],
};
}
// Set the filter for the group by or match everything
const filters = options.groupBy ? [{ match: { [options.groupBy]: series.id } }] : [];
const timerange = { min: options.timerange.from, max: options.timerange.to };

View file

@ -66,6 +66,33 @@ const metricsExplorerTest: KbnTestProvider = ({ getService }) => {
});
});
it('should work for empty metrics', async () => {
const postBody = {
timerange: {
field: '@timestamp',
to: max,
from: min,
interval: '>=1m',
},
indexPattern: 'metricbeat-*',
metrics: [],
};
const response = await supertest
.post('/api/infra/metrics_explorer')
.set('kbn-xsrf', 'xxx')
.send(postBody)
.expect(200);
const body: MetricsExplorerResponse = response.body;
expect(body).to.have.property('series');
expect(body.series).length(1);
const firstSeries = first(body.series);
expect(firstSeries).to.have.property('id', 'ALL');
expect(firstSeries).to.have.property('columns');
expect(firstSeries).to.have.property('rows');
expect(firstSeries!.columns).to.eql([]);
expect(firstSeries!.rows).to.have.length(0);
});
it('should work with groupBy', async () => {
const postBody = {
timerange: {