Merge branch 'master' of https://github.com/mk-dhia/grafana into mk-dhia-master

This commit is contained in:
Torkel Ödegaard 2017-06-08 11:22:48 +02:00
commit 3c41d0477a
4 changed files with 26 additions and 8 deletions

View File

@ -67,7 +67,6 @@ function (angular, _, queryDef) {
} else if (!$scope.agg.field) {
$scope.agg.field = 'select field';
}
switch($scope.agg.type) {
case 'cardinality': {
var precision_threshold = $scope.agg.settings.precision_threshold || '';
@ -103,12 +102,14 @@ function (angular, _, queryDef) {
break;
}
case 'raw_document': {
$scope.target.metrics = [$scope.agg];
$scope.agg.settings.size = $scope.agg.settings.size || 500;
$scope.settingsLinkText = 'Size: ' + $scope.agg.settings.size ;
$scope.target.metrics.splice(0,$scope.target.metrics.length, $scope.agg);
$scope.target.bucketAggs = [];
break;
}
}
if ($scope.aggDef.supportsInlineScript) {
// I know this stores the inline script twice
// but having it like this simplifes the query_builder

View File

@ -72,6 +72,11 @@
<label class="gf-form-label width-10">Percentiles</label>
<input type="text" class="gf-form-input max-width-12" ng-model="agg.settings.percents" array-join ng-blur="onChange()"></input>
</div>
<div class="gf-form offset-width-7" ng-if="agg.type === 'raw_document'">
<label class="gf-form-label width-10">Size</label>
<input type="number" class="gf-form-input max-width-12" ng-model="agg.settings.size" ng-blur="onChange()"></input>
</div>
<div class="gf-form offset-width-7" ng-if="agg.type === 'cardinality'">
<label class="gf-form-label width-10">Precision threshold</label>

View File

@ -109,8 +109,8 @@ function (queryDef) {
return filterObj;
};
ElasticQueryBuilder.prototype.documentQuery = function(query) {
query.size = 500;
ElasticQueryBuilder.prototype.documentQuery = function(query, size) {
query.size = size === undefined ? 500 : size;
query.sort = {};
query.sort[this.timeField] = {order: 'desc', unmapped_type: 'boolean'};
@ -194,9 +194,12 @@ function (queryDef) {
if (target.bucketAggs.length === 0) {
metric = target.metrics[0];
if (metric && metric.type !== 'raw_document') {
throw {message: 'Invalid query'};
target.bucketAggs = [{type: 'date_histogram', id: '2', settings: {interval: 'auto'}}];
} else {
var size = metric && metric.hasOwnProperty("settings") && metric.settings.hasOwnProperty("size")
&& metric.settings["size"] !== null ? metric.settings["size"] : 500 ;
return this.documentQuery(query,size);
}
return this.documentQuery(query, target);
}
nestedAggs = query;

View File

@ -156,13 +156,22 @@ describe('ElasticQueryBuilder', function() {
it('with raw_document metric', function() {
var query = builder.build({
metrics: [{type: 'raw_document', id: '1'}],
metrics: [{type: 'raw_document', id: '1',settings: {}}],
timeField: '@timestamp',
bucketAggs: [],
});
expect(query.size).to.be(500);
});
it('with raw_document metric size set', function() {
var query = builder.build({
metrics: [{type: 'raw_document', id: '1',settings: {size: 1337}}],
timeField: '@timestamp',
bucketAggs: [],
});
expect(query.size).to.be(1337);
});
it('with moving average', function() {
var query = builder.build({