From ae4a2b6bc23399a87c73e0dd901d836b493c4a34 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Thu, 15 Dec 2022 17:12:18 +0100 Subject: [PATCH] [pkg/trace][otlp] do not mark payloads to avoid races (#14769) * [pkg/trace][otlp] do not mark payloads to avoid races * Apply suggestions from code review Co-authored-by: Gabriel Aszalos * Fix tests Co-authored-by: Gabriel Aszalos --- pkg/trace/api/otlp.go | 9 +-------- pkg/trace/api/otlp_test.go | 15 --------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/pkg/trace/api/otlp.go b/pkg/trace/api/otlp.go index be9a294bb3b33..f3ded1c4424dc 100644 --- a/pkg/trace/api/otlp.go +++ b/pkg/trace/api/otlp.go @@ -359,14 +359,7 @@ func (o *OTLPReceiver) ReceiveResourceSpans(ctx context.Context, rspans ptrace.R } select { case o.out <- &p: - // Stats will be computed for p. Mark the original resource spans to ensure that they don't - // get computed twice in case these spans pass through here again. - // - // Spans can pass through here multiple times because this code path gets used by the: - // - OpenTelemetry Collector Datadog processor, when computing stats. - // - OpenTelemetry Collector Datadog exporter, when flushing. - // - Datadog Agent OTLP Ingest, when used in conjunction with an SDK or a Collector. - rspans.Resource().Attributes().PutBool(keyStatsComputed, true) + // success default: log.Warn("Payload in channel full. Dropped 1 payload.") } diff --git a/pkg/trace/api/otlp_test.go b/pkg/trace/api/otlp_test.go index a99f1fc2f8958..ecb1b832de003 100644 --- a/pkg/trace/api/otlp_test.go +++ b/pkg/trace/api/otlp_test.go @@ -363,8 +363,6 @@ func TestOTLPReceiveResourceSpans(t *testing.T) { }, }, }).Traces().ResourceSpans().At(0) - _, ok := rspans.Resource().Attributes().Get(keyStatsComputed) - require.False(ok) rcv.ReceiveResourceSpans(context.Background(), rspans, http.Header{}, "agent_tests") timeout := time.After(500 * time.Millisecond) select { @@ -374,19 +372,6 @@ func TestOTLPReceiveResourceSpans(t *testing.T) { // stats are computed this time require.False(p.ClientComputedStats) } - // after the first receive, the keyStatsComputed attribute has to be applied, - // so that on the second run stats are skipped - v, ok := rspans.Resource().Attributes().Get(keyStatsComputed) - require.True(ok) - require.Equal("true", v.AsString()) - rcv.ReceiveResourceSpans(context.Background(), rspans, http.Header{}, "agent_tests") - select { - case <-timeout: - t.Fatal("timed out") - case p := <-out: - // stats are not computed the second time - require.True(p.ClientComputedStats) - } }) }