mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
move target extraction logic to query def
This commit is contained in:
parent
dd7a13930f
commit
b4763290de
@ -13,7 +13,7 @@ function (_) {
|
||||
{text: "Min", value: 'min', requiresField: true},
|
||||
{text: "Extended Stats", value: 'extended_stats', requiresField: true},
|
||||
{text: "Percentiles", value: 'percentiles', requiresField: true},
|
||||
{text: "Moving Avg", value: 'moving_avg', requiresField: true, requiresBucketsPath: true},
|
||||
{text: "Moving Avg", value: 'moving_avg', requiresField: false, requiresBucketsPath: true},
|
||||
{text: "Unique Count", value: "cardinality", requiresField: true},
|
||||
{text: "Raw Document", value: "raw_document", requiresField: false}
|
||||
],
|
||||
@ -67,6 +67,18 @@ function (_) {
|
||||
{text: '1d', value: '1d'},
|
||||
],
|
||||
|
||||
getMovingAverageSourceOptions: function(targets) {
|
||||
var self = this;
|
||||
var result = [];
|
||||
_.each(targets.metrics, function(metric) {
|
||||
if (metric.type !== 'moving_avg') {
|
||||
result.push({text: self.describeMetric(metric), value: metric.id });
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
getOrderByOptions: function(target) {
|
||||
var self = this;
|
||||
var metricRefs = [];
|
||||
|
@ -0,0 +1,48 @@
|
||||
///<amd-dependency path="../query_def" name="QueryDef" />
|
||||
///<amd-dependency path="test/specs/helpers" name="helpers" />
|
||||
|
||||
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
|
||||
|
||||
declare var helpers: any;
|
||||
declare var QueryDef: any;
|
||||
|
||||
describe('ElasticQueryDef', function() {
|
||||
|
||||
describe('with zero targets', function() {
|
||||
var response = QueryDef.getMovingAverageSourceOptions([]);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with count and sum targets', function() {
|
||||
var targets = {
|
||||
metrics: [
|
||||
{ type: 'count', field: '@value' },
|
||||
{ type: 'sum', field: '@value' }
|
||||
]
|
||||
};
|
||||
|
||||
var response = QueryDef.getMovingAverageSourceOptions(targets);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with count and moving average targets', function() {
|
||||
var targets = {
|
||||
metrics: [
|
||||
{ type: 'count', field: '@value' },
|
||||
{ type: 'moving_avg', field: '@value' }
|
||||
]
|
||||
};
|
||||
|
||||
var response = QueryDef.getMovingAverageSourceOptions(targets);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(1);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user