Skip to content

Commit

Permalink
[processor/tailsampling] Fix SpanCount sampler not using the correct …
Browse files Browse the repository at this point in the history
…span count for decision (#13386)

* Fixes SpanCount sampler not using the correct count for decision

Signed-off-by: Miguel Alexandre <[email protected]>

* Add changelog

Signed-off-by: Miguel Alexandre <[email protected]>

* Fix test to make the correct decision

Signed-off-by: Miguel Alexandre <[email protected]>

* Reference issue in changelog

Signed-off-by: Miguel Alexandre <[email protected]>

* Keep previous tests, renamed to make sense

Signed-off-by: Miguel Alexandre <[email protected]>

Signed-off-by: Miguel Alexandre <[email protected]>
  • Loading branch information
Symbianx authored Sep 6, 2022
1 parent ebc8ea2 commit 7adcabf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ func NewSpanCount(logger *zap.Logger, minSpans int32) PolicyEvaluator {
func (c *spanCount) Evaluate(_ pcommon.TraceID, traceData *TraceData) (Decision, error) {
c.logger.Debug("Evaluating spans counts in filter")

traceData.Lock()
batches := traceData.ReceivedBatches
traceData.Unlock()

for _, trace := range batches {
if trace.SpanCount() >= int(c.minSpans) {
return Sampled, nil
}
if int(traceData.SpanCount.Load()) >= int(c.minSpans) {
return Sampled, nil
}
return NotSampled, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/atomic"
"go.uber.org/zap"
)

Expand All @@ -41,26 +42,47 @@ func TestEvaluate_NumberSpans(t *testing.T) {
NotSampled,
},
{
"Less spans than the threshold",
"Bigger amount of spans than the threshold, in one single batch",
[]int32{
1, 1, 1,
3,
},
NotSampled,
Sampled,
},
{
"Same number of spans than the threshold",
"Bigger amount of spans than the threshold, with different span count per batch",
[]int32{
1, 2, 1,
},
Sampled,
},
{
"Bigger amount of spans than the threashold",
"Same number of spans as the threshold, in one single batch",
[]int32{
2,
},
Sampled,
},
{
"Bigger amount of spans than the threshold, across multiple batches",
[]int32{
1, 1, 1,
},
Sampled,
},
{
"Bigger amount of spans than the threshold, with a different number",
[]int32{
1, 3, 1,
},
Sampled,
},
{
"Same number of spans as the threshold, across multiple batches",
[]int32{
1, 1,
},
Sampled,
},
}

for _, c := range cases {
Expand All @@ -75,6 +97,7 @@ func TestEvaluate_NumberSpans(t *testing.T) {

func newTraceWithMultipleSpans(numberSpans []int32) *TraceData {
var traceBatches []ptrace.Traces
var totalNumberSpans = int32(0)

// For each trace, going to create the number of spans defined in the array
for i := range numberSpans {
Expand All @@ -89,9 +112,11 @@ func newTraceWithMultipleSpans(numberSpans []int32) *TraceData {
span.SetSpanID(pcommon.NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
}
traceBatches = append(traceBatches, traces)
totalNumberSpans += numberSpans[i]
}

return &TraceData{
ReceivedBatches: traceBatches,
SpanCount: atomic.NewInt64(int64(totalNumberSpans)),
}
}
16 changes: 16 additions & 0 deletions unreleased/fix-span-count-incorrect-tracking.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: tailsamplingprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes SpanCount sampler not using the correct span count for decision.

# One or more tracking issues related to the change
issues: [13865]

# (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:

0 comments on commit 7adcabf

Please sign in to comment.