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

feat(dynamic-sampling): Implement dynamic factor function and new factor-based rules [TET-702] #44500

Merged
merged 14 commits into from
Feb 17, 2023

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Feb 13, 2023

This PR aims at implementing the new dynamic factor function and factor-based rules introduced in Relay with the following PR -> getsentry/relay#1790.

@iambriccardo iambriccardo marked this pull request as ready for review February 14, 2023 12:31
@iambriccardo iambriccardo requested a review from a team as a code owner February 14, 2023 12:31
@iambriccardo iambriccardo requested a review from a team February 14, 2023 12:31
@iambriccardo iambriccardo requested a review from a team as a code owner February 14, 2023 12:31
"The dynamic factor function requires a sample rate in the interval [0.0, 1.0]."
)

return float(x / x**base_sample_rate)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO function doc string should demonstrate this formula rather then saying in general def a factor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, I will describe it.

@@ -12,19 +12,23 @@
)
from sentry.dynamic_sampling.rules.helpers.latest_releases import ProjectBoostedReleases
from sentry.dynamic_sampling.rules.utils import (
RELEASE_BOOST_FACTOR,
BOOST_LATEST_RELEASES_DECAYED_FACTOR,
BOOST_LATEST_RELEASES_FACTOR,
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't understand the purpose of this rename?

RELEASE_BOOST_FACTOR,

sounds IMO correct, wdyt @RaduW ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's aligned with the file naming, this is the rationale.

@@ -331,7 +331,7 @@ def test_generate_rules_return_uniform_rules_and_key_transaction_rule_with_many_
"op": "or",
},
"id": 1003,
"samplingValue": {"type": "sampleRate", "value": 0.5},
"samplingValue": {"type": "factor", "value": 1.5},
Copy link
Contributor

Choose a reason for hiding this comment

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

please use constants here - we do the same for globs.

for each rule based on the base_sample_rate of the project.

The function decreases the factor from x to 1 in the interval [0.0, 1.0] which means that a user with
base_sample_rate = 0.0 will have a factor of x, whereas with base_sample_rate = 1.0 we will have a factor of 1.
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we will raise an exception if sample rate is 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. It's not a problem mathematically but it doesn't make sense to compute any factors if that is the case.

Copy link
Contributor

@andriisoldatenko andriisoldatenko Feb 16, 2023

Choose a reason for hiding this comment

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

to demonstrate this you can add assert base_sample_rate == 0.0

base_sample_rate = 0.0 will have a factor of x, whereas with base_sample_rate = 1.0 we will have a factor of 1.

The high-level idea is that we want to reduce the factor the bigger the base_sample_rate becomes, this is done
because multiplication will exceed 1 very quickly in case we don't reduce the factor.
Copy link
Contributor

Choose a reason for hiding this comment

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

i think you can keep only this sentence and remove first two.

Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

LGTM! I did not review the dynamic factor conversion function in detail, but I assume it has been discussed before.

@patch("sentry.dynamic_sampling.rules.base.quotas.get_blended_sample_rate")
def test_generate_rules_return_uniform_rules_and_key_transaction_rule(
get_blended_sample_rate, default_project, default_team
get_blended_sample_rate, apply_dynamic_factor, default_project, default_team
Copy link
Member

Choose a reason for hiding this comment

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

Why do these tests mock apply_dynamic_factor? Couldn't we just assert on the real return value?

@iambriccardo iambriccardo merged commit 7f5822a into master Feb 17, 2023
@iambriccardo iambriccardo deleted the riccardo/feat/dynamic-factor-function branch February 17, 2023 10:20
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants