Skip to content

Commit

Permalink
[pkg/trace][otlp] do not mark payloads to avoid races (#14769)
Browse files Browse the repository at this point in the history
* [pkg/trace][otlp] do not mark payloads to avoid races

* Apply suggestions from code review

Co-authored-by: Gabriel Aszalos <[email protected]>

* Fix tests

Co-authored-by: Gabriel Aszalos <[email protected]>
  • Loading branch information
mx-psi and gbbr authored Dec 15, 2022
1 parent 5cf8318 commit ae4a2b6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
9 changes: 1 addition & 8 deletions pkg/trace/api/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
15 changes: 0 additions & 15 deletions pkg/trace/api/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
})
}

Expand Down

0 comments on commit ae4a2b6

Please sign in to comment.