From bf41eb824d24d30e7ae904ee19ce46d84be116ea Mon Sep 17 00:00:00 2001 From: Qtax Date: Sat, 5 Dec 2015 23:56:55 +0100 Subject: [PATCH] Added ES histogram setting to drop/ignore the first and last datapoints --- .../datasource/elasticsearch/bucket_agg.js | 3 +++ .../elasticsearch/elastic_response.js | 17 ++++++------- .../elasticsearch/partials/bucket_agg.html | 24 +++++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/bucket_agg.js b/public/app/plugins/datasource/elasticsearch/bucket_agg.js index 2a21bc17960..62cdcb3f59e 100644 --- a/public/app/plugins/datasource/elasticsearch/bucket_agg.js +++ b/public/app/plugins/datasource/elasticsearch/bucket_agg.js @@ -96,6 +96,9 @@ function (angular, _, queryDef) { $scope.agg.field = $scope.target.timeField; settingsLinkText = 'Interval: ' + settings.interval; settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count; + if (settings.dropFirstLast) { + settingsLinkText += ', Drop first & last value'; + } } } diff --git a/public/app/plugins/datasource/elasticsearch/elastic_response.js b/public/app/plugins/datasource/elasticsearch/elastic_response.js index b8405797408..5915578530f 100644 --- a/public/app/plugins/datasource/elasticsearch/elastic_response.js +++ b/public/app/plugins/datasource/elasticsearch/elastic_response.js @@ -10,8 +10,9 @@ function (_, queryDef) { this.response = response; } - ElasticResponse.prototype.processMetrics = function(esAgg, target, seriesList, props) { + ElasticResponse.prototype.processMetrics = function(esAgg, target, seriesList, props, dropFirstLast) { var metric, y, i, newSeries, bucket, value; + dropFirstLast = dropFirstLast ? 1 : 0; for (y = 0; y < target.metrics.length; y++) { metric = target.metrics[y]; @@ -22,7 +23,7 @@ function (_, queryDef) { switch(metric.type) { case 'count': { newSeries = { datapoints: [], metric: 'count', props: props}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; value = bucket.doc_count; newSeries.datapoints.push([value, bucket.key]); @@ -31,17 +32,17 @@ function (_, queryDef) { break; } case 'percentiles': { - if (esAgg.buckets.length === 0) { + if (esAgg.buckets.length - dropFirstLast * 2 <= 0) { break; } - var firstBucket = esAgg.buckets[0]; + var firstBucket = esAgg.buckets[dropFirstLast]; var percentiles = firstBucket[metric.id].values; for (var percentileName in percentiles) { newSeries = {datapoints: [], metric: 'p' + percentileName, props: props, field: metric.field}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; var values = bucket[metric.id].values; newSeries.datapoints.push([values[percentileName], bucket.key]); @@ -59,7 +60,7 @@ function (_, queryDef) { newSeries = {datapoints: [], metric: statName, props: props, field: metric.field}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; var stats = bucket[metric.id]; @@ -77,7 +78,7 @@ function (_, queryDef) { } default: { newSeries = { datapoints: [], metric: metric.type, field: metric.field, props: props}; - for (i = 0; i < esAgg.buckets.length; i++) { + for (i = dropFirstLast; i < esAgg.buckets.length - dropFirstLast; i++) { bucket = esAgg.buckets[i]; value = bucket[metric.id]; @@ -158,7 +159,7 @@ function (_, queryDef) { if (depth === maxDepth) { if (aggDef.type === 'date_histogram') { - this.processMetrics(esAgg, target, seriesList, props); + this.processMetrics(esAgg, target, seriesList, props, aggDef.settings && aggDef.settings.dropFirstLast); } else { this.processAggregationDocs(esAgg, aggDef, target, docs, props); } diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html index 5a84ec8f6cd..b4092a0317a 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html @@ -37,7 +37,7 @@
    -
  • +
  • Interval
  • @@ -46,13 +46,29 @@
-
+
    -
  • +
  • Min Doc Count
  • - + +
  • +
+
+
+
+
    +
  • + Drop first & last value +
  • +
  • + + +
  • +
  • +