Forráskód Böngészése

[elasticsearch] Add option for result set size in raw_dcument
it allows to specify the result set size in raw_document.
Example: table panel could show more (or less) than 500 line if needed.
Added test to spec

Dhia MOAKHAR 8 éve
szülő
commit
966c2912fc

+ 2 - 0
public/app/plugins/datasource/elasticsearch/metric_agg.js

@@ -103,6 +103,8 @@ function (angular, _, queryDef) {
           break;
         }
         case 'raw_document': {
+          $scope.agg.settings.size = $scope.agg.settings.size || 500;
+          $scope.settingsLinkText = 'Size: ' + $scope.agg.settings.size ;
           $scope.target.metrics = [$scope.agg];
           $scope.target.bucketAggs = [];
           break;

+ 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="text" 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>

+ 5 - 3
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 : parseInt(size , 10);
     query.sort = {};
     query.sort[this.timeField] = {order: 'desc', unmapped_type: 'boolean'};
 
@@ -196,7 +196,9 @@ function (queryDef) {
       if (metric && metric.type !== 'raw_document') {
         throw {message: 'Invalid query'};
       }
-      return this.documentQuery(query, target);
+      var size = metric && metric.hasOwnProperty("settings") && metric.settings.hasOwnProperty("size")
+                   && metric.settings["size"] !== null ? metric.settings["size"] : 500 ;
+      return this.documentQuery(query,size);
     }
 
     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({