mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactor es pipeline aggregation variables to match ES
This commit is contained in:
parent
0644bfe27c
commit
8e18f2c5d2
@ -199,7 +199,11 @@ function (_, queryDef) {
|
||||
|
||||
if (series.field && series.metric === 'moving_avg') {
|
||||
var appliedAgg = _.findWhere(target.metrics, { id: series.field });
|
||||
if (appliedAgg) {
|
||||
metricName += ' ' + queryDef.describeMetric(appliedAgg);
|
||||
} else {
|
||||
metricName = 'Unset';
|
||||
}
|
||||
} else if (series.field) {
|
||||
metricName += ' ' + series.field;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ function (angular, _, queryDef) {
|
||||
};
|
||||
|
||||
$scope.updateMavgOptions = function() {
|
||||
$scope.mavgOptions = queryDef.getMovingAverageSourceOptions($scope.target);
|
||||
$scope.mavgOptions = queryDef.getMovingAverageOptions($scope.target);
|
||||
};
|
||||
|
||||
$rootScope.onAppEvent('elastic-query-updated', function() {
|
||||
@ -43,9 +43,9 @@ function (angular, _, queryDef) {
|
||||
|
||||
switch($scope.agg.type) {
|
||||
case 'moving_avg': {
|
||||
$scope.agg.mavgSource = $scope.agg.mavgSource || 'Metric to apply moving average';
|
||||
$scope.agg.pipelineAgg = $scope.agg.pipelineAgg || 'Metric to apply moving average';
|
||||
$scope.settingsLinkText = 'Moving average options';
|
||||
$scope.agg.field = $scope.agg.mavgSource;
|
||||
$scope.agg.field = $scope.agg.pipelineAgg;
|
||||
break;
|
||||
}
|
||||
case 'percentiles': {
|
||||
|
@ -33,7 +33,7 @@
|
||||
Based on
|
||||
</li>
|
||||
<li>
|
||||
<metric-segment-model property="agg.mavgSource" options="mavgOptions" on-change="onChangeInternal()" css-class="last"></metric-segment-model>
|
||||
<metric-segment-model property="agg.pipelineAgg" options="mavgOptions" on-change="onChangeInternal()" css-class="last"></metric-segment-model>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
|
@ -171,8 +171,8 @@ function () {
|
||||
var metricAgg = null;
|
||||
|
||||
if (metric.type === 'moving_avg') {
|
||||
if (metric.mavgSource && /^\d*$/.test(metric.mavgSource)) {
|
||||
metricAgg = { buckets_path: metric.mavgSource };
|
||||
if (metric.pipelineAgg && /^\d*$/.test(metric.pipelineAgg)) {
|
||||
metricAgg = { buckets_path: metric.pipelineAgg };
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -67,7 +67,17 @@ function (_) {
|
||||
{text: '1d', value: '1d'},
|
||||
],
|
||||
|
||||
getMovingAverageSourceOptions: function(targets) {
|
||||
pipelineAggs: ['moving_avg'],
|
||||
|
||||
isPipelineAgg: function(metric) {
|
||||
if (metric.type) {
|
||||
return this.pipelineAggs.indexOf(metric.type) > -1;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
getMovingAverageOptions: function(targets) {
|
||||
var self = this;
|
||||
var result = [];
|
||||
_.each(targets.metrics, function(metric) {
|
||||
|
@ -167,7 +167,7 @@ describe('ElasticQueryBuilder', function() {
|
||||
id: '2',
|
||||
type: 'moving_avg',
|
||||
field: '3',
|
||||
mavgSource: '3'
|
||||
pipelineAgg: '3'
|
||||
}
|
||||
],
|
||||
bucketAggs: [
|
||||
@ -194,13 +194,13 @@ describe('ElasticQueryBuilder', function() {
|
||||
id: '2',
|
||||
type: 'moving_avg',
|
||||
field: '3',
|
||||
mavgSource: '3'
|
||||
pipelineAgg: '3'
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
type: 'moving_avg',
|
||||
field: '3',
|
||||
mavgSource: 'Metric to apply moving average'
|
||||
pipelineAgg: 'Metric to apply moving average'
|
||||
}
|
||||
],
|
||||
bucketAggs: [
|
||||
|
@ -8,8 +8,9 @@ declare var QueryDef: any;
|
||||
|
||||
describe('ElasticQueryDef', function() {
|
||||
|
||||
describe('getMovingAverageOptions', function() {
|
||||
describe('with zero targets', function() {
|
||||
var response = QueryDef.getMovingAverageSourceOptions([]);
|
||||
var response = QueryDef.getMovingAverageOptions([]);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(0);
|
||||
@ -24,7 +25,7 @@ describe('ElasticQueryDef', function() {
|
||||
]
|
||||
};
|
||||
|
||||
var response = QueryDef.getMovingAverageSourceOptions(targets);
|
||||
var response = QueryDef.getMovingAverageOptions(targets);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(2);
|
||||
@ -39,10 +40,29 @@ describe('ElasticQueryDef', function() {
|
||||
]
|
||||
};
|
||||
|
||||
var response = QueryDef.getMovingAverageSourceOptions(targets);
|
||||
var response = QueryDef.getMovingAverageOptions(targets);
|
||||
|
||||
it('should return zero', function() {
|
||||
expect(response.length).to.be(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPipelineMetric', function() {
|
||||
describe('moving_avg', function() {
|
||||
var result = QueryDef.isPipelineAgg({ type: 'moving_avg' });
|
||||
|
||||
it('is pipe line metric', function() {
|
||||
expect(result).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('count', function() {
|
||||
var result = QueryDef.isPipelineAgg({ type: 'count' });
|
||||
|
||||
it('is not pipe line metric', function() {
|
||||
expect(result).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user