fix: Elasticsearch table aggregation and support for many aggregations of same type, now uses field name if more than 1 aggregation of same type, fixes #4709

This commit is contained in:
Torkel Ödegaard 2017-05-17 11:33:08 +02:00
parent 820671d6cc
commit 8e03f321eb
2 changed files with 48 additions and 1 deletions

View File

@ -132,6 +132,13 @@ function (_, queryDef) {
} }
default: { default: {
metricName = this._getMetricName(metric.type); metricName = this._getMetricName(metric.type);
var otherMetrics = _.filter(target.metrics, {type: metric.type});
// if more of the same metric type include field field name in property
if (otherMetrics.length > 1) {
metricName += ' ' + metric.field;
}
doc[metricName] = bucket[metric.id].value; doc[metricName] = bucket[metric.id].value;
break; break;
} }

View File

@ -541,6 +541,46 @@ describe('ElasticResponse', function() {
}); });
}); });
describe('Multiple metrics of same type', function() {
beforeEach(function() {
targets = [{
refId: 'A',
metrics: [
{type: 'avg', id: '1', field: 'test'},
{type: 'avg', id: '2', field: 'test2'}
],
bucketAggs: [{id: '2', type: 'terms', field: 'host'}],
}];
response = {
responses: [{
aggregations: {
"2": {
buckets: [
{
"1": { value: 1000},
"2": { value: 3000},
key: "server-1",
doc_count: 369,
}
]
}
}
}]
};
result = new ElasticResponse(targets, response).getTimeSeries();
});
it('should include field in metric name', function() {
expect(result.data[0].type).to.be('docs');
expect(result.data[0].datapoints[0].Average).to.be(undefined);
expect(result.data[0].datapoints[0]['Average test']).to.be(1000);
expect(result.data[0].datapoints[0]['Average test2']).to.be(3000);
});
});
describe('Raw documents query', function() { describe('Raw documents query', function() {
beforeEach(function() { beforeEach(function() {
targets = [{ refId: 'A', metrics: [{type: 'raw_document', id: '1'}], bucketAggs: [] }]; targets = [{ refId: 'A', metrics: [{type: 'raw_document', id: '1'}], bucketAggs: [] }];