From 6e4ed4debd0aa84067d6e0d03abbce66a5d3445a Mon Sep 17 00:00:00 2001 From: Steven Arnott Date: Mon, 19 Sep 2016 11:12:43 -0400 Subject: [PATCH 1/7] Altered DB for Prefix (#6062) --- docs/sources/installation/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index 54cb2d95fee..4c7f63d53ae 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -428,7 +428,7 @@ session provider you have configured. - **mysql:** go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1:3306)/database_name` - **postgres:** ex: user=a password=b host=localhost port=5432 dbname=c sslmode=disable - **memcache:** ex: 127.0.0.1:11211 -- **redis:** ex: `addr=127.0.0.1:6379,pool_size=100,db=grafana` +- **redis:** ex: `addr=127.0.0.1:6379,pool_size=100,prefix=grafana` If you use MySQL or Postgres as the session store you need to create the session table manually. From 490141da8252aaf80c6bd0660ee253cecdbbfda1 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Sat, 19 Mar 2016 23:02:42 +0900 Subject: [PATCH 2/7] (cloudwatch) expand multi select template variable --- .../datasource/cloudwatch/datasource.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index d9fc6464491..c98c7e09b2b 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -23,6 +23,7 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) { var queries = []; options = angular.copy(options); + options.targets = this.expandTemplateVariable(options.targets); _.each(options.targets, function(target) { if (target.hide || !target.namespace || !target.metricName || _.isEmpty(target.statistics)) { return; @@ -337,6 +338,36 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) { }); } + this.expandTemplateVariable = function(targets) { + return _.chain(targets) + .map(function(target) { + var dimensionKey = null; + var variableName = null; + _.each(target.dimensions, function(v, k) { + if (templateSrv.variableExists(v)) { + dimensionKey = k; + variableName = v; + } + }); + if (dimensionKey) { + var variable = _.find(templateSrv.variables, function(variable) { + return templateSrv.containsVariable(variableName, variable.name); + }); + return _.chain(variable.options) + .filter(function(v) { + return v.selected; + }) + .map(function(v) { + var t = angular.copy(target); + t.dimensions[dimensionKey] = v.value; + return t; + }).value(); + } else { + return [target]; + } + }).flatten().value(); + }; + this.convertToCloudWatchTime = function(date, roundUp) { if (_.isString(date)) { date = dateMath.parse(date, roundUp); From 540436e9d5f9f068882e952ae65498e09a9748a7 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Wed, 20 Apr 2016 21:06:53 +0900 Subject: [PATCH 3/7] inject templateSrv --- public/app/plugins/datasource/cloudwatch/datasource.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index c98c7e09b2b..1a3d990eac6 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -23,7 +23,7 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) { var queries = []; options = angular.copy(options); - options.targets = this.expandTemplateVariable(options.targets); + options.targets = this.expandTemplateVariable(options.targets, templateSrv); _.each(options.targets, function(target) { if (target.hide || !target.namespace || !target.metricName || _.isEmpty(target.statistics)) { return; @@ -338,7 +338,7 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) { }); } - this.expandTemplateVariable = function(targets) { + this.expandTemplateVariable = function(targets, templateSrv) { return _.chain(targets) .map(function(target) { var dimensionKey = null; From 481cc012423c4d667babeb96ef0800b327526fcb Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 19 Apr 2016 23:27:18 +0900 Subject: [PATCH 4/7] (cloudwatch) add test for expand templater variables --- .../cloudwatch/specs/datasource_specs.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts index 86e085b3f6f..0b9b3b53fb6 100644 --- a/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/cloudwatch/specs/datasource_specs.ts @@ -98,6 +98,38 @@ describe('CloudWatchDatasource', function() { }); ctx.$rootScope.$apply(); }); + + it('should generate the correct targets by expanding template variables', function() { + var templateSrv = { + variables: [ + { + name: 'instance_id', + options: [ + { value: 'i-23456789', selected: false }, + { value: 'i-34567890', selected: true } + ] + } + ], + variableExists: function (e) { return true; }, + containsVariable: function (str, variableName) { return str.indexOf('$' + variableName) !== -1; } + }; + + var targets = [ + { + region: 'us-east-1', + namespace: 'AWS/EC2', + metricName: 'CPUUtilization', + dimensions: { + InstanceId: '$instance_id' + }, + statistics: ['Average'], + period: 300 + } + ]; + + var result = ctx.ds.expandTemplateVariable(targets, templateSrv); + expect(result[0].dimensions.InstanceId).to.be('i-34567890'); + }); }); function describeMetricFindQuery(query, func) { From 07cce5f6bd06a5a5e36b63da39efb2b24b2f5b04 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 6 Sep 2016 01:22:39 +0900 Subject: [PATCH 5/7] refactor --- .../datasource/cloudwatch/datasource.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index 1a3d990eac6..10bf4e1295c 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -338,7 +338,20 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) { }); } + this.getExpandedVariables = function(target, dimensionKey, variable) { + return _.chain(variable.options) + .filter(function(v) { + return v.selected; + }) + .map(function(v) { + var t = angular.copy(target); + t.dimensions[dimensionKey] = v.value; + return t; + }).value(); + }; + this.expandTemplateVariable = function(targets, templateSrv) { + var self = this; return _.chain(targets) .map(function(target) { var dimensionKey = null; @@ -353,15 +366,7 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) { var variable = _.find(templateSrv.variables, function(variable) { return templateSrv.containsVariable(variableName, variable.name); }); - return _.chain(variable.options) - .filter(function(v) { - return v.selected; - }) - .map(function(v) { - var t = angular.copy(target); - t.dimensions[dimensionKey] = v.value; - return t; - }).value(); + return self.getExpandedVariables(target, dimensionKey, variable); } else { return [target]; } From 71b5007ec7722d3a4ab4e6fb09694a15e6f67146 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 6 Sep 2016 01:51:10 +0900 Subject: [PATCH 6/7] refactor --- .../app/plugins/datasource/cloudwatch/datasource.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index 10bf4e1295c..4365c2e2596 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -354,17 +354,13 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) { var self = this; return _.chain(targets) .map(function(target) { - var dimensionKey = null; - var variableName = null; - _.each(target.dimensions, function(v, k) { - if (templateSrv.variableExists(v)) { - dimensionKey = k; - variableName = v; - } + var dimensionKey = _.findKey(target.dimensions, function(v) { + return templateSrv.variableExists(v); }); + if (dimensionKey) { var variable = _.find(templateSrv.variables, function(variable) { - return templateSrv.containsVariable(variableName, variable.name); + return templateSrv.containsVariable(target.dimensions[dimensionKey], variable.name); }); return self.getExpandedVariables(target, dimensionKey, variable); } else { From 46866add7e0f9bef50a8a72ea808743730a0dc97 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 20 Sep 2016 08:13:53 +0200 Subject: [PATCH 7/7] docs(changelog): add note about closing #5003 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 505a5f433bb..92f4ddfc586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * **Graphite**: Add support for groupByNode, closes [#5613](https://github.com/grafana/grafana/pull/5613) * **Influxdb**: Add support for elapsed(), closes [#5827](https://github.com/grafana/grafana/pull/5827) * **OAuth**: Add support for generic oauth, closes [#4718](https://github.com/grafana/grafana/pull/4718) +* **Cloudwatch**: Add support to expand multi select template variable, closes [#5003](https://github.com/grafana/grafana/pull/5003) ### Breaking changes * **SystemD**: Change systemd description, closes [#5971](https://github.com/grafana/grafana/pull/5971)