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

Add aws componenets benchmark #812

Merged

Conversation

bhautikpip
Copy link
Contributor

Added benchmarks for aws idgenerator, propagator and for sampling and non-sampling scenarios

@bhautikpip
Copy link
Contributor Author

@Aneurysm9 @MrAlias Can you review this PR?

propagators/aws/xray/idgenerator_test.go Outdated Show resolved Hide resolved
propagators/aws/xray/sampled_unsampled_span_test.go Outdated Show resolved Hide resolved
@bhautikpip bhautikpip requested a review from Aneurysm9 June 7, 2021 19:06
@codecov
Copy link

codecov bot commented Jun 7, 2021

Codecov Report

Merging #812 (83fc5f6) into main (2ca6018) will increase coverage by 0.0%.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #812   +/-   ##
=====================================
  Coverage   78.7%   78.8%           
=====================================
  Files         62      62           
  Lines       2707    2707           
=====================================
+ Hits        2133    2135    +2     
+ Misses       441     440    -1     
+ Partials     133     132    -1     
Impacted Files Coverage Δ
...n/github.com/Shopify/sarama/otelsarama/producer.go 94.8% <0.0%> (+2.0%) ⬆️

@bhautikpip bhautikpip requested a review from Aneurysm9 June 8, 2021 07:30
@bhautikpip
Copy link
Contributor Author

bhautikpip commented Jun 8, 2021

@Aneurysm9 not sure but getting code cov failure in tests due to some missing token issue.

codecov/codecov-action#258

@Aneurysm9
Copy link
Member

@Aneurysm9 not sure but getting code cov failure in tests due to some missing token issue.

codecov/codecov-action#258

GitHub Actions was having a struggle the other day. I've kicked off the CI process again, we'll see if it's feeling better today!

Comment on lines 128 to 129
otel.SetTracerProvider(curTp)
otel.SetTextMapPropagator(curProp)
Copy link
Contributor

Choose a reason for hiding this comment

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

These are no-ops. The global set operation is only ever performed once.

https://github.com/open-telemetry/opentelemetry-go/blob/651409851900230cc2f8c62a5ec69a7ac9307847/internal/global/state.go#L74

https://github.com/open-telemetry/opentelemetry-go/blob/651409851900230cc2f8c62a5ec69a7ac9307847/internal/global/state.go#L50

It would make more sense to define tracer with TracerProvider in an init function and skip any dealing with the TextMapPropagtor (it doesn't look used in any of these benchmarks).

Copy link
Contributor Author

@bhautikpip bhautikpip Jun 17, 2021

Choose a reason for hiding this comment

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

Are you suggesting to add trace.Start in init function ? As per @Aneurysm9's suggestion I have added restoring logic of propagators so had to add those in every benchmark.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm suggesting you create a TracerProvider in an init function that you then use to set the value of a package level tracer variable with.

The restoring logic you added does nothing, the second call is a no-op. You should not use the global tracer here.

span.SetAttributes(attribute.Key("example attribute 2").String("value 2"))
}

func startAndEndUnSampledSpan() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The created span in this function will come from a TracerProvider that has an AlwaysSample Sampler. This span will be sampled and this function is no different, as far as I can see, from startAndEndSampledSpan. Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callout. I will probably add tracer with NeverSample config.

@bhautikpip bhautikpip requested a review from MrAlias June 17, 2021 17:39
@MrAlias
Copy link
Contributor

MrAlias commented Jun 18, 2021

I see my review has been re-requested, but the issues I raised on my first review have not been addressed AFAIK. Can you link me to the fixes if I missed them?

@bhautikpip
Copy link
Contributor Author

I see my review has been re-requested, but the issues I raised on my first review have not been addressed AFAIK. Can you link me to the fixes if I missed them?

Yeah re-request review was done by mistake I still have to address your comments.

@bhautikpip
Copy link
Contributor Author

I see my review has been re-requested, but the issues I raised on my first review have not been addressed AFAIK. Can you link me to the fixes if I missed them?

@MrAlias Submitted new changes to address your query please take a look.

"go.opentelemetry.io/otel/trace"
)

var tracer = otel.Tracer("sample-app")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var tracer = otel.Tracer("sample-app")
var tracer trace.Tracer

Comment on lines 72 to 79
idg := NewIDGenerator()

tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithIDGenerator(idg),
)

otel.SetTracerProvider(tp)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
idg := NewIDGenerator()
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithIDGenerator(idg),
)
otel.SetTracerProvider(tp)
tracer = sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithIDGenerator(NewIDGenerator()),
).Tracer("sample-app")

Comment on lines 29 to 37
func startAndEndSampledSpan() {
var span trace.Span
_, span = tracer.Start(
context.Background(),
"Example Trace",
)

defer span.End()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func startAndEndSampledSpan() {
var span trace.Span
_, span = tracer.Start(
context.Background(),
"Example Trace",
)
defer span.End()
}

Comment on lines 83 to 85
for i := 0; i < b.N; i++ {
startAndEndSampledSpan()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for i := 0; i < b.N; i++ {
startAndEndSampledSpan()
}
for i := 0; i < b.N; i++ {
_, span := tracer.Start(context.Background(), "Example Trace")
span.End()
}

Comment on lines 39 to 46
func startAndEndNestedSampledSpan() {
var span trace.Span
ctx, span := tracer.Start(context.Background(), "Parent operation...")
defer span.End()

_, span = tracer.Start(ctx, "Sub operation...")
defer span.End()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func startAndEndNestedSampledSpan() {
var span trace.Span
ctx, span := tracer.Start(context.Background(), "Parent operation...")
defer span.End()
_, span = tracer.Start(ctx, "Sub operation...")
defer span.End()
}

Comment on lines 89 to 91
for i := 0; i < b.N; i++ {
startAndEndNestedSampledSpan()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for i := 0; i < b.N; i++ {
startAndEndNestedSampledSpan()
}
ctx, parent := tracer.Start(context.Background(), "Parent operation...")
defer parent.End()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, span := tracer.Start(ctx, "Sub operation...")
span.End()
}

Comment on lines 48 to 57
func getCurrentSampledSpan() trace.Span {
var span trace.Span
ctx, span := tracer.Start(
context.Background(),
"Example Trace",
)
defer span.End()

return trace.SpanFromContext(ctx)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func getCurrentSampledSpan() trace.Span {
var span trace.Span
ctx, span := tracer.Start(
context.Background(),
"Example Trace",
)
defer span.End()
return trace.SpanFromContext(ctx)
}

Comment on lines 94 to 98
func BenchmarkGetCurrentSampledSpan(b *testing.B) {
for i := 0; i < b.N; i++ {
getCurrentSampledSpan()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This provides no additional bencmarking of this package. The creation and ending of a span is already benchmarked and this only adds a benchmark on retrieving a span from a context, something that is not a function of this package.

Suggested change
func BenchmarkGetCurrentSampledSpan(b *testing.B) {
for i := 0; i < b.N; i++ {
getCurrentSampledSpan()
}
}

Comment on lines 100 to 104
func BenchmarkAddAttributesToSampledSpan(b *testing.B) {
for i := 0; i < b.N; i++ {
addAttributesToSampledSpan()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar here, this tests the AddAttributes method of the default SDK and does not provide any relevant benchmark for this package.

Suggested change
func BenchmarkAddAttributesToSampledSpan(b *testing.B) {
for i := 0; i < b.N; i++ {
addAttributesToSampledSpan()
}
}

Comment on lines 59 to 69
func addAttributesToSampledSpan() {
var span trace.Span
_, span = tracer.Start(
context.Background(),
"Example Trace",
)
defer span.End()

span.SetAttributes(attribute.Key("example attribute 1").String("value 1"))
span.SetAttributes(attribute.Key("example attribute 2").String("value 2"))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func addAttributesToSampledSpan() {
var span trace.Span
_, span = tracer.Start(
context.Background(),
"Example Trace",
)
defer span.End()
span.SetAttributes(attribute.Key("example attribute 1").String("value 1"))
span.SetAttributes(attribute.Key("example attribute 2").String("value 2"))
}

@@ -0,0 +1,104 @@
// Copyright The OpenTelemetry Authors
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should be renamed to something descriptive of the benchmarks included. I.e. idgenerator_benchmark_test.go

@bhautikpip bhautikpip requested a review from MrAlias June 18, 2021 17:40
@Aneurysm9 Aneurysm9 merged commit 91e5180 into open-telemetry:main Jun 18, 2021
plantfansam referenced this pull request in plantfansam/opentelemetry-go-contrib Mar 18, 2022
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@pellared pellared added this to the untracked milestone Nov 8, 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.

4 participants