From 9fd31aed40240a919c6d2add88bf537681496a52 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 30 Jun 2020 23:09:35 +0800 Subject: [PATCH 1/3] [MetricBeat] add param `aws_partition` to support aws-cn, aws-us-gov regions (#19423) * add params `aws_partition` to support other aws region: aws-cn, aws-us-gov (cherry picked from commit 1ea8c84edcc846acf3b249732de2a3fb05cce067) --- CHANGELOG.next.asciidoc | 1 + x-pack/libbeat/common/aws/credentials.go | 1 + x-pack/libbeat/docs/aws-credentials-config.asciidoc | 1 + x-pack/metricbeat/module/aws/aws.go | 12 ++++++++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 6f2a38ba89f..3a6b760a852 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -302,6 +302,7 @@ field. You can revert this change by configuring tags for the module and omittin - Fix incorrect usage of hints builder when exposed port is a substring of the hint {pull}19052[19052] - Stop counterCache only when already started {pull}19103[19103] - Remove dedot for tag values in aws module. {issue}19112[19112] {pull}19221[19221] +- Add param `aws_partition` to support aws-cn, aws-us-gov regions. {issue}18850[18850] {pull}19423[19423] - Fix bug incorrect parsing of float numbers as integers in Couchbase module {issue}18949[18949] {pull}19055[19055] *Packetbeat* diff --git a/x-pack/libbeat/common/aws/credentials.go b/x-pack/libbeat/common/aws/credentials.go index c9a5f5de9b2..97d06a6a255 100644 --- a/x-pack/libbeat/common/aws/credentials.go +++ b/x-pack/libbeat/common/aws/credentials.go @@ -24,6 +24,7 @@ type ConfigAWS struct { SharedCredentialFile string `config:"shared_credential_file"` Endpoint string `config:"endpoint"` RoleArn string `config:"role_arn"` + AWSPartition string `config:"aws_partition"` } // GetAWSCredentials function gets aws credentials from the config. diff --git a/x-pack/libbeat/docs/aws-credentials-config.asciidoc b/x-pack/libbeat/docs/aws-credentials-config.asciidoc index cee77fd80a8..be536f433ab 100644 --- a/x-pack/libbeat/docs/aws-credentials-config.asciidoc +++ b/x-pack/libbeat/docs/aws-credentials-config.asciidoc @@ -11,6 +11,7 @@ To configure AWS credentials, either put the credentials into the {beatname_uc} * *shared_credential_file*: directory of the shared credentials file. * *endpoint*: URL of the entry point for an AWS web service. * *role_arn*: AWS IAM Role to assume. +* *aws_partition*: AWS region parttion name, value is one of `aws, aws-cn, aws-us-gov`, default is `aws`. [float] ==== Supported Formats diff --git a/x-pack/metricbeat/module/aws/aws.go b/x-pack/metricbeat/module/aws/aws.go index 469fe7c334f..983d44ee47b 100644 --- a/x-pack/metricbeat/module/aws/aws.go +++ b/x-pack/metricbeat/module/aws/aws.go @@ -93,8 +93,16 @@ func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) { base.Logger().Debug("Metricset level config for period: ", metricSet.Period) base.Logger().Debug("Metricset level config for tags filter: ", metricSet.TagsFilter) - // Get IAM account name - awsConfig.Region = "us-east-1" + // Get IAM account name, set region by aws_partition, default is aws global partition + // refer https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html + switch config.AWSConfig.AWSPartition { + case "aws-cn": + awsConfig.Region = "cn-north-1" + case "aws-us-gov": + awsConfig.Region = "us-gov-east-1" + default: + awsConfig.Region = "us-east-1" + } svcIam := iam.New(awscommon.EnrichAWSConfigWithEndpoint( config.AWSConfig.Endpoint, "iam", "", awsConfig)) req := svcIam.ListAccountAliasesRequest(&iam.ListAccountAliasesInput{}) From 810887fc3e259687909052b4cc22a3dc9cf56a98 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Tue, 30 Jun 2020 12:36:27 -0600 Subject: [PATCH 2/3] update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 42f6a136848..add6e8d5955 100644 --- a/go.mod +++ b/go.mod @@ -160,7 +160,7 @@ require ( golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 golang.org/x/text v0.3.2 golang.org/x/time v0.0.0-20191024005414-555d28b269f0 - golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f + golang.org/x/tools v0.0.0-20200630154851-b2d8b0336632 google.golang.org/api v0.15.0 google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb google.golang.org/grpc v1.29.1 From f082f55bde5c064136fca8322bd08366eb5dadf1 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Wed, 1 Jul 2020 09:05:12 -0600 Subject: [PATCH 3/3] update changelog --- CHANGELOG.next.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 3a6b760a852..13fd4409018 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -302,7 +302,6 @@ field. You can revert this change by configuring tags for the module and omittin - Fix incorrect usage of hints builder when exposed port is a substring of the hint {pull}19052[19052] - Stop counterCache only when already started {pull}19103[19103] - Remove dedot for tag values in aws module. {issue}19112[19112] {pull}19221[19221] -- Add param `aws_partition` to support aws-cn, aws-us-gov regions. {issue}18850[18850] {pull}19423[19423] - Fix bug incorrect parsing of float numbers as integers in Couchbase module {issue}18949[18949] {pull}19055[19055] *Packetbeat* @@ -595,6 +594,7 @@ field. You can revert this change by configuring tags for the module and omittin - Add dashboards for googlecloud load balancing metricset. {pull}18369[18369] - Update Couchbase to version 6.5 {issue}18595[18595] {pull}19055[19055] - Add support for v1 consumer API in Cloud Foundry module, use it by default. {pull}19268[19268] +- Add param `aws_partition` to support aws-cn, aws-us-gov regions. {issue}18850[18850] {pull}19423[19423] *Packetbeat*