From 8ea9c965c3703a532fd1072e23e92fad6653d802 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Thu, 25 Apr 2019 11:51:04 -0600 Subject: [PATCH 1/2] Copy the aws config beforing modifying --- x-pack/metricbeat/module/aws/ec2/ec2.go | 7 ++++--- .../module/aws/s3_daily_storage/s3_daily_storage.go | 5 +++-- x-pack/metricbeat/module/aws/s3_request/s3_request.go | 5 +++-- x-pack/metricbeat/module/aws/sqs/sqs.go | 7 ++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/x-pack/metricbeat/module/aws/ec2/ec2.go b/x-pack/metricbeat/module/aws/ec2/ec2.go index e0300572d9f..4ffa0c6bd97 100644 --- a/x-pack/metricbeat/module/aws/ec2/ec2.go +++ b/x-pack/metricbeat/module/aws/ec2/ec2.go @@ -76,8 +76,9 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { } for _, regionName := range m.MetricSet.RegionsList { - m.MetricSet.AwsConfig.Region = regionName - svcEC2 := ec2.New(*m.MetricSet.AwsConfig) + awsConfig := *m.MetricSet.AwsConfig + awsConfig.Region = regionName + svcEC2 := ec2.New(awsConfig) instanceIDs, instancesOutputs, err := getInstancesPerRegion(svcEC2) if err != nil { err = errors.Wrap(err, "getInstancesPerRegion failed, skipping region "+regionName) @@ -86,7 +87,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { continue } - svcCloudwatch := cloudwatch.New(*m.MetricSet.AwsConfig) + svcCloudwatch := cloudwatch.New(awsConfig) namespace := "AWS/EC2" listMetricsOutput, err := aws.GetListMetricsOutput(namespace, regionName, svcCloudwatch) if err != nil { diff --git a/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go b/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go index d247becaaec..8bd30e76a0f 100644 --- a/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go +++ b/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go @@ -81,8 +81,9 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { // GetMetricData for AWS S3 from Cloudwatch for _, regionName := range m.MetricSet.RegionsList { - m.MetricSet.AwsConfig.Region = regionName - svcCloudwatch := cloudwatch.New(*m.MetricSet.AwsConfig) + awsConfig := *m.MetricSet.AwsConfig + awsConfig.Region = regionName + svcCloudwatch := cloudwatch.New(awsConfig) listMetricsOutputs, err := aws.GetListMetricsOutput(namespace, regionName, svcCloudwatch) if err != nil { err = errors.Wrap(err, "GetListMetricsOutput failed, skipping region "+regionName) diff --git a/x-pack/metricbeat/module/aws/s3_request/s3_request.go b/x-pack/metricbeat/module/aws/s3_request/s3_request.go index fab2d39719c..b765dfb0b23 100644 --- a/x-pack/metricbeat/module/aws/s3_request/s3_request.go +++ b/x-pack/metricbeat/module/aws/s3_request/s3_request.go @@ -80,8 +80,9 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { // GetMetricData for AWS S3 from Cloudwatch for _, regionName := range m.MetricSet.RegionsList { - m.MetricSet.AwsConfig.Region = regionName - svcCloudwatch := cloudwatch.New(*m.MetricSet.AwsConfig) + awsConfig := *m.MetricSet.AwsConfig + awsConfig.Region = regionName + svcCloudwatch := cloudwatch.New(awsConfig) listMetricsOutputs, err := aws.GetListMetricsOutput(namespace, regionName, svcCloudwatch) if err != nil { m.Logger().Error(err.Error()) diff --git a/x-pack/metricbeat/module/aws/sqs/sqs.go b/x-pack/metricbeat/module/aws/sqs/sqs.go index d40baec5fcc..423909c6646 100644 --- a/x-pack/metricbeat/module/aws/sqs/sqs.go +++ b/x-pack/metricbeat/module/aws/sqs/sqs.go @@ -76,9 +76,10 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { } for _, regionName := range m.MetricSet.RegionsList { - m.MetricSet.AwsConfig.Region = regionName - svcCloudwatch := cloudwatch.New(*m.MetricSet.AwsConfig) - svcSQS := sqs.New(*m.MetricSet.AwsConfig) + awsConfig := *m.MetricSet.AwsConfig + awsConfig.Region = regionName + svcCloudwatch := cloudwatch.New(awsConfig) + svcSQS := sqs.New(awsConfig) // Get queueUrls for each region queueURLs, err := getQueueUrls(svcSQS) From cdfcc341de2eeabf90e486082e2558268508c232 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Fri, 26 Apr 2019 09:37:58 -0600 Subject: [PATCH 2/2] Switch to use copy method from aws-go-sdk-v2 --- x-pack/metricbeat/module/aws/ec2/ec2.go | 2 +- .../module/aws/s3_daily_storage/s3_daily_storage.go | 4 ++-- x-pack/metricbeat/module/aws/s3_request/s3_request.go | 4 ++-- x-pack/metricbeat/module/aws/sqs/sqs.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/metricbeat/module/aws/ec2/ec2.go b/x-pack/metricbeat/module/aws/ec2/ec2.go index 4ffa0c6bd97..55255c69069 100644 --- a/x-pack/metricbeat/module/aws/ec2/ec2.go +++ b/x-pack/metricbeat/module/aws/ec2/ec2.go @@ -76,7 +76,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { } for _, regionName := range m.MetricSet.RegionsList { - awsConfig := *m.MetricSet.AwsConfig + awsConfig := m.MetricSet.AwsConfig.Copy() awsConfig.Region = regionName svcEC2 := ec2.New(awsConfig) instanceIDs, instancesOutputs, err := getInstancesPerRegion(svcEC2) diff --git a/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go b/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go index 8bd30e76a0f..3c3b8273b3a 100644 --- a/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go +++ b/x-pack/metricbeat/module/aws/s3_daily_storage/s3_daily_storage.go @@ -81,7 +81,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { // GetMetricData for AWS S3 from Cloudwatch for _, regionName := range m.MetricSet.RegionsList { - awsConfig := *m.MetricSet.AwsConfig + awsConfig := m.MetricSet.AwsConfig.Copy() awsConfig.Region = regionName svcCloudwatch := cloudwatch.New(awsConfig) listMetricsOutputs, err := aws.GetListMetricsOutput(namespace, regionName, svcCloudwatch) @@ -143,7 +143,7 @@ func getBucketNames(listMetricsOutputs []cloudwatch.Metric) (bucketNames []strin } func constructMetricQueries(listMetricsOutputs []cloudwatch.Metric, periodInSec int) []cloudwatch.MetricDataQuery { - metricDataQueries := []cloudwatch.MetricDataQuery{} + var metricDataQueries []cloudwatch.MetricDataQuery metricDataQueryEmpty := cloudwatch.MetricDataQuery{} metricNames := []string{"NumberOfObjects", "BucketSizeBytes"} for i, listMetric := range listMetricsOutputs { diff --git a/x-pack/metricbeat/module/aws/s3_request/s3_request.go b/x-pack/metricbeat/module/aws/s3_request/s3_request.go index b765dfb0b23..30a4f491191 100644 --- a/x-pack/metricbeat/module/aws/s3_request/s3_request.go +++ b/x-pack/metricbeat/module/aws/s3_request/s3_request.go @@ -80,7 +80,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { // GetMetricData for AWS S3 from Cloudwatch for _, regionName := range m.MetricSet.RegionsList { - awsConfig := *m.MetricSet.AwsConfig + awsConfig := m.MetricSet.AwsConfig.Copy() awsConfig.Region = regionName svcCloudwatch := cloudwatch.New(awsConfig) listMetricsOutputs, err := aws.GetListMetricsOutput(namespace, regionName, svcCloudwatch) @@ -172,7 +172,7 @@ func createMetricDataQuery(metric cloudwatch.Metric, periodInSec int, index int) } func constructMetricQueries(listMetricsOutputs []cloudwatch.Metric, periodInSec int) []cloudwatch.MetricDataQuery { - metricDataQueries := []cloudwatch.MetricDataQuery{} + var metricDataQueries []cloudwatch.MetricDataQuery metricDataQueryEmpty := cloudwatch.MetricDataQuery{} dailyMetricNames := []string{"NumberOfObjects", "BucketSizeBytes"} for i, listMetric := range listMetricsOutputs { diff --git a/x-pack/metricbeat/module/aws/sqs/sqs.go b/x-pack/metricbeat/module/aws/sqs/sqs.go index 423909c6646..ffd6d560b01 100644 --- a/x-pack/metricbeat/module/aws/sqs/sqs.go +++ b/x-pack/metricbeat/module/aws/sqs/sqs.go @@ -76,7 +76,7 @@ func (m *MetricSet) Fetch(report mb.ReporterV2) error { } for _, regionName := range m.MetricSet.RegionsList { - awsConfig := *m.MetricSet.AwsConfig + awsConfig := m.MetricSet.AwsConfig.Copy() awsConfig.Region = regionName svcCloudwatch := cloudwatch.New(awsConfig) svcSQS := sqs.New(awsConfig) @@ -142,7 +142,7 @@ func getQueueUrls(svc sqsiface.SQSAPI) ([]string, error) { } func constructMetricQueries(listMetricsOutput []cloudwatch.Metric, period int64) []cloudwatch.MetricDataQuery { - metricDataQueries := []cloudwatch.MetricDataQuery{} + var metricDataQueries []cloudwatch.MetricDataQuery for i, listMetric := range listMetricsOutput { metricDataQuery := createMetricDataQuery(listMetric, i, period) metricDataQueries = append(metricDataQueries, metricDataQuery)