Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Fix rate limiting sampler maxBalance #140

Merged
merged 1 commit into from
Apr 26, 2017
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
3 changes: 2 additions & 1 deletion sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package jaeger

import (
"fmt"
"math"
"net/url"
"sync"
"time"
Expand Down Expand Up @@ -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,
}
}
Expand Down
14 changes: 14 additions & 0 deletions sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down