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

Commit

Permalink
Fix rate limiting sampler maxBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
black-adder committed Apr 26, 2017
1 parent 0cd585b commit 34ab8dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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

0 comments on commit 34ab8dd

Please sign in to comment.