From f6cb01d38a0b406e6c6318f295dc77c61ccefdd5 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 19 Jun 2018 17:41:26 +0900 Subject: [PATCH] show all CloudWatch regions --- pkg/tsdb/cloudwatch/metric_find_query.go | 2 +- .../datasource/cloudwatch/config_ctrl.ts | 24 ++++++++++++++++++- .../cloudwatch/partials/config.html | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg/tsdb/cloudwatch/metric_find_query.go b/pkg/tsdb/cloudwatch/metric_find_query.go index 64e5118e579..214b6ccbc67 100644 --- a/pkg/tsdb/cloudwatch/metric_find_query.go +++ b/pkg/tsdb/cloudwatch/metric_find_query.go @@ -234,7 +234,7 @@ func parseMultiSelectValue(input string) []string { // Please update the region list in public/app/plugins/datasource/cloudwatch/partials/config.html func (e *CloudWatchExecutor) handleGetRegions(ctx context.Context, parameters *simplejson.Json, queryContext *tsdb.TsdbQuery) ([]suggestData, error) { regions := []string{ - "cn-north-1", "cn-northwest-1", "us-gov-west-1", "us-isob-east-1", "us-iso-east-1", + "cn-north-1", "cn-northwest-1", "us-gov-east-1", "us-gov-west-1", "us-isob-east-1", "us-iso-east-1", } err := e.ensureClientSession("us-east-1") diff --git a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts index ff0d39944ca..1ff744854f5 100644 --- a/public/app/plugins/datasource/cloudwatch/config_ctrl.ts +++ b/public/app/plugins/datasource/cloudwatch/config_ctrl.ts @@ -1,17 +1,20 @@ export class CloudWatchConfigCtrl { static templateUrl = 'partials/config.html'; current: any; + $http: any; accessKeyExist = false; secretKeyExist = false; /** @ngInject */ - constructor($scope) { + constructor($scope, $http) { this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp'; this.current.jsonData.authType = this.current.jsonData.authType || 'credentials'; this.accessKeyExist = this.current.secureJsonFields.accessKey; this.secretKeyExist = this.current.secureJsonFields.secretKey; + this.$http = $http; + this.getRegions(); } resetAccessKey() { @@ -36,4 +39,23 @@ export class CloudWatchConfigCtrl { { name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' }, { name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' }, ]; + + regions = []; + + getRegions() { + this.$http.get('https://ip-ranges.amazonaws.com/ip-ranges.json').then(ip_ranges => { + let regions = {}; + ip_ranges.data.prefixes + .map(p => { + return p.region; + }) + .filter(r => { + return r !== 'GLOBAL'; + }) + .forEach(r => { + regions[r] = true; + }); + this.regions = Object.keys(regions).sort(); + }); + } } diff --git a/public/app/plugins/datasource/cloudwatch/partials/config.html b/public/app/plugins/datasource/cloudwatch/partials/config.html index e5ab0910cba..40249d32b7e 100644 --- a/public/app/plugins/datasource/cloudwatch/partials/config.html +++ b/public/app/plugins/datasource/cloudwatch/partials/config.html @@ -39,7 +39,7 @@
- + Specify the region, such as for US West (Oregon) use ` us-west-2 ` as the region.