-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sampling): Reservoir sampling (#2550)
Relay implementation of the reservoir project: getsentry/sentry#54449 Reservoir bias uses a type of `SamplingRule` which will sample all matches until a certain limit has been reached. This limit is tracked both locally on each relay, and with a global synchronized one in redis that procesisng relays can have access to. The redis counter will update the local counter if it's available. The counters are saved on the `Project` struct, with a Mutex<BTreeMap<Ruleid, i64>> . When we send an envelope for processing we send its corresponding project counters in the `ProcessEnvelopeState` to the `EnvelopeProcessorService`. There, in the `dynamic-sampling` crate, we introduce a `ReservoirEvaluator`, which will, when a reservoir rule is matching, check if the rule has been reached or not by using the local counters we sent or if applicable the redis global count. The `ReservoirEvaluator` also takes care of updating both redis and the local counter. After the limit is reached, the rule is no longer valid and will be ignored, so that the normal `SampleRate` and `Factor` variant of `SamplingValue` will apply. Sentry is responsible for removing the reservoir rule from the `SamplingConfig` when it has reached its limit. Whenever we receive a new `ProjectConfig`, we remove all the reservoir counters from its project that are no longer in the `DynamicSamplingConfig`. regarding the use of mutex: We use try_lock to avoid getting blocked in case the mutex is already in use. There's two reasons it might be blocked. 1. Another thread is handling a reservoir rule from the same project at the same time. 2. We are in the process of removing counters from that same project.
- Loading branch information
Showing
13 changed files
with
420 additions
and
45 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.