@@ -90,12 +90,19 @@ type testSamplingStrategyParser struct {
90
90
func (p * testSamplingStrategyParser ) Parse (response []byte ) (interface {}, error ) {
91
91
strategy := new (jaeger_api_v2.SamplingStrategyResponse )
92
92
93
- if string (response ) == "probabilistic" {
93
+ switch string (response ) {
94
+ case "probabilistic" :
94
95
strategy .StrategyType = jaeger_api_v2 .SamplingStrategyType_PROBABILISTIC
95
96
strategy .ProbabilisticSampling = & jaeger_api_v2.ProbabilisticSamplingStrategy {
96
97
SamplingRate : 0.85 ,
97
98
}
98
99
return strategy , nil
100
+ case "rateLimiting" :
101
+ strategy .StrategyType = jaeger_api_v2 .SamplingStrategyType_RATE_LIMITING
102
+ strategy .RateLimitingSampling = & jaeger_api_v2.RateLimitingSamplingStrategy {
103
+ MaxTracesPerSecond : 100 ,
104
+ }
105
+ return strategy , nil
99
106
}
100
107
101
108
return nil , errors .New ("unknown strategy test request" )
@@ -280,6 +287,29 @@ func TestRemotelyControlledSampler_updateSampler(t *testing.T) {
280
287
}
281
288
}
282
289
290
+ func TestRemotelyControlledSampler_ImmediatelyUpdateOnStartup (t * testing.T ) {
291
+ initSampler := newProbabilisticSampler (0.123 )
292
+ fetcher := & testSamplingStrategyFetcher {response : []byte ("rateLimiting" )}
293
+ parser := new (testSamplingStrategyParser )
294
+ updaters := []samplerUpdater {new (probabilisticSamplerUpdater ), new (rateLimitingSamplerUpdater )}
295
+ sampler := New (
296
+ "test" ,
297
+ WithMaxOperations (42 ),
298
+ WithOperationNameLateBinding (true ),
299
+ WithInitialSampler (initSampler ),
300
+ WithSamplingServerURL ("my url" ),
301
+ WithSamplingRefreshInterval (10 * time .Minute ),
302
+ withSamplingStrategyFetcher (fetcher ),
303
+ withSamplingStrategyParser (parser ),
304
+ withUpdaters (updaters ... ),
305
+ )
306
+ time .Sleep (100 * time .Millisecond ) // waiting for s.pollController
307
+ sampler .Close () // stop pollController, avoid date race
308
+ s , ok := sampler .sampler .(* rateLimitingSampler )
309
+ assert .True (t , ok )
310
+ assert .Equal (t , float64 (100 ), s .maxTracesPerSecond )
311
+ }
312
+
283
313
func TestRemotelyControlledSampler_multiStrategyResponse (t * testing.T ) {
284
314
agent , sampler := initAgent (t )
285
315
defer agent .Close ()
0 commit comments