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
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dcc01de
added failure scenario when getting container fails
bhautikpip Feb 5, 2021
1dd54d9
fix test case failure
bhautikpip Feb 5, 2021
03f6fb4
add changelog
bhautikpip Feb 5, 2021
5919be5
Merge branch 'main' into main
bhautikpip Feb 5, 2021
ebd45b4
Merge branch 'main' into main
Aneurysm9 Feb 5, 2021
e1ff7d0
fix ecs resource detector bug
bhautikpip Feb 7, 2021
041d9b8
Merge branch 'main' of https://github.com/bhautikpip/opentelemetry-go…
bhautikpip Feb 7, 2021
e12a4b1
fix struct name as per golint suggestion
bhautikpip Feb 7, 2021
e906d2a
fix merge conflict
bhautikpip Feb 7, 2021
86c04d1
minor changes
bhautikpip Feb 7, 2021
047f5d0
added NewResourceDetector func and interface assertions
bhautikpip Feb 9, 2021
21db8fa
fix golint failure
bhautikpip Feb 9, 2021
5204d27
minor changes to address review comments
bhautikpip Feb 10, 2021
c9c1bca
Merge branch 'main' into main
MrAlias Feb 10, 2021
c956d4b
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
bhautikpip Feb 10, 2021
12c6c74
Merge branch 'main' of https://github.com/bhautikpip/opentelemetry-go…
bhautikpip Feb 10, 2021
e042a6f
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
bhautikpip Jun 3, 2021
6b2e3c3
added benchmarks for aws id generator and propagator
bhautikpip Jun 3, 2021
2622e4e
ran gofmt
bhautikpip Jun 3, 2021
c50fed8
ran precommit
bhautikpip Jun 3, 2021
ac3b67a
remove idgenerator and added logic to restore global state
bhautikpip Jun 7, 2021
8fe79d4
added current state of propagator and trace provider
bhautikpip Jun 7, 2021
0d0588f
minor design change
bhautikpip Jun 8, 2021
bd3d279
removed setting global propagators and minor changes
bhautikpip Jun 18, 2021
79e7602
make precommit changes
bhautikpip Jun 18, 2021
c95f44a
removed unnecessary benchmark
bhautikpip Jun 18, 2021
83fc5f6
Merge branch 'main' into add-aws-componenets-benchmark
Aneurysm9 Jun 18, 2021
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
34 changes: 34 additions & 0 deletions propagators/aws/xray/propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
package xray

import (
"context"
"net/http"
"strings"
"testing"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"

"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -96,3 +101,32 @@ func TestAwsXrayExtract(t *testing.T) {
assert.Equal(t, trace.NewSpanContext(test.expected), sc, info...)
}
}

func BenchmarkPropagatorExtract(b *testing.B) {
propagator := Propagator{}

ctx := context.Background()
req, _ := http.NewRequest("GET", "http://example.com", nil)

req.Header.Set("Root", "1-8a3c60f7-d188f8fa79d48a391a778fa6")
req.Header.Set("Parent", "53995c3f42cd8ad8")
req.Header.Set("Sampled", "1")

b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = propagator.Extract(ctx, propagation.HeaderCarrier(req.Header))
}
}

func BenchmarkPropagatorInject(b *testing.B) {
propagator := Propagator{}
tracer := otel.Tracer("test")

req, _ := http.NewRequest("GET", "http://example.com", nil)
ctx, _ := tracer.Start(context.Background(), "Parent operation...")

b.ResetTimer()
for i := 0; i < b.N; i++ {
propagator.Inject(ctx, propagation.HeaderCarrier(req.Header))
}
}
220 changes: 220 additions & 0 deletions propagators/aws/xray/sampled_unsampled_span_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// 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

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package xray

import (
"context"
"testing"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"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


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()
}


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()
}


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)
}


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"))
}


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.

var span trace.Span
_, span = tracer.Start(
context.Background(),
"Example Trace",
)

defer span.End()
}

func startAndEndNestedUnSampledSpan() {
var span trace.Span
ctx, span := tracer.Start(context.Background(), "Parent operation...")
defer span.End()

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

func getCurrentUnSampledSpan() trace.Span {
var span trace.Span
ctx, span := tracer.Start(
context.Background(),
"Example Trace",
)
defer span.End()

return trace.SpanFromContext(ctx)
}

func addAttributesToUnSampledSpan() {
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"))
}

func initialization() {
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")

otel.SetTextMapPropagator(Propagator{})
}
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved

func BenchmarkStartAndEndSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
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()
}

otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}

func BenchmarkStartAndEndNestedSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
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()
}

otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}

func BenchmarkGetCurrentSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
for i := 0; i < b.N; i++ {
getCurrentSampledSpan()
}
otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}

func BenchmarkAddAttributesToSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
for i := 0; i < b.N; i++ {
addAttributesToSampledSpan()
}
otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}

func BenchmarkStartAndEndUnSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
for i := 0; i < b.N; i++ {
startAndEndUnSampledSpan()
}
otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}

func BenchmarkStartAndEndNestedUnSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
for i := 0; i < b.N; i++ {
startAndEndNestedUnSampledSpan()
}
otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}

func BenchmarkGetCurrentUnSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
for i := 0; i < b.N; i++ {
getCurrentUnSampledSpan()
}
otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}

func BenchmarkAddAttributesToUnSampledSpan(b *testing.B) {
currentTraceProvider := otel.GetTracerProvider()
currentPropagator := otel.GetTextMapPropagator()

initialization()
for i := 0; i < b.N; i++ {
addAttributesToUnSampledSpan()
}

otel.SetTracerProvider(currentTraceProvider)
otel.SetTextMapPropagator(currentPropagator)
}