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

Fix concurrency in emf exporter #2571

Merged
merged 1 commit into from
Mar 9, 2021

Conversation

bjrara
Copy link
Contributor

@bjrara bjrara commented Mar 7, 2021

Why do we need it?
This PR fixes the concurrency issue described in aws-observability/aws-otel-collector#387, and does a code refactoring to pusher.

We add two locks, one for logEventBatch instance update and one for streamToken replacement to ensure they're both goroutine safe. It also fixes an issue of deciding where a new logEvent should go to when the current batch could not meet the requirement before or after the new entry appending. In today's implementation, it is added to the old batch, and this PR changes it to be added to a newly created batch.

@codecov
Copy link

codecov bot commented Mar 7, 2021

Codecov Report

Merging #2571 (2a37444) into main (99f2d89) will increase coverage by 0.01%.
The diff coverage is 97.40%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2571      +/-   ##
==========================================
+ Coverage   91.31%   91.32%   +0.01%     
==========================================
  Files         429      429              
  Lines       21457    21467      +10     
==========================================
+ Hits        19593    19605      +12     
+ Misses       1395     1394       -1     
+ Partials      469      468       -1     
Flag Coverage Δ
integration 69.24% <ø> (+0.06%) ⬆️
unit 90.22% <97.40%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
exporter/awsemfexporter/pusher.go 98.38% <97.36%> (+1.89%) ⬆️
exporter/awsemfexporter/metric_translator.go 97.70% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99f2d89...2a37444. Read the comment docs.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you summarize

exporter/awsemfexporter/emf_exporter.go Outdated Show resolved Hide resolved
exporter/awsemfexporter/pusher.go Outdated Show resolved Hide resolved
exporter/awsemfexporter/pusher.go Show resolved Hide resolved
@bjrara bjrara changed the title Fix concurrency and performance issues in emf exporter Fix concurrency in emf exporter Mar 7, 2021
@bjrara
Copy link
Contributor Author

bjrara commented Mar 7, 2021

Using channels could achieve the same goal, but we found it would make codes more complex to read to maintain the same semantics of the error returned by ConsumeMetrics from the previous implementation - error should be the very end of the request processing.

Copy link
Member

@mxiamxia mxiamxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fixing.

Comment on lines +77 to +91
if *logEvent.InputLogEvent.Timestamp == int64(0) {
logEvent.InputLogEvent.Timestamp = aws.Int64(logEvent.LogGeneratedTime.UnixNano() / int64(time.Millisecond))
}
return logEvent
if len(*logEvent.InputLogEvent.Message) == 0 {
return errors.New("empty log event message")
}

//http:https://docs.aws.amazon.com/goto/SdkForGoV1/logs-2014-03-28/PutLogEvents
//* None of the log events in the batch can be more than 2 hours in the
//future.
//* None of the log events in the batch can be older than 14 days or the
//retention period of the log group.
currentTime := time.Now().UTC()
utcTime := time.Unix(0, *logEvent.InputLogEvent.Timestamp*int64(time.Millisecond)).UTC()
duration := currentTime.Sub(utcTime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting all the data validation logic in one place.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small point, mostly LGTM

exporter/awsemfexporter/pusher.go Outdated Show resolved Hide resolved
@bogdandrutu bogdandrutu merged commit bdbc192 into open-telemetry:main Mar 9, 2021
@bjrara bjrara deleted the emf_concurrency branch March 9, 2021 20:06
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants