mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
adds spec for query builder
This commit is contained in:
parent
d3ff4bf75e
commit
0b285845d1
@ -37,7 +37,7 @@ function (angular, _, queryDef) {
|
||||
$scope.settingsLinkText = '';
|
||||
$scope.aggDef = _.findWhere($scope.metricAggTypes, {value: $scope.agg.type});
|
||||
|
||||
if (!$scope.agg.field && $scope.agg.type !== 'moving_avg') {
|
||||
if (!$scope.agg.field) {
|
||||
$scope.agg.field = 'select field';
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,11 @@ function () {
|
||||
var metricAgg = null;
|
||||
|
||||
if (metric.type === 'moving_avg') {
|
||||
metricAgg = {buckets_path: "1"};
|
||||
if (metric.mavgSource && /^\d*$/.test(metric.mavgSource)) {
|
||||
metricAgg = { buckets_path: metric.mavgSource };
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
metricAgg = {field: metric.field};
|
||||
}
|
||||
|
@ -158,11 +158,16 @@ describe('ElasticQueryBuilder', function() {
|
||||
it('with moving average', function() {
|
||||
var query = builder.build({
|
||||
metrics: [
|
||||
{
|
||||
id: '3',
|
||||
type: 'sum',
|
||||
field: '@value'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'moving_avg',
|
||||
field: '@value',
|
||||
aggregation: 'sum'
|
||||
field: '3',
|
||||
mavgSource: '3'
|
||||
}
|
||||
],
|
||||
bucketAggs: [
|
||||
@ -171,9 +176,43 @@ describe('ElasticQueryBuilder', function() {
|
||||
});
|
||||
|
||||
var firstLevel = query.aggs["3"];
|
||||
console.log(JSON.stringify(query));
|
||||
|
||||
expect(firstLevel.aggs["2"]).not.to.be(undefined);
|
||||
expect(firstLevel.aggs["2"].moving_avg).not.to.be(undefined);
|
||||
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("99");
|
||||
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("3");
|
||||
});
|
||||
|
||||
it('with broken moving average', function() {
|
||||
var query = builder.build({
|
||||
metrics: [
|
||||
{
|
||||
id: '3',
|
||||
type: 'sum',
|
||||
field: '@value'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'moving_avg',
|
||||
field: '3',
|
||||
mavgSource: '3'
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
type: 'moving_avg',
|
||||
field: '3',
|
||||
mavgSource: 'Metric to apply moving average'
|
||||
}
|
||||
],
|
||||
bucketAggs: [
|
||||
{ type: 'date_histogram', field: '@timestamp', id: '3' }
|
||||
],
|
||||
});
|
||||
|
||||
var firstLevel = query.aggs["3"];
|
||||
|
||||
expect(firstLevel.aggs["2"]).not.to.be(undefined);
|
||||
expect(firstLevel.aggs["2"].moving_avg).not.to.be(undefined);
|
||||
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("3");
|
||||
expect(firstLevel.aggs["4"]).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user