-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[connector/datadog] Improve performance in cases with many peer tags (#…
…34945) **Description:** Improves performance of Datadog connector when there are many peer tags and `connector.datadogconnector.NativeIngest` is enabled **Link to tracking Issue:** Related to DataDog/datadog-agent#28908 **Testing:** Added new benchmark tests, results: ``` % go test -bench . -benchmem -benchtime=1000x goos: darwin goarch: arm64 pkg: github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector cpu: Apple M1 Max BenchmarkPeerTags_Native-10 1000 22851735 ns/op 9147 B/op 118 allocs/op BenchmarkPeerTags_Legacy-10 1000 27704684 ns/op 12157 B/op 152 allocs/op PASS ```
- Loading branch information
Showing
15 changed files
with
199 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: datadogconnector | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: "Optimize Datadog connector when there are many peer tags and `connector.datadogconnector.NativeIngest` is enabled" | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [34945] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: "`connector.datadogconnector.NativeIngest` is currently enabled by default" | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector" | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/connector/connectortest" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/featuregate" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
) | ||
|
||
func genTrace() ptrace.Traces { | ||
start := time.Now().Add(-1 * time.Second) | ||
end := time.Now() | ||
traces := ptrace.NewTraces() | ||
rspan := traces.ResourceSpans().AppendEmpty() | ||
rattrs := rspan.Resource().Attributes() | ||
rattrs.PutStr("deployment.environment", "test_env") | ||
rattrs.PutStr("service.name", "test_svc") | ||
sspan := rspan.ScopeSpans().AppendEmpty() | ||
span := sspan.Spans().AppendEmpty() | ||
span.SetTraceID(testTraceID) | ||
span.SetSpanID(testSpanID1) | ||
span.SetStartTimestamp(pcommon.NewTimestampFromTime(start)) | ||
span.SetEndTimestamp(pcommon.NewTimestampFromTime(end)) | ||
span.SetName("span_name") | ||
span.SetKind(ptrace.SpanKindClient) | ||
span.Attributes().PutStr("peer.service", "my_peer_svc") | ||
span.Attributes().PutStr("rpc.service", "my_rpc_svc") | ||
span.Attributes().PutStr("net.peer.name", "my_net_peer") | ||
return traces | ||
} | ||
|
||
func BenchmarkPeerTags_Native(b *testing.B) { | ||
benchmarkPeerTags(b) | ||
} | ||
|
||
func BenchmarkPeerTags_Legacy(b *testing.B) { | ||
err := featuregate.GlobalRegistry().Set(NativeIngestFeatureGate.ID(), false) | ||
assert.NoError(b, err) | ||
defer func() { | ||
_ = featuregate.GlobalRegistry().Set(NativeIngestFeatureGate.ID(), true) | ||
}() | ||
|
||
benchmarkPeerTags(b) | ||
} | ||
|
||
func benchmarkPeerTags(b *testing.B) { | ||
cfg := NewFactory().CreateDefaultConfig().(*Config) | ||
cfg.Traces.ComputeStatsBySpanKind = true | ||
cfg.Traces.PeerTagsAggregation = true | ||
cfg.Traces.BucketInterval = 1 * time.Millisecond | ||
cfg.Traces.TraceBuffer = 0 | ||
|
||
factory := NewFactory() | ||
creationParams := connectortest.NewNopSettings() | ||
metricsSink := &consumertest.MetricsSink{} | ||
|
||
tconn, err := factory.CreateTracesToMetrics(context.Background(), creationParams, cfg, metricsSink) | ||
assert.NoError(b, err) | ||
|
||
err = tconn.Start(context.Background(), componenttest.NewNopHost()) | ||
if err != nil { | ||
b.Errorf("Error starting connector: %v", err) | ||
return | ||
} | ||
defer func() { | ||
require.NoError(b, tconn.Shutdown(context.Background())) | ||
}() | ||
|
||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
err = tconn.ConsumeTraces(context.Background(), genTrace()) | ||
assert.NoError(b, err) | ||
for { | ||
metrics := metricsSink.AllMetrics() | ||
if len(metrics) > 0 { | ||
assert.Len(b, metrics, 1) | ||
break | ||
} | ||
} | ||
metricsSink.Reset() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.