Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: use peroperationsamplerupdater first #2137

Merged
merged 6 commits into from Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixed
- Fixed jaegerremote sampler not behaving properly with per operation strategy set. (#2137)

## [1.6.0/0.31.0] - 2022-03-28

### Added
Expand Down
10 changes: 4 additions & 6 deletions samplers/jaegerremote/sampler_remote_options.go
Expand Up @@ -52,12 +52,10 @@ func newConfig(options ...Option) config {
for _, option := range options {
option.apply(&c)
}
c.updaters = append(c.updaters,
&perOperationSamplerUpdater{
MaxOperations: c.posParams.MaxOperations,
OperationNameLateBinding: c.posParams.OperationNameLateBinding,
})

c.updaters = append([]samplerUpdater{&perOperationSamplerUpdater{
MaxOperations: c.posParams.MaxOperations,
OperationNameLateBinding: c.posParams.OperationNameLateBinding,
}}, c.updaters...)
vuuihc marked this conversation as resolved.
Show resolved Hide resolved
return c
}

Expand Down
41 changes: 40 additions & 1 deletion samplers/jaegerremote/sampler_remote_test.go
Expand Up @@ -125,7 +125,7 @@ func TestRemoteSamplerOptions(t *testing.T) {
assert.Equal(t, 42*time.Second, sampler.samplingRefreshInterval)
assert.Same(t, fetcher, sampler.samplingFetcher)
assert.Same(t, parser, sampler.samplingParser)
assert.Same(t, updaters[0], sampler.updaters[0])
assert.EqualValues(t, sampler.updaters[0], &perOperationSamplerUpdater{MaxOperations: 42, OperationNameLateBinding: true})
}

func TestRemoteSamplerOptionsDefaults(t *testing.T) {
Expand Down Expand Up @@ -281,6 +281,45 @@ func TestRemotelyControlledSampler_updateSampler(t *testing.T) {
}
}

func TestRemotelyControlledSampler_multiStrategyResponse(t *testing.T) {
agent, sampler := initAgent(t)
defer agent.Close()
initSampler, ok := sampler.sampler.(*probabilisticSampler)
assert.True(t, ok)

defaultSampingRate := 1.0
testUnusedOpName := "unused_op"
testUnusedOpSamplingRate := 0.0

res := &jaeger_api_v2.SamplingStrategyResponse{
StrategyType: jaeger_api_v2.SamplingStrategyType_PROBABILISTIC,
ProbabilisticSampling: &jaeger_api_v2.ProbabilisticSamplingStrategy{SamplingRate: defaultSampingRate},
OperationSampling: &jaeger_api_v2.PerOperationSamplingStrategies{
DefaultSamplingProbability: defaultSampingRate,
DefaultLowerBoundTracesPerSecond: 0.001,
PerOperationStrategies: []*jaeger_api_v2.OperationSamplingStrategy{
{
Operation: testUnusedOpName,
ProbabilisticSampling: &jaeger_api_v2.ProbabilisticSamplingStrategy{
SamplingRate: testUnusedOpSamplingRate,
}},
},
},
}

agent.AddSamplingStrategy("client app", res)
sampler.UpdateSampler()
s, ok := sampler.sampler.(*perOperationSampler)
assert.True(t, ok)
assert.NotEqual(t, initSampler, sampler.sampler, "Sampler should have been updated")
assert.Equal(t, defaultSampingRate, s.defaultSampler.SamplingRate())

result := sampler.ShouldSample(makeSamplingParameters(testMaxID-10, testUnusedOpName))
assert.Equal(t, trace.RecordAndSample, result.Decision) // first call always pass
result = sampler.ShouldSample(makeSamplingParameters(testMaxID, testUnusedOpName))
assert.Equal(t, trace.Drop, result.Decision)
}

func TestSamplerQueryError(t *testing.T) {
agent, sampler := initAgent(t)
defer agent.Close()
Expand Down