Skip to content

Commit 21e8fc8

Browse files
authored
Merge branch 'main' into gcp_resource_v2
2 parents 73ba153 + 520efe3 commit 21e8fc8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

samplers/jaegerremote/sampler_remote.go

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ func (s *Sampler) pollController() {
127127
}
128128

129129
func (s *Sampler) pollControllerWithTicker(ticker *time.Ticker) {
130+
s.UpdateSampler()
131+
130132
for {
131133
select {
132134
case <-ticker.C:

samplers/jaegerremote/sampler_remote_test.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,19 @@ type testSamplingStrategyParser struct {
9090
func (p *testSamplingStrategyParser) Parse(response []byte) (interface{}, error) {
9191
strategy := new(jaeger_api_v2.SamplingStrategyResponse)
9292

93-
if string(response) == "probabilistic" {
93+
switch string(response) {
94+
case "probabilistic":
9495
strategy.StrategyType = jaeger_api_v2.SamplingStrategyType_PROBABILISTIC
9596
strategy.ProbabilisticSampling = &jaeger_api_v2.ProbabilisticSamplingStrategy{
9697
SamplingRate: 0.85,
9798
}
9899
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
99106
}
100107

101108
return nil, errors.New("unknown strategy test request")
@@ -280,6 +287,29 @@ func TestRemotelyControlledSampler_updateSampler(t *testing.T) {
280287
}
281288
}
282289

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+
283313
func TestRemotelyControlledSampler_multiStrategyResponse(t *testing.T) {
284314
agent, sampler := initAgent(t)
285315
defer agent.Close()

0 commit comments

Comments
 (0)