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

ddtrace/tracer: have RuleSampler use User{Keep,Reject} instead of new values #1030

Merged
merged 2 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 2 additions & 8 deletions ddtrace/ext/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ package ext
// In a distributed context, it should be set before any context propagation (fork, RPC calls) to be effective.

const (
// PriorityRuleSamplerReject specifies that the rule sampler has decided that this trace should be rejected.
PriorityRuleSamplerReject = -3

// PriorityUserReject informs the backend that a trace should be rejected and not stored.
// This should be used by user code overriding default priority.
// This should be used by user code or configuration overriding default priority
PriorityUserReject = -1

// PriorityAutoReject informs the backend that a trace should be rejected and not stored.
Expand All @@ -25,9 +22,6 @@ const (
PriorityAutoKeep = 1

// PriorityUserKeep informs the backend that a trace should be kept and not stored.
// This should be used by user code overriding default priority.
// This should be used by user code or configuration overriding default priority
PriorityUserKeep = 2

// PriorityRuleSamplerKeep specifies that the rule sampler has decided that this trace should be kept.
PriorityRuleSamplerKeep = 3
)
6 changes: 3 additions & 3 deletions ddtrace/tracer/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,15 @@ func (rs *rulesSampler) apply(span *span) bool {
func (rs *rulesSampler) applyRate(span *span, rate float64, now time.Time) {
span.SetTag(keyRulesSamplerAppliedRate, rate)
if !sampledByRate(span.TraceID, rate) {
span.SetTag(ext.SamplingPriority, ext.PriorityRuleSamplerReject)
span.SetTag(ext.SamplingPriority, ext.PriorityUserReject)
return
}

sampled, rate := rs.limiter.allowOne(now)
if sampled {
span.SetTag(ext.SamplingPriority, ext.PriorityRuleSamplerKeep)
span.SetTag(ext.SamplingPriority, ext.PriorityUserKeep)
} else {
span.SetTag(ext.SamplingPriority, ext.PriorityRuleSamplerReject)
span.SetTag(ext.SamplingPriority, ext.PriorityUserReject)
}
span.SetTag(keyRulesSamplerLimiterRate, rate)
}
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/tracer/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ func TestRulesSamplerInternals(t *testing.T) {
// first span kept, second dropped
span := makeSpanAt("http.request", "test-service", now)
rs.applyRate(span, 1.0, now)
assert.EqualValues(ext.PriorityRuleSamplerKeep, span.Metrics[keySamplingPriority])
assert.EqualValues(ext.PriorityUserKeep, span.Metrics[keySamplingPriority])
assert.Equal(1.0, span.Metrics["_dd.rule_psr"])
assert.Equal(1.0, span.Metrics["_dd.limit_psr"])
span = makeSpanAt("http.request", "test-service", now)
rs.applyRate(span, 1.0, now)
assert.EqualValues(ext.PriorityRuleSamplerReject, span.Metrics[keySamplingPriority])
assert.EqualValues(ext.PriorityUserReject, span.Metrics[keySamplingPriority])
assert.Equal(1.0, span.Metrics["_dd.rule_psr"])
assert.Equal(0.75, span.Metrics["_dd.limit_psr"])
})
Expand Down