Commit 8e18f2c5 by carl bergquist

refactor es pipeline aggregation variables to match ES

parent 0644bfe2
...@@ -199,7 +199,11 @@ function (_, queryDef) { ...@@ -199,7 +199,11 @@ function (_, queryDef) {
if (series.field && series.metric === 'moving_avg') { if (series.field && series.metric === 'moving_avg') {
var appliedAgg = _.findWhere(target.metrics, { id: series.field }); var appliedAgg = _.findWhere(target.metrics, { id: series.field });
metricName += ' ' + queryDef.describeMetric(appliedAgg); if (appliedAgg) {
metricName += ' ' + queryDef.describeMetric(appliedAgg);
} else {
metricName = 'Unset';
}
} else if (series.field) { } else if (series.field) {
metricName += ' ' + series.field; metricName += ' ' + series.field;
} }
......
...@@ -22,7 +22,7 @@ function (angular, _, queryDef) { ...@@ -22,7 +22,7 @@ function (angular, _, queryDef) {
}; };
$scope.updateMavgOptions = function() { $scope.updateMavgOptions = function() {
$scope.mavgOptions = queryDef.getMovingAverageSourceOptions($scope.target); $scope.mavgOptions = queryDef.getMovingAverageOptions($scope.target);
}; };
$rootScope.onAppEvent('elastic-query-updated', function() { $rootScope.onAppEvent('elastic-query-updated', function() {
...@@ -43,9 +43,9 @@ function (angular, _, queryDef) { ...@@ -43,9 +43,9 @@ function (angular, _, queryDef) {
switch($scope.agg.type) { switch($scope.agg.type) {
case 'moving_avg': { 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.settingsLinkText = 'Moving average options';
$scope.agg.field = $scope.agg.mavgSource; $scope.agg.field = $scope.agg.pipelineAgg;
break; break;
} }
case 'percentiles': { case 'percentiles': {
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
Based on Based on
</li> </li>
<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> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
......
...@@ -171,8 +171,8 @@ function () { ...@@ -171,8 +171,8 @@ function () {
var metricAgg = null; var metricAgg = null;
if (metric.type === 'moving_avg') { if (metric.type === 'moving_avg') {
if (metric.mavgSource && /^\d*$/.test(metric.mavgSource)) { if (metric.pipelineAgg && /^\d*$/.test(metric.pipelineAgg)) {
metricAgg = { buckets_path: metric.mavgSource }; metricAgg = { buckets_path: metric.pipelineAgg };
} else { } else {
continue; continue;
} }
......
...@@ -67,7 +67,17 @@ function (_) { ...@@ -67,7 +67,17 @@ function (_) {
{text: '1d', value: '1d'}, {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 self = this;
var result = []; var result = [];
_.each(targets.metrics, function(metric) { _.each(targets.metrics, function(metric) {
......
...@@ -167,7 +167,7 @@ describe('ElasticQueryBuilder', function() { ...@@ -167,7 +167,7 @@ describe('ElasticQueryBuilder', function() {
id: '2', id: '2',
type: 'moving_avg', type: 'moving_avg',
field: '3', field: '3',
mavgSource: '3' pipelineAgg: '3'
} }
], ],
bucketAggs: [ bucketAggs: [
...@@ -194,13 +194,13 @@ describe('ElasticQueryBuilder', function() { ...@@ -194,13 +194,13 @@ describe('ElasticQueryBuilder', function() {
id: '2', id: '2',
type: 'moving_avg', type: 'moving_avg',
field: '3', field: '3',
mavgSource: '3' pipelineAgg: '3'
}, },
{ {
id: '4', id: '4',
type: 'moving_avg', type: 'moving_avg',
field: '3', field: '3',
mavgSource: 'Metric to apply moving average' pipelineAgg: 'Metric to apply moving average'
} }
], ],
bucketAggs: [ bucketAggs: [
......
...@@ -8,41 +8,61 @@ declare var QueryDef: any; ...@@ -8,41 +8,61 @@ declare var QueryDef: any;
describe('ElasticQueryDef', function() { describe('ElasticQueryDef', function() {
describe('with zero targets', function() { describe('getMovingAverageOptions', function() {
var response = QueryDef.getMovingAverageSourceOptions([]); describe('with zero targets', function() {
var response = QueryDef.getMovingAverageOptions([]);
it('should return zero', function() { it('should return zero', function() {
expect(response.length).to.be(0); expect(response.length).to.be(0);
});
}); });
});
describe('with count and sum targets', function() { describe('with count and sum targets', function() {
var targets = { var targets = {
metrics: [ metrics: [
{ type: 'count', field: '@value' }, { type: 'count', field: '@value' },
{ type: 'sum', field: '@value' } { type: 'sum', field: '@value' }
] ]
}; };
var response = QueryDef.getMovingAverageSourceOptions(targets); var response = QueryDef.getMovingAverageOptions(targets);
it('should return zero', function() { it('should return zero', function() {
expect(response.length).to.be(2); 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.getMovingAverageOptions(targets);
it('should return zero', function() {
expect(response.length).to.be(1);
});
}); });
}); });
describe('with count and moving average targets', function() { describe('isPipelineMetric', function() {
var targets = { describe('moving_avg', function() {
metrics: [ var result = QueryDef.isPipelineAgg({ type: 'moving_avg' });
{ type: 'count', field: '@value' },
{ type: 'moving_avg', field: '@value' } it('is pipe line metric', function() {
] expect(result).to.be(true);
}; });
});
var response = QueryDef.getMovingAverageSourceOptions(targets); describe('count', function() {
var result = QueryDef.isPipelineAgg({ type: 'count' });
it('should return zero', function() { it('is not pipe line metric', function() {
expect(response.length).to.be(1); expect(result).to.be(false);
});
}); });
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment