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

Disable same kind, enable exact match compression by default #1256

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 5 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ const (
envUseElasticTraceparentHeader = "ELASTIC_APM_USE_ELASTIC_TRACEPARENT_HEADER"
envCloudProvider = "ELASTIC_APM_CLOUD_PROVIDER"

// NOTE(marclop) Experimental settings
// span_compression (default `false`)
// span_compression (default `true`)
envSpanCompressionEnabled = "ELASTIC_APM_SPAN_COMPRESSION_ENABLED"
// span_compression_exact_match_max_duration (default `50ms`)
envSpanCompressionExactMatchMaxDuration = "ELASTIC_APM_SPAN_COMPRESSION_EXACT_MATCH_MAX_DURATION"
// span_compression_same_kind_max_duration (default `5ms`)
// span_compression_same_kind_max_duration (default `0ms`)
envSpanCompressionSameKindMaxDuration = "ELASTIC_APM_SPAN_COMPRESSION_SAME_KIND_MAX_DURATION"

// exit_span_min_duration (default `1ms`)
Expand Down Expand Up @@ -104,10 +103,10 @@ const (
minMetricsBufferSize = 10 * configutil.KByte
maxMetricsBufferSize = 100 * configutil.MByte

// Experimental Span Compressions default setting values
defaultSpanCompressionEnabled = false
// Span Compressions default setting values
defaultSpanCompressionEnabled = true
defaultSpanCompressionExactMatchMaxDuration = 50 * time.Millisecond
defaultSpanCompressionSameKindMaxDuration = 5 * time.Millisecond
defaultSpanCompressionSameKindMaxDuration = 0
)

var (
Expand Down
8 changes: 2 additions & 6 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestTracerCentralConfigUpdate(t *testing.T) {
require.NoError(t, err)
return tracer.IgnoredTransactionURL(u)
})
run("span_compression_enabled", "true", func(tracer *apmtest.RecordingTracer) bool {
run("span_compression_enabled", "false", func(tracer *apmtest.RecordingTracer) bool {
tracer.ResetPayloads()
tx := tracer.StartTransaction("name", "type")
exitSpanOpts := apm.SpanOptions{ExitSpan: true}
Expand All @@ -154,12 +154,10 @@ func TestTracerCentralConfigUpdate(t *testing.T) {
}
tx.End()
tracer.Flush(nil)
return len(tracer.Payloads().Spans) == 1
return len(tracer.Payloads().Spans) == 2
})
run("span_compression_exact_match_max_duration", "100ms", func(tracer *apmtest.RecordingTracer) bool {
tracer.ResetPayloads()
tracer.SetSpanCompressionEnabled(true)
defer tracer.SetSpanCompressionEnabled(false)
tx := tracer.StartTransaction("name", "type")
exitSpanOpts := apm.SpanOptions{ExitSpan: true}
for i := 0; i < 2; i++ {
Expand All @@ -177,8 +175,6 @@ func TestTracerCentralConfigUpdate(t *testing.T) {
})
run("span_compression_same_kind_max_duration", "10ms", func(tracer *apmtest.RecordingTracer) bool {
tracer.ResetPayloads()
tracer.SetSpanCompressionEnabled(true)
defer tracer.SetSpanCompressionEnabled(false)
tx := tracer.StartTransaction("name", "type")
exitSpanOpts := apm.SpanOptions{ExitSpan: true}
for i := 0; i < 2; i++ {
Expand Down
20 changes: 10 additions & 10 deletions span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func TestCompressSpanSameKind(t *testing.T) {
// These should be compressed into 1 since they meet the compression
// criteria.
path := []string{"/a", "/b", "/c", "/d", "/e"}
for i := 0; i < 5; i++ {
for i := 0; i < len(path); i++ {
span := tx.StartSpanOptions(fmt.Sprint("GET ", path[i]), "request", apm.SpanOptions{
ExitSpan: true, Start: currentTime,
})
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestCompressSpanSameKind(t *testing.T) {
}

t.Run("DefaultThreshold", func(t *testing.T) {
// With the default threshold the composite count will be 5.
// By default same kind compression is disabled thus count will be 7.
lahsivjar marked this conversation as resolved.
Show resolved Hide resolved
tracer := apmtest.NewRecordingTracer()
defer tracer.Close()
tracer.SetSpanCompressionEnabled(true)
Expand All @@ -532,21 +532,16 @@ func TestCompressSpanSameKind(t *testing.T) {
_, spans, debugFunc := testCase(tracer)
defer debugFunc()

require.Equal(t, 3, len(spans))
require.Equal(t, 7, len(spans))
mysqlSpan := spans[0]
assert.Equal(t, "mysql", mysqlSpan.Context.Destination.Service.Resource)
assert.Nil(t, mysqlSpan.Composite)

requestSpan := spans[1]
assert.Equal(t, "request", requestSpan.Context.Destination.Service.Resource)
require.NotNil(t, requestSpan.Composite)
assert.Equal(t, 5, requestSpan.Composite.Count)
assert.Equal(t, "same_kind", requestSpan.Composite.CompressionStrategy)
assert.Equal(t, "Calls to request", requestSpan.Name)
// Check that the sum and span duration is at least the duration of the time set.
assert.Equal(t, 0.0005, requestSpan.Composite.Sum, requestSpan.Composite.Sum)
assert.Equal(t, 0.0005, requestSpan.Duration, requestSpan.Duration)
require.Nil(t, requestSpan.Composite)
})

t.Run("10msThreshold", func(t *testing.T) {
// With this threshold the composite count will be 6.
os.Setenv("ELASTIC_APM_SPAN_COMPRESSION_SAME_KIND_MAX_DURATION", "10ms")
Expand Down Expand Up @@ -599,6 +594,7 @@ func TestCompressSpanSameKindParentSpan(t *testing.T) {
tracer := apmtest.NewRecordingTracer()
tracer.SetSpanCompressionEnabled(true)
tracer.SetExitSpanMinDuration(0)
tracer.SetSpanCompressionSameKindMaxDuration(5 * time.Millisecond)

// This test case covers spans that have other spans as parents.
// |_______________transaction (6b1e4866252dea6f) - 1.45ms________________|
Expand Down Expand Up @@ -708,6 +704,7 @@ func TestCompressSpanSameKindParentSpanContext(t *testing.T) {
tracer := apmtest.NewRecordingTracer()
tracer.SetSpanCompressionEnabled(true)
tracer.SetExitSpanMinDuration(0)
tracer.SetSpanCompressionSameKindMaxDuration(5 * time.Millisecond)

txStart := time.Now()
tx := tracer.StartTransactionOptions("name", "type",
Expand Down Expand Up @@ -951,6 +948,7 @@ func TestCompressSpanPrematureEnd(t *testing.T) {
defer tracer.Close()
tracer.SetSpanCompressionEnabled(true)
tracer.SetExitSpanMinDuration(test.exitSpanMinDuration)
tracer.SetSpanCompressionSameKindMaxDuration(5 * time.Millisecond)

txStart := time.Now()
tx := tracer.StartTransaction("name", "type")
Expand Down Expand Up @@ -1001,6 +999,7 @@ func TestCompressSpanPrematureEnd(t *testing.T) {
defer tracer.Close()
tracer.SetSpanCompressionEnabled(true)
tracer.SetExitSpanMinDuration(time.Nanosecond)
tracer.SetSpanCompressionSameKindMaxDuration(5 * time.Millisecond)

tx := tracer.StartTransaction("name", "type")
ctx := apm.ContextWithTransaction(context.Background(), tx)
Expand Down Expand Up @@ -1036,6 +1035,7 @@ func TestCompressSpanPrematureEnd(t *testing.T) {
defer tracer.Close()
tracer.SetSpanCompressionEnabled(true)
tracer.SetExitSpanMinDuration(time.Nanosecond)
tracer.SetSpanCompressionSameKindMaxDuration(5 * time.Millisecond)

tx := tracer.StartTransaction("name", "type")
parent := tx.StartSpan("parent", "internal", nil)
Expand Down
3 changes: 3 additions & 0 deletions transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ func TestTransactionDroppedSpansStats(t *testing.T) {
t.Run("DefaultLimit", func(t *testing.T) {
tracer := apmtest.NewRecordingTracer()
defer tracer.Close()
tracer.SetSpanCompressionEnabled(false)

tx, _, _ := tracer.WithTransaction(func(ctx context.Context) {
generateSpans(ctx, 1000)
Expand Down Expand Up @@ -446,6 +447,7 @@ func TestTransactionDroppedSpansStats(t *testing.T) {
defer tracer.Close()
// Set the exit span minimum duration. This test asserts that spans
// with a duration over the span minimum duration are not dropped.
tracer.SetSpanCompressionEnabled(false)
tracer.SetExitSpanMinDuration(time.Microsecond)

// Each of the generated spans duration is 10 microseconds.
Expand All @@ -460,6 +462,7 @@ func TestTransactionDroppedSpansStats(t *testing.T) {
tracer := apmtest.NewRecordingTracer()
defer tracer.Close()
// Assert that any spans over 100 are dropped and stats are aggregated.
tracer.SetSpanCompressionEnabled(false)
tracer.SetMaxSpans(100)

tx, spans, _ := tracer.WithTransaction(func(ctx context.Context) {
Expand Down