Skip to content

Commit

Permalink
[processor/tailsampling] Fix composite policy with inverse matching (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#9793)

Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
pmm-sumo and Alex Boten committed Jun 3, 2022
1 parent 6297dff commit e667567
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- `dynatraceexporter`: Ensure min is always less than or equal to mean and max is always greater or equal to mean for histogram estimation. (#10257)
- `resourcedetectionprocessor`: GCP resource detector now properly detects zone/region on GKE (#10347)
- `resourcedetectionprocessor`: GCP resource detector no longer fails to detect resource when using workload identity (#10486)
- `tailsamplingprocessor`: Fix composite sampler with inverse policy

## v0.52.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *Composite) Evaluate(traceID pcommon.TraceID, trace *TraceData) (Decisio
return Unspecified, err
}

if decision == Sampled {
if decision == Sampled || decision == InvertSampled {
// The subpolicy made a decision to Sample. Now we need to make our decision.

// Calculate resulting SPS counter if we decide to sample this trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@ func TestCompositeEvaluatorSampled_AlwaysSampled(t *testing.T) {
}
}

func TestCompositeEvaluatorInverseSampled_AlwaysSampled(t *testing.T) {

// The first policy does not match, the second matches through invert
n1 := NewStringAttributeFilter(zap.NewNop(), "tag", []string{"foo"}, false, 0, false)
n2 := NewStringAttributeFilter(zap.NewNop(), "tag", []string{"foo"}, false, 0, true)
c := NewComposite(zap.NewNop(), 10, []SubPolicyEvalParams{{n1, 20}, {n2, 20}}, FakeTimeProvider{})

for i := 1; i <= 10; i++ {
trace := createTrace()

decision, err := c.Evaluate(traceID, trace)
require.NoError(t, err, "Failed to evaluate composite policy: %v", err)

// The second policy is AlwaysSample, so the decision should be Sampled.
expected := Sampled
assert.Equal(t, decision, expected)
}
}

func TestCompositeEvaluatorThrottling(t *testing.T) {

// Create only one subpolicy, with 100% Sampled policy.
Expand Down

0 comments on commit e667567

Please sign in to comment.