SkyAPM / go2sky

Distributed tracing and monitor SDK in Go for Apache SkyWalking APM
https://skywalking.apache.org/
Apache License 2.0
447 stars 122 forks source link

RandomSampler may get not sampled when samplingRate is 0 #101

Closed matianjun1 closed 3 years ago

matianjun1 commented 3 years ago

https://github.com/SkyAPM/go2sky/blob/520133d117488e6c3fd952f84018f4a39651d89b/sampler.go#L52-L56

rand.Intn(100) should be [0-100), so that when samplingRate is 0, IsSampled maybe true

fix like this s.threshold >= s.rand.Intn(100) + 1

If confused with IsSampled(), NewConstSampler always return false when input param sample is false

mrproliu commented 3 years ago

Hi, I think use s.threshold >= s.rand.Intn(100) + 1 it's enough. Welcome to contribute.