-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
API usability improvements in sampling package #31940
Merged
Merged
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
e822a9b
Add t-value sampler draft
jmacd 1bc6017
copy/import tracestate parser package
jmacd d1fd891
test ot tracestate
jmacd 85e4472
tidy
jmacd bb75f8a
renames
jmacd 6a57b77
testing two parsers w/ generic code
jmacd 7fa8130
integrated
jmacd 36230e7
Comments
jmacd 7bae35c
revert two files
jmacd 9010a67
Update with r, s, and t-value. Now using regexps and strings.IndexBy…
jmacd 0e27e40
fix sampler build
jmacd efcdc3d
add support for s-value for non-consistent mode
jmacd 939c758
WIP
jmacd b9a1e56
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd a31266c
use new proposed syntax see https://github.com/open-telemetry/opentel…
jmacd 690cd64
update tracestate libs for new encoding
jmacd c8baf29
wip working on probabilistic sampler with two new modes: downsampler …
jmacd 7f47e4a
unsigned implement split
jmacd 422e0b2
two implementations
jmacd 787b9fd
wip
jmacd ed36f03
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd d795210
Updates for OTEP 235
jmacd 09000f7
wip TODO
jmacd a4d467b
versions.yaml
jmacd e373b9b
Add proportional sampler mode; comment on TODOs; create SamplerMode t…
jmacd fe6a085
back from internal
jmacd 396efb1
wip
jmacd 36de5dd
fix existing tests
jmacd f1aa0ad
:wip:
jmacd 700734e
Update for rejection threshold
jmacd ae50bdd
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd a94b8e7
fix preexisting tests
jmacd 4edcbcb
basic yes/no t-value sampling test
jmacd 53bf119
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd 3cdb957
add version for sampling pkg
jmacd e506847
more testing
jmacd 2cddfeb
add probability to threshold with precision option
jmacd f69d6ee
ProbabilityToThresholdWithPrecision
jmacd cc02934
test coverage for equalizing and proportional
jmacd 1eecc4a
config test
jmacd 2159107
comments and notes
jmacd e0898a6
update README
jmacd d0991ed
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd a002774
Remove sampling pkg, it is now upstream
jmacd 3a49922
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd fca0184
build w/ new sampling pkg
jmacd f11e0a4
more test coverage
jmacd 3f495a6
more config tests
jmacd 581095c
test precision underflow
jmacd 7b8fd31
test warning logs
jmacd 1a6be4f
hash_seed fixes
jmacd 712cf17
wip
jmacd 34c0d3b
aip
jmacd 7742668
wip-refactoring
jmacd 8d60168
refactor wip
jmacd 3779caa
cleanup refactor
jmacd c261ac1
wip
jmacd 34469e4
moving code
jmacd 8dabf47
fix tests; round up small probs to avoid errors
jmacd d44afb5
preserve legacy behavior
jmacd 1cf9991
logs handled sampling priority differently
jmacd 365d35d
still two errors
jmacd 12a3047
builds
jmacd 8655f42
needs testing
jmacd 468e6c6
fixing tests
jmacd 23b4423
cleanup
jmacd 07841e5
remove strict feature
jmacd 6936bc4
tests fixed
jmacd c132f4c
wip
jmacd bd13ac9
typo
jmacd aa33b1c
more logs tests
jmacd 06556dc
Add more comments
jmacd a4940e6
update README
jmacd 4f616e9
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd b4ca3aa
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd fdd26ac
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
jmacd 5097f43
revert these
jmacd aaff323
Remove new files too
jmacd dd979b9
comments
jmacd 34004a2
chlog
jmacd f202a57
add tests
jmacd d401076
comment
jmacd 2e41e69
fix that
jmacd eddffa8
Merge branch 'main' into jmacd/pkgsamplingup
MovieStoreGuy 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 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: pkg/sampling | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Usability improvements in the sampling API. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [31918] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [api] |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -11,12 +11,9 @@ import ( | |
// ErrProbabilityRange is returned when a value should be in the range [1/MaxAdjustedCount, 1]. | ||
var ErrProbabilityRange = errors.New("sampling probability out of the range [1/MaxAdjustedCount, 1]") | ||
|
||
// ErrPrecisionUnderflow is returned when a precision is too great for the range. | ||
var ErrPrecisionUnderflow = errors.New("sampling precision is too great for the range") | ||
|
||
// MinSamplingProbability is the smallest representable probability | ||
// and is the inverse of MaxAdjustedCount. | ||
const MinSamplingProbability = 1.0 / MaxAdjustedCount | ||
const MinSamplingProbability = 1.0 / float64(MaxAdjustedCount) | ||
|
||
// probabilityInRange tests MinSamplingProb <= prob <= 1. | ||
func probabilityInRange(prob float64) bool { | ||
|
@@ -26,67 +23,60 @@ func probabilityInRange(prob float64) bool { | |
// ProbabilityToThreshold converts a probability to a Threshold. It | ||
// returns an error when the probability is out-of-range. | ||
func ProbabilityToThreshold(prob float64) (Threshold, error) { | ||
// Probability cases | ||
if !probabilityInRange(prob) { | ||
return AlwaysSampleThreshold, ErrProbabilityRange | ||
} | ||
|
||
scaled := uint64(math.Round(prob * MaxAdjustedCount)) | ||
|
||
return Threshold{ | ||
unsigned: MaxAdjustedCount - scaled, | ||
}, nil | ||
return ProbabilityToThresholdWithPrecision(prob, NumHexDigits) | ||
} | ||
|
||
// ProbabilityToThresholdWithPrecision is like ProbabilityToThreshold | ||
// with support for reduced precision. The `prec` argument determines | ||
// with support for reduced precision. The `precision` argument determines | ||
// how many significant hex digits will be used to encode the exact | ||
// probability. | ||
func ProbabilityToThresholdWithPrecision(prob float64, prec uint8) (Threshold, error) { | ||
func ProbabilityToThresholdWithPrecision(fraction float64, precision int) (Threshold, error) { | ||
// Assume full precision at 0. | ||
if prec == 0 { | ||
return ProbabilityToThreshold(prob) | ||
if precision == 0 { | ||
precision = NumHexDigits | ||
} | ||
if !probabilityInRange(prob) { | ||
if !probabilityInRange(fraction) { | ||
return AlwaysSampleThreshold, ErrProbabilityRange | ||
} | ||
// Special case for prob == 1. The logic for revising precision | ||
// that follows requires 0 < 1 - prob < 1. | ||
if prob == 1 { | ||
// Special case for prob == 1. | ||
if fraction == 1 { | ||
return AlwaysSampleThreshold, nil | ||
} | ||
|
||
// Adjust precision considering the significance of leading | ||
// zeros. If we can multiply the rejection probability by 16 | ||
// and still be less than 1, then there is a leading zero of | ||
// obligatory precision. | ||
for reject := 1 - prob; reject*16 < 1; { | ||
reject *= 16 | ||
prec++ | ||
} | ||
|
||
// Check if leading zeros plus precision is above the maximum. | ||
// This is called underflow because the requested precision | ||
// leads to complete no significant figures. | ||
if prec > NumHexDigits { | ||
return AlwaysSampleThreshold, ErrPrecisionUnderflow | ||
// Calculate the amount of precision needed to encode the | ||
// threshold with reasonable precision. Here, we count the | ||
// number of leading `0` or `f` characters and automatically | ||
// add precision to preserve relative error near the extremes. | ||
// | ||
// Frexp() normalizes both the fraction and one-minus the | ||
// fraction, because more digits of precision are needed if | ||
// either value is near zero. Frexp returns an exponent <= 0. | ||
// | ||
// If `exp <= -4`, there will be a leading hex `0` or `f`. | ||
// For every multiple of -4, another leading `0` or `f` | ||
// appears, so this raises precision accordingly. | ||
_, expF := math.Frexp(fraction) | ||
_, expR := math.Frexp(1 - fraction) | ||
precision = min(NumHexDigits, max(precision+expF/-hexBits, precision+expR/-hexBits)) | ||
|
||
// Compute the threshold | ||
scaled := uint64(math.Round(fraction * float64(MaxAdjustedCount))) | ||
threshold := MaxAdjustedCount - scaled | ||
|
||
// Round to the specified precision, if less than the maximum. | ||
if shift := hexBits * (NumHexDigits - precision); shift != 0 { | ||
half := uint64(1) << (shift - 1) | ||
threshold += half | ||
threshold >>= shift | ||
threshold <<= shift | ||
Comment on lines
+46
to
+71
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. Note I removed |
||
} | ||
|
||
scaled := uint64(math.Round(prob * MaxAdjustedCount)) | ||
rscaled := MaxAdjustedCount - scaled | ||
shift := 4 * (14 - prec) | ||
half := uint64(1) << (shift - 1) | ||
|
||
rscaled += half | ||
rscaled >>= shift | ||
rscaled <<= shift | ||
|
||
return Threshold{ | ||
unsigned: rscaled, | ||
unsigned: threshold, | ||
}, nil | ||
} | ||
|
||
// Probability is the sampling ratio in the range [MinSamplingProb, 1]. | ||
func (t Threshold) Probability() float64 { | ||
return float64(MaxAdjustedCount-t.unsigned) / MaxAdjustedCount | ||
return float64(MaxAdjustedCount-t.unsigned) / float64(MaxAdjustedCount) | ||
} |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the Go toolchain is reformatting this comment block for me. 🤷