diff --git a/sampler.go b/sampler.go index 81db5c86..c80feec2 100644 --- a/sampler.go +++ b/sampler.go @@ -22,6 +22,7 @@ package jaeger import ( "fmt" + "math" "net/url" "sync" "time" @@ -167,7 +168,7 @@ func NewRateLimitingSampler(maxTracesPerSecond float64) Sampler { } return &rateLimitingSampler{ maxTracesPerSecond: maxTracesPerSecond, - rateLimiter: utils.NewRateLimiter(maxTracesPerSecond, 1.0), + rateLimiter: utils.NewRateLimiter(maxTracesPerSecond, math.Max(maxTracesPerSecond, 1.0)), tags: tags, } } diff --git a/sampler_test.go b/sampler_test.go index c3914f50..ad58ee82 100644 --- a/sampler_test.go +++ b/sampler_test.go @@ -148,6 +148,20 @@ func TestRateLimitingSampler(t *testing.T) { assert.True(t, sampler.Equal(sampler2)) assert.False(t, sampler.Equal(sampler3)) assert.False(t, sampler.Equal(NewConstSampler(false))) + + sampler = NewRateLimitingSampler(2) + sampled, _ := sampler.IsSampled(TraceID{}, testOperationName) + assert.True(t, sampled) + sampled, _ = sampler.IsSampled(TraceID{}, testOperationName) + assert.True(t, sampled) + sampled, _ = sampler.IsSampled(TraceID{}, testOperationName) + assert.False(t, sampled) + + sampler = NewRateLimitingSampler(0.1) + sampled, _ = sampler.IsSampled(TraceID{}, testOperationName) + assert.True(t, sampled) + sampled, _ = sampler.IsSampled(TraceID{}, testOperationName) + assert.False(t, sampled) } func TestGuaranteedThroughputProbabilisticSamplerUpdate(t *testing.T) {