Elasticsearch: Fix view percentiles metric in table without date histogram (#15686)

Fix for properly display percentiles metrics in table panel when 
using a query without date histogram and for example grouping by 
terms.

Fixes #3786
This commit is contained in:
Igor Ratsuk
2019-03-29 07:22:04 +01:00
committed by Marcus Efraimsson
parent 7ddb770e3b
commit 930fd8b43a
2 changed files with 61 additions and 0 deletions

View File

@@ -156,6 +156,14 @@ export class ElasticResponse {
} }
break; break;
} }
case 'percentiles': {
const percentiles = bucket[metric.id].values;
for (const percentileName in percentiles) {
addMetricValue(values, `p${percentileName} ${metric.field}`, percentiles[percentileName]);
}
break;
}
default: { default: {
let metricName = this.getMetricName(metric.type); let metricName = this.getMetricName(metric.type);
const otherMetrics = _.filter(target.metrics, { type: metric.type }); const otherMetrics = _.filter(target.metrics, { type: metric.type });

View File

@@ -582,6 +582,59 @@ describe('ElasticResponse', () => {
}); });
}); });
describe('No group by time with percentiles ', () => {
let result;
beforeEach(() => {
targets = [
{
refId: 'A',
metrics: [{ type: 'percentiles', field: 'value', settings: { percents: [75, 90] }, id: '1' }],
bucketAggs: [{ type: 'term', field: 'id', id: '3' }],
},
];
response = {
responses: [
{
aggregations: {
'3': {
buckets: [
{
'1': { values: { '75': 3.3, '90': 5.5 } },
doc_count: 10,
key: 'id1',
},
{
'1': { values: { '75': 2.3, '90': 4.5 } },
doc_count: 15,
key: 'id2',
},
],
},
},
},
],
};
result = new ElasticResponse(targets, response).getTimeSeries();
});
it('should return table', () => {
expect(result.data.length).toBe(1);
expect(result.data[0].type).toBe('table');
expect(result.data[0].columns[0].text).toBe('id');
expect(result.data[0].columns[1].text).toBe('p75 value');
expect(result.data[0].columns[2].text).toBe('p90 value');
expect(result.data[0].rows.length).toBe(2);
expect(result.data[0].rows[0][0]).toBe('id1');
expect(result.data[0].rows[0][1]).toBe(3.3);
expect(result.data[0].rows[0][2]).toBe(5.5);
expect(result.data[0].rows[1][0]).toBe('id2');
expect(result.data[0].rows[1][1]).toBe(2.3);
expect(result.data[0].rows[1][2]).toBe(4.5);
});
});
describe('Multiple metrics of same type', () => { describe('Multiple metrics of same type', () => {
beforeEach(() => { beforeEach(() => {
targets = [ targets = [