-
Notifications
You must be signed in to change notification settings - Fork 705
Clean up ProbabilitySampler for 64 bit trace IDs #238
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f2251ea
Make ProbabilitySampler check high byets
c24t bdee2f9
Blacken
c24t 381c41f
Types fix, slight optimization
c24t bd16b67
Update sampler to check low-order bits
c24t cf11116
Merge branch 'master' into sampler-api-go-high
c24t f8602df
Fix typo
c24t 20fb95c
Blacken
c24t 9791acc
Update opentelemetry-api/src/opentelemetry/trace/sampling.py
c24t 18299e2
Fix OBOE
c24t 2747f23
Parens
c24t 29f5eff
Merge branch 'master' into sampler-api-go-high
c24t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
import unittest | ||
|
||
from opentelemetry import trace | ||
|
@@ -137,7 +138,7 @@ def test_probability_sampler(self): | |
trace.SpanContext( | ||
0xDEADBEF0, 0xDEADBEF1, trace_options=TO_DEFAULT | ||
), | ||
0x8000000000000000, | ||
0x7FFFFFFFFFFFFFFF, | ||
0xDEADBEEF, | ||
"span name", | ||
).sampled | ||
|
@@ -147,7 +148,7 @@ def test_probability_sampler(self): | |
trace.SpanContext( | ||
0xDEADBEF0, 0xDEADBEF1, trace_options=TO_SAMPLED | ||
), | ||
0x8000000000000001, | ||
0x8000000000000000, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as above, but not a strong preference in either case. |
||
0xDEADBEEF, | ||
"span name", | ||
).sampled | ||
|
@@ -189,14 +190,13 @@ def test_probability_sampler_limits(self): | |
sampling.ProbabilitySampler.get_bound_for_rate(2 ** -64), 0x1 | ||
) | ||
|
||
# Sample every trace with (last 8 bytes of) trace ID less than | ||
# 0xffffffffffffffff. In principle this is the highest possible | ||
# sampling rate less than 1, but we can't actually express this rate as | ||
# a float! | ||
# Sample every trace with trace ID less than 0xffffffffffffffff. In | ||
# principle this is the highest possible sampling rate less than 1, but | ||
# we can't actually express this rate as a float! | ||
# | ||
# In practice, the highest possible sampling rate is: | ||
# | ||
# round(sys.float_info.epsilon * 2 ** 64) | ||
# 1 - sys.float_info.epsilon | ||
|
||
almost_always_on = sampling.ProbabilitySampler(1 - 2 ** -64) | ||
self.assertTrue( | ||
|
@@ -212,12 +212,29 @@ def test_probability_sampler_limits(self): | |
# self.assertFalse( | ||
# almost_always_on.should_sample( | ||
# None, | ||
# 0xffffffffffffffff, | ||
# 0xdeadbeef, | ||
# 0xFFFFFFFFFFFFFFFF, | ||
# 0xDEADBEEF, | ||
# "span name", | ||
# ).sampled | ||
# ) | ||
# self.assertEqual( | ||
# sampling.ProbabilitySampler.get_bound_for_rate(1 - 2 ** -64)), | ||
# 0xffffffffffffffff, | ||
# 0xFFFFFFFFFFFFFFFF, | ||
# ) | ||
|
||
# Check that a sampler with the highest effective sampling rate < 1 | ||
# refuses to sample traces with trace ID 0xffffffffffffffff. | ||
almost_almost_always_on = sampling.ProbabilitySampler( | ||
1 - sys.float_info.epsilon | ||
) | ||
self.assertFalse( | ||
almost_almost_always_on.should_sample( | ||
None, 0xFFFFFFFFFFFFFFFF, 0xDEADBEEF, "span name" | ||
).sampled | ||
) | ||
# Check that the higest effective sampling rate is actually lower than | ||
# the highest theoretical sampling rate. If this test fails the test | ||
# above is wrong. | ||
self.assertLess( | ||
almost_almost_always_on.bound, 0xFFFFFFFFFFFFFFFF, | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.