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 OTLP traces benchmark #34

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Changes from all commits
Commits
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
22 changes: 17 additions & 5 deletions cmd/apmbench/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func Benchmark10000AggregationGroups(b *testing.B, l *rate.Limiter) {
func newTracer(tb testing.TB) *apm.Tracer {
httpTransport, err := transport.NewHTTPTransport(transport.HTTPTransportOptions{
ServerURLs: []*url.URL{loadgencfg.Config.ServerURL},
APIKey: loadgencfg.Config.APIKey,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes APIKey auth for the apm-tracer based benchmarks but I haven't been able to find a way to add custom headers for these.

SecretToken: loadgencfg.Config.SecretToken,
})
if err != nil {
Expand All @@ -147,6 +148,7 @@ func newTracer(tb testing.TB) *apm.Tracer {
func newOTLPExporter(tb testing.TB) *otlptrace.Exporter {
serverURL := loadgencfg.Config.ServerURL
secretToken := loadgencfg.Config.SecretToken
apiKey := loadgencfg.Config.APIKey
endpoint := serverURL.Host
if serverURL.Port() == "" {
switch serverURL.Scheme {
Expand All @@ -156,14 +158,24 @@ func newOTLPExporter(tb testing.TB) *otlptrace.Exporter {
endpoint += ":443"
}
}

headers := make(map[string]string)
for k, v := range loadgencfg.Config.Headers {
headers[k] = v
}
if secretToken != "" || apiKey != "" {
if apiKey != "" {
// higher priority to APIKey auth
headers["Authorization"] = "ApiKey " + apiKey
} else {
headers["Authorization"] = "Bearer " + secretToken
}
}

opts := []otlptracegrpc.Option{
otlptracegrpc.WithEndpoint(endpoint),
otlptracegrpc.WithDialOption(grpc.WithBlock()),
}
if secretToken != "" {
opts = append(opts, otlptracegrpc.WithHeaders(map[string]string{
"Authorization": "Bearer " + secretToken,
}))
otlptracegrpc.WithHeaders(headers),
}
if serverURL.Scheme == "http" {
opts = append(opts, otlptracegrpc.WithInsecure())
Expand Down