Browse Source

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

Torkel Ödegaard 8 years ago
parent
commit
3c41d0477a

+ 4 - 3
public/app/plugins/datasource/elasticsearch/metric_agg.js

@@ -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

+ 5 - 0
public/app/plugins/datasource/elasticsearch/partials/metric_agg.html

@@ -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>

+ 7 - 4
public/app/plugins/datasource/elasticsearch/query_builder.js

@@ -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;

+ 10 - 1
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts

@@ -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({