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

Improve performance of internal traces to jaeger proto translation #906

Conversation

dmitryax
Copy link
Member

@dmitryax dmitryax commented May 1, 2020

Benchmark results:

Before:

BenchmarkInternalTracesToJaegerProto-12       611580          1696 ns/op        2952 B/op         17 allocs/op

After:

BenchmarkInternalTracesToJaegerProto-12       837252          1299 ns/op        2024 B/op         13 allocs/op

@codecov-io
Copy link

codecov-io commented May 1, 2020

Codecov Report

Merging #906 into master will increase coverage by 0.00%.
The diff coverage is 88.88%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #906   +/-   ##
=======================================
  Coverage   85.12%   85.12%           
=======================================
  Files         174      174           
  Lines       13376    13410   +34     
=======================================
+ Hits        11386    11415   +29     
- Misses       1543     1545    +2     
- Partials      447      450    +3     
Impacted Files Coverage Δ
translator/trace/jaeger/traces_to_jaegerproto.go 79.75% <88.88%> (-0.06%) ⬇️
translator/internaldata/resource_to_oc.go 76.47% <0.00%> (+2.94%) ⬆️

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 27b2d65...97fe397. Read the comment docs.

Comment on lines 123 to 133
if attrsCount == 0 {
return &process
}

tags := make([]model.KeyValue, 0, attrsCount)
process.Tags = appendTagsFromResourceAttributes(tags, attrs)
return &process

}

func attributesToJaegerProtoTags(attrs pdata.AttributeMap) []model.KeyValue {
func appendTagsFromResourceAttributes(dest []model.KeyValue, attrs pdata.AttributeMap) []model.KeyValue {
Copy link
Member

Choose a reason for hiding this comment

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

Simpler code:

process.Tags = appendTagsFromResourceAttributes(attrsCount, attrs)
return &process

func appendTagsFromResourceAttributes(attrs pdata.AttributeMap) []model.KeyValue {
	if attrs.Cap() == 0 {
		return nil
	}
        dest = make([]model.KeyValue, 0, attrs.Cap())
}

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not always the case that we can use attrs.Cap() as capacity for tags slice, that's why I moved it outside

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, confused, why, because we allocate 1 extra element?

Copy link
Member Author

Choose a reason for hiding this comment

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

The similar function appendTagsFromAttributes needs to allocate more than attrs.Cap(), I kept the same approach here as well

This PR also fixes an attribute mutation bug when "service.name" got removed from resource data structure
@dmitryax dmitryax force-pushed the feature/dmitryax/improve-otlp-to-jaeger-performance branch from 203d477 to 97fe397 Compare May 2, 2020 00:55
@dmitryax
Copy link
Member Author

dmitryax commented May 2, 2020

@bogdandrutu PTAL

@bogdandrutu bogdandrutu merged commit 24c1569 into open-telemetry:master May 2, 2020
bogdandrutu referenced this pull request in bogdandrutu/opentelemetry-collector May 2, 2020
)

This PR also fixes an attribute mutation bug when "service.name" got removed from resource data structure
bogdandrutu referenced this pull request in bogdandrutu/opentelemetry-collector May 3, 2020
)

This PR also fixes an attribute mutation bug when "service.name" got removed from resource data structure
wyTrivail pushed a commit to mxiamxia/opentelemetry-collector that referenced this pull request Jul 13, 2020
…pen-telemetry#906)

This PR also fixes an attribute mutation bug when "service.name" got removed from resource data structure
Troels51 pushed a commit to Troels51/opentelemetry-collector that referenced this pull request Jul 5, 2024
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.

3 participants