Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy the aws config before modifying to avoid concurrent errors #11938

Merged
merged 2 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions x-pack/metricbeat/module/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Copy()
awsConfig.Region = regionName
svcEC2 := ec2.New(awsConfig)
instanceIDs, instancesOutputs, err := getInstancesPerRegion(svcEC2)
if err != nil {
err = errors.Wrap(err, "getInstancesPerRegion failed, skipping region "+regionName)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Copy()
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)
Expand Down Expand Up @@ -142,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 {
Expand Down
7 changes: 4 additions & 3 deletions x-pack/metricbeat/module/aws/s3_request/s3_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Copy()
awsConfig.Region = regionName
svcCloudwatch := cloudwatch.New(awsConfig)
listMetricsOutputs, err := aws.GetListMetricsOutput(namespace, regionName, svcCloudwatch)
if err != nil {
m.Logger().Error(err.Error())
Expand Down Expand Up @@ -171,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 {
Expand Down
9 changes: 5 additions & 4 deletions x-pack/metricbeat/module/aws/sqs/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Copy()
awsConfig.Region = regionName
svcCloudwatch := cloudwatch.New(awsConfig)
svcSQS := sqs.New(awsConfig)

// Get queueUrls for each region
queueURLs, err := getQueueUrls(svcSQS)
Expand Down Expand Up @@ -141,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)
Expand Down