Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Unset highest bit of traceID in probabilistic sampler #490

Merged
merged 2 commits into from
Mar 2, 2020

Conversation

funny-falcon
Copy link
Contributor

@funny-falcon funny-falcon commented Feb 26, 2020

This commit fixes interconnection of ProbabilisticSampler.IsSampled and tracerOptions.RandomNumber:

  • RandomNumber accepts func() uint64 and doesn't documents it should return 63bit integer
  • IsSampled performed check as if random number were 63bit integer.

This fix (suggested by Yuri Shkuro) truncates highest bit before comparison in IsSampled,
therefore it doesn't matter if random number is 63bit or 64bit.

fixes #489

Signed-off-by: Sokolov Yura funny.falcon@gmail.com

This commit fixes interconnection of ProbabilisticSampler.IsSampled and tracerOptions.RandomNumber:
- RandomNumber accepts `func() uint64` and doesn't documents it should return 63bit integer
- IsSampled performed check as if random number were 63bit integer.
This fix (suggested by Yuri Shkuro) truncates highest bit before comparison in IsSampled,
therefore it doesn't matter if random number is 63bit or 64bit.

Signed-off-by: Sokolov Yura <funny.falcon@gmail.com>
@codecov
Copy link

codecov bot commented Feb 26, 2020

Codecov Report

Merging #490 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #490   +/-   ##
=======================================
  Coverage   88.43%   88.43%           
=======================================
  Files          59       59           
  Lines        3581     3581           
=======================================
  Hits         3167     3167           
  Misses        303      303           
  Partials      111      111
Impacted Files Coverage Δ
sampler.go 93.87% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47258d8...00ac23a. Read the comment docs.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s add a test

@funny-falcon
Copy link
Contributor Author

I've added test for 64bit values

sampled, tags := sampler.IsSampled(TraceID{Low: (testMaxID + 10) | 1<<63}, testOperationName)
assert.False(t, sampled)
assert.Equal(t, testProbabilisticExpectedTags, tags)
sampled, tags = sampler.IsSampled(TraceID{Low: (testMaxID - 20) | 1<<63}, testOperationName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ineffectual assignment to tags (from ineffassign)

Signed-off-by: Sokolov Yura <funny.falcon@gmail.com>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@yurishkuro yurishkuro changed the title fix probabilistic sampler Unset highest bit of traceID in probabilistic sampler Mar 2, 2020
@yurishkuro yurishkuro merged commit 9b6429a into jaegertracing:master Mar 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tracerOptions.RandomNumber accepts uint64 generator, but ProbabilisticSampler compares as 63bit integer.
3 participants