Skip to content

Commit

Permalink
Fix race condition in end time update for discovery jobs. (#375)
Browse files Browse the repository at this point in the history
This fixes a data race happening when goroutines for jobs of type discovery
attempt to update the `endtime` variable.
  • Loading branch information
cristiangreco authored Jul 9, 2021
1 parent 211d18f commit 5237bb3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
run: go build -o yace cmd/yace/main.go

- name: Test
run: go test -v ./...
run: go test -v -race ./...
6 changes: 3 additions & 3 deletions pkg/abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func scrapeAwsData(config ScrapeConf, now time.Time, metricsPerQuery int, fips,
asgClient: createASGSession(&region, role, fips),
ec2Client: createEC2Session(&region, role, fips),
}
var resources []*tagsData
var metrics []*cloudwatchData
resources, metrics, endtime = scrapeDiscoveryJobUsingMetricData(discoveryJob, region, accountId, config.Discovery.ExportedTagsOnMetrics, clientTag, clientCloudwatch, now, metricsPerQuery, floatingTimeWindow, tagSemaphore)

resources, metrics, end := scrapeDiscoveryJobUsingMetricData(discoveryJob, region, accountId, config.Discovery.ExportedTagsOnMetrics, clientTag, clientCloudwatch, now, metricsPerQuery, floatingTimeWindow, tagSemaphore)
mux.Lock()
awsInfoData = append(awsInfoData, resources...)
cwData = append(cwData, metrics...)
endtime = end
mux.Unlock()
}(discoveryJob, region, role)
}
Expand Down

0 comments on commit 5237bb3

Please sign in to comment.