Skip to content

Commit

Permalink
Get BasicSampler(0), RandomSampler(0), and BurstSampler(0) to behave …
Browse files Browse the repository at this point in the history
…the same and not write anything (#696)
  • Loading branch information
OlegSchwann authored Nov 14, 2024
1 parent 6abadab commit 582f820
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type BasicSampler struct {
// Sample implements the Sampler interface.
func (s *BasicSampler) Sample(lvl Level) bool {
n := s.N
if n == 0 {
return false
}
if n == 1 {
return true
}
Expand Down
21 changes: 21 additions & 0 deletions sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,41 @@ var samplers = []struct {
},
100, 20, 20,
},
{
"BasicSampler_0",
func() Sampler {
return &BasicSampler{N: 0}
},
100, 0, 0,
},
{
"RandomSampler",
func() Sampler {
return RandomSampler(5)
},
100, 10, 30,
},
{
"RandomSampler_0",
func() Sampler {
return RandomSampler(0)
},
100, 0, 0,
},
{
"BurstSampler",
func() Sampler {
return &BurstSampler{Burst: 20, Period: time.Second}
},
100, 20, 20,
},
{
"BurstSampler_0",
func() Sampler {
return &BurstSampler{Burst: 0, Period: time.Second}
},
100, 0, 0,
},
{
"BurstSamplerNext",
func() Sampler {
Expand Down

0 comments on commit 582f820

Please sign in to comment.