From 10f66fa78fee2f302444ebe25c58e90f4da4ed15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 11 Dec 2015 18:20:53 +0100 Subject: [PATCH] feat(elasticsearch): adds support for inline script and missing options to all elasticsearch metrics, closes #3500 --- CHANGELOG.md | 1 + .../datasource/elasticsearch/directives.js | 4 +-- .../datasource/elasticsearch/metric_agg.js | 29 +++++++++++++++---- .../{bucketAgg.html => bucket_agg.html} | 0 .../{metricAgg.html => metric_agg.html} | 28 +++++++++++++++++- .../datasource/elasticsearch/query_def.js | 14 ++++----- 6 files changed, 60 insertions(+), 16 deletions(-) rename public/app/plugins/datasource/elasticsearch/partials/{bucketAgg.html => bucket_agg.html} (100%) rename public/app/plugins/datasource/elasticsearch/partials/{metricAgg.html => metric_agg.html} (77%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad2757fb01f..efc6e88d5b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### New Features * **Elasticsearch**: Support for pipeline aggregations Moving average and derivative, closes [#2715](https://github.com/grafana/grafana/issues/2715) +* **Elasticsearch**: Support for inline script and missing options for metrics, closes [#3500](https://github.com/grafana/grafana/issues/3500) * **Syslog**: Support for syslog logging, closes [#3161](https://github.com/grafana/grafana/pull/3161) * **Timepicker**: Always show refresh button even with refresh rate, closes [#3498](https://github.com/grafana/grafana/pull/3498) * **Login**: Make it possible to change the login hint on the login page, closes [#2571](https://github.com/grafana/grafana/pull/2571) diff --git a/public/app/plugins/datasource/elasticsearch/directives.js b/public/app/plugins/datasource/elasticsearch/directives.js index 480ee79ad0a..b09c82b481e 100644 --- a/public/app/plugins/datasource/elasticsearch/directives.js +++ b/public/app/plugins/datasource/elasticsearch/directives.js @@ -22,7 +22,7 @@ function (angular) { module.directive('elasticMetricAgg', function() { return { - templateUrl: 'app/plugins/datasource/elasticsearch/partials/metricAgg.html', + templateUrl: 'app/plugins/datasource/elasticsearch/partials/metric_agg.html', controller: 'ElasticMetricAggCtrl', restrict: 'E', scope: { @@ -36,7 +36,7 @@ function (angular) { module.directive('elasticBucketAgg', function() { return { - templateUrl: 'app/plugins/datasource/elasticsearch/partials/bucketAgg.html', + templateUrl: 'app/plugins/datasource/elasticsearch/partials/bucket_agg.html', controller: 'ElasticBucketAggCtrl', restrict: 'E', scope: { diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js index df5d8e00a80..b4ef6a80b79 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.js +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js @@ -55,10 +55,15 @@ function (angular, _, queryDef) { switch($scope.agg.type) { case 'percentiles': { $scope.agg.settings.percents = $scope.agg.settings.percents || [25,50,75,95,99]; - $scope.settingsLinkText = 'values: ' + $scope.agg.settings.percents.join(','); + $scope.settingsLinkText = 'Values: ' + $scope.agg.settings.percents.join(','); break; } case 'extended_stats': { + if (_.keys($scope.agg.meta).length === 0) { + $scope.agg.meta.std_deviation_bounds_lower = true; + $scope.agg.meta.std_deviation_bounds_upper = true; + } + var stats = _.reduce($scope.agg.meta, function(memo, val, key) { if (val) { var def = _.findWhere($scope.extendedStats, {value: key}); @@ -66,17 +71,29 @@ function (angular, _, queryDef) { } return memo; }, []); - $scope.settingsLinkText = 'Stats: ' + stats.join(', '); - if (stats.length === 0) { - $scope.agg.meta.std_deviation_bounds_lower = true; - $scope.agg.meta.std_deviation_bounds_upper = true; - } + $scope.settingsLinkText = 'Stats: ' + stats.join(', '); break; } case 'raw_document': { $scope.target.metrics = [$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 + var inlineScript = $scope.agg.inlineScript; + if (inlineScript) { + $scope.agg.settings.script = {inline: inlineScript}; + } else { + delete $scope.agg.settings.script; + } + + if ($scope.settingsLinkText === '') { + $scope.settingsLinkText = 'Options'; } } }; diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html similarity index 100% rename from public/app/plugins/datasource/elasticsearch/partials/bucketAgg.html rename to public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html diff --git a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html b/public/app/plugins/datasource/elasticsearch/partials/metric_agg.html similarity index 77% rename from public/app/plugins/datasource/elasticsearch/partials/metricAgg.html rename to public/app/plugins/datasource/elasticsearch/partials/metric_agg.html index 9a706a96ba6..4da8b53181b 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/metricAgg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/metric_agg.html @@ -85,7 +85,7 @@
-
+
  • Sigma @@ -96,5 +96,31 @@
+ +
+
    +
  • + Script +
  • +
  • + +
  • +
+
+
+ +
+
    +
  • + Missing + The missing parameter defines how documents that are missing a value should be treated. By default they will be ignored but it is also possible to treat them as if they had a value +
  • +
  • + +
  • +
+
+
+
diff --git a/public/app/plugins/datasource/elasticsearch/query_def.js b/public/app/plugins/datasource/elasticsearch/query_def.js index 6e7ae6d5d0a..c798646db06 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.js +++ b/public/app/plugins/datasource/elasticsearch/query_def.js @@ -7,15 +7,15 @@ function (_) { return { metricAggTypes: [ {text: "Count", value: 'count', requiresField: false}, - {text: "Average", value: 'avg', requiresField: true}, - {text: "Sum", value: 'sum', requiresField: true}, - {text: "Max", value: 'max', requiresField: true}, - {text: "Min", value: 'min', requiresField: true}, - {text: "Extended Stats", value: 'extended_stats', requiresField: true}, - {text: "Percentiles", value: 'percentiles', requiresField: true}, + {text: "Average", value: 'avg', requiresField: true, supportsInlineScript: true, supportsMissing: true}, + {text: "Sum", value: 'sum', requiresField: true, supportsInlineScript: true, supportsMissing: true}, + {text: "Max", value: 'max', requiresField: true, supportsInlineScript: true, supportsMissing: true}, + {text: "Min", value: 'min', requiresField: true, supportsInlineScript: true, supportsMissing: true}, + {text: "Extended Stats", value: 'extended_stats', requiresField: true, supportsMissing: true, supportsInlineScript: true}, + {text: "Percentiles", value: 'percentiles', requiresField: true, supportsMissing: true, supportsInlineScript: true}, + {text: "Unique Count", value: "cardinality", requiresField: true, supportsMissing: true}, {text: "Moving Average", value: 'moving_avg', requiresField: false, isPipelineAgg: true }, {text: "Derivative", value: 'derivative', requiresField: false, isPipelineAgg: true }, - {text: "Unique Count", value: "cardinality", requiresField: true}, {text: "Raw Document", value: "raw_document", requiresField: false} ],