Skip to content

Commit 7daa270

Browse files
author
Riccardo Busetti
authored
ref(dynamic-sampling): Remove rules v1 (#44581)
1 parent 0519956 commit 7daa270

19 files changed

+61
-823
lines changed

src/sentry/api/endpoints/project_details.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ def get(self, request: Request, project) -> Response:
384384
include_rules = request.GET.get("includeDynamicSamplingRules") == "1"
385385
if include_rules and is_active_superuser(request):
386386
data["dynamicSamplingRules"] = {
387-
"rules": generate_rules(project),
388-
"rulesV2": generate_rules(project, True),
387+
"rules": [],
388+
"rulesV2": generate_rules(project),
389389
}
390390
else:
391391
data["dynamicSamplingBiases"] = None

src/sentry/dynamic_sampling/rules/base.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
from sentry import quotas
66
from sentry.dynamic_sampling.rules.biases.base import Bias, BiasParams
7-
from sentry.dynamic_sampling.rules.combine import (
8-
get_relay_biases_combinator,
9-
get_relay_biases_combinator_v2,
10-
)
7+
from sentry.dynamic_sampling.rules.combine import get_relay_biases_combinator
118
from sentry.dynamic_sampling.rules.logging import log_rules
129
from sentry.dynamic_sampling.rules.utils import PolymorphicRule, RuleType, get_enabled_user_biases
1310
from sentry.models import Project
@@ -29,7 +26,6 @@ def _get_rules_of_enabled_biases(
2926
base_sample_rate: float,
3027
enabled_biases: Set[str],
3128
combined_biases: OrderedDict[RuleType, Bias],
32-
version_2: bool = False,
3329
) -> List[PolymorphicRule]:
3430
rules = []
3531

@@ -44,18 +40,13 @@ def _get_rules_of_enabled_biases(
4440
rules += bias.get_rules(BiasParams(project, base_sample_rate))
4541

4642
# We want to log only rules v2, to avoid confusion and duplication.
47-
if version_2:
48-
log_rules(project.organization.id, project.id, rules)
43+
log_rules(project.organization.id, project.id, rules)
4944

5045
return rules
5146

5247

53-
def generate_rules(project: Project, version_2: bool = False) -> List[PolymorphicRule]:
48+
def generate_rules(project: Project) -> List[PolymorphicRule]:
5449
try:
55-
biases_combinator = (
56-
get_relay_biases_combinator_v2() if version_2 else get_relay_biases_combinator()
57-
)
58-
5950
return _get_rules_of_enabled_biases(
6051
project,
6152
get_guarded_blended_sample_rate(project),
@@ -65,8 +56,7 @@ def generate_rules(project: Project, version_2: bool = False) -> List[Polymorphi
6556
# * Rules generator
6657
# * Bias
6758
# check in the dynamic_sampling/rules/biases module how existing biases are implemented.
68-
biases_combinator.get_combined_biases(),
69-
version_2,
59+
get_relay_biases_combinator().get_combined_biases(),
7060
)
7161
except Exception as e:
7262
sentry_sdk.capture_exception(e)

src/sentry/dynamic_sampling/rules/biases/boost_environments_bias.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@ def get_bias_data(self, bias_params: BiasParams) -> BiasData:
2323

2424

2525
class BoostEnvironmentsRulesGenerator(BiasRulesGenerator):
26-
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
27-
return [
28-
{
29-
"sampleRate": 1,
30-
"type": "trace",
31-
"condition": {
32-
"op": "or",
33-
"inner": [
34-
{
35-
"op": "glob",
36-
"name": "trace.environment",
37-
"value": ENVIRONMENT_GLOBS,
38-
"options": {"ignoreCase": True},
39-
}
40-
],
41-
},
42-
"active": True,
43-
"id": bias_data["id"],
44-
}
45-
]
46-
47-
48-
class BoostEnvironmentsRulesGeneratorV2(BiasRulesGenerator):
4926
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
5027
return [
5128
{
@@ -74,8 +51,3 @@ def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
7451
class BoostEnvironmentsBias(Bias):
7552
def __init__(self) -> None:
7653
super().__init__(BoostEnvironmentsDataProvider, BoostEnvironmentsRulesGenerator)
77-
78-
79-
class BoostEnvironmentsBiasV2(Bias):
80-
def __init__(self) -> None:
81-
super().__init__(BoostEnvironmentsDataProvider, BoostEnvironmentsRulesGeneratorV2)

src/sentry/dynamic_sampling/rules/biases/boost_key_transactions_bias.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,6 @@ def get_bias_data(self, bias_params: BiasParams) -> BiasData:
2626

2727

2828
class BoostKeyTransactionsRulesGenerator(BiasRulesGenerator):
29-
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
30-
if len(bias_data["keyTransactions"]) == 0:
31-
return []
32-
33-
return [
34-
{
35-
"sampleRate": bias_data["sampleRate"],
36-
"type": "transaction",
37-
"condition": {
38-
"op": "or",
39-
"inner": [
40-
{
41-
"op": "eq",
42-
"name": "event.transaction",
43-
"value": bias_data["keyTransactions"],
44-
"options": {"ignoreCase": True},
45-
}
46-
],
47-
},
48-
"active": True,
49-
"id": bias_data["id"],
50-
}
51-
]
52-
53-
54-
class BoostKeyTransactionsRulesGeneratorV2(BiasRulesGenerator):
5529
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
5630
if len(bias_data["keyTransactions"]) == 0:
5731
return []
@@ -83,8 +57,3 @@ def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
8357
class BoostKeyTransactionsBias(Bias):
8458
def __init__(self) -> None:
8559
super().__init__(BoostKeyTransactionsDataProvider, BoostKeyTransactionsRulesGenerator)
86-
87-
88-
class BoostKeyTransactionsBiasV2(Bias):
89-
def __init__(self) -> None:
90-
super().__init__(BoostKeyTransactionsDataProvider, BoostKeyTransactionsRulesGeneratorV2)

src/sentry/dynamic_sampling/rules/biases/boost_latest_releases_bias.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,59 +32,6 @@ def get_bias_data(self, bias_params: BiasParams) -> BiasData:
3232

3333

3434
class BoostLatestReleasesRulesGenerator(BiasRulesGenerator):
35-
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
36-
boosted_releases = bias_data["boostedReleases"]
37-
38-
return cast(
39-
List[PolymorphicRule],
40-
[
41-
{
42-
"sampleRate": bias_data["sampleRate"],
43-
"type": "trace",
44-
"active": True,
45-
"condition": {
46-
"op": "and",
47-
"inner": [
48-
{
49-
"op": "eq",
50-
"name": "trace.release",
51-
"value": [boosted_release.version],
52-
},
53-
{
54-
"op": "eq",
55-
"name": "trace.environment",
56-
# When environment is None, it will be mapped to equivalent null in json.
57-
# When Relay receives a rule with "value": null it will match it against events without
58-
# the environment tag set.
59-
"value": boosted_release.environment,
60-
},
61-
],
62-
},
63-
"id": bias_data["id"] + idx,
64-
"timeRange": {
65-
"start": str(
66-
datetime.utcfromtimestamp(boosted_release.timestamp).replace(tzinfo=UTC)
67-
),
68-
"end": str(
69-
datetime.utcfromtimestamp(
70-
boosted_release.timestamp
71-
+ boosted_release.platform.time_to_adoption
72-
).replace(tzinfo=UTC)
73-
),
74-
},
75-
# We want to use the linear decaying function for latest release boosting, with the goal
76-
# of interpolating the adoption growth with the reduction in sample rate.
77-
"decayingFn": {
78-
"type": "linear",
79-
"decayedSampleRate": bias_data["baseSampleRate"],
80-
},
81-
}
82-
for idx, boosted_release in enumerate(boosted_releases)
83-
],
84-
)
85-
86-
87-
class BoostLatestReleasesRulesGeneratorV2(BiasRulesGenerator):
8835
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
8936
boosted_releases = bias_data["boostedReleases"]
9037

@@ -143,8 +90,3 @@ def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
14390
class BoostLatestReleasesBias(Bias):
14491
def __init__(self) -> None:
14592
super().__init__(BoostLatestReleasesDataProvider, BoostLatestReleasesRulesGenerator)
146-
147-
148-
class BoostLatestReleasesBiasV2(Bias):
149-
def __init__(self) -> None:
150-
super().__init__(BoostLatestReleasesDataProvider, BoostLatestReleasesRulesGeneratorV2)

src/sentry/dynamic_sampling/rules/biases/ignore_health_checks_bias.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,6 @@ def get_bias_data(self, bias_params: BiasParams) -> BiasData:
3737

3838

3939
class IgnoreHealthChecksRulesGenerator(BiasRulesGenerator):
40-
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
41-
return [
42-
{
43-
"sampleRate": bias_data["sampleRate"],
44-
"type": "transaction",
45-
"condition": {
46-
"op": "or",
47-
"inner": [
48-
{
49-
"op": "glob",
50-
"name": "event.transaction",
51-
"value": bias_data["healthCheckGlobs"],
52-
"options": {"ignoreCase": True},
53-
}
54-
],
55-
},
56-
"active": True,
57-
"id": bias_data["id"],
58-
}
59-
]
60-
61-
62-
class IgnoreHealthChecksRulesGeneratorV2(BiasRulesGenerator):
6340
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
6441
return [
6542
{
@@ -85,8 +62,3 @@ def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
8562
class IgnoreHealthChecksBias(Bias):
8663
def __init__(self) -> None:
8764
super().__init__(IgnoreHealthChecksDataProvider, IgnoreHealthChecksRulesGenerator)
88-
89-
90-
class IgnoreHealthChecksBiasV2(Bias):
91-
def __init__(self) -> None:
92-
super().__init__(IgnoreHealthChecksDataProvider, IgnoreHealthChecksRulesGeneratorV2)

src/sentry/dynamic_sampling/rules/biases/uniform_bias.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,6 @@ def get_bias_data(self, bias_params: BiasParams) -> BiasData:
1919

2020

2121
class UniformRulesGenerator(BiasRulesGenerator):
22-
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
23-
return [
24-
{
25-
"sampleRate": bias_data["sampleRate"],
26-
"type": "trace",
27-
"active": True,
28-
"condition": {
29-
"op": "and",
30-
"inner": [],
31-
},
32-
"id": bias_data["id"],
33-
}
34-
]
35-
36-
37-
class UniformRulesGeneratorV2(BiasRulesGenerator):
3822
def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
3923
return [
4024
{
@@ -56,8 +40,3 @@ def _generate_bias_rules(self, bias_data: BiasData) -> List[PolymorphicRule]:
5640
class UniformBias(Bias):
5741
def __init__(self) -> None:
5842
super().__init__(UniformDataProvider, UniformRulesGenerator)
59-
60-
61-
class UniformBiasV2(Bias):
62-
def __init__(self) -> None:
63-
super().__init__(UniformDataProvider, UniformRulesGeneratorV2)
Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
1-
from sentry.dynamic_sampling.rules.biases.boost_environments_bias import (
2-
BoostEnvironmentsBias,
3-
BoostEnvironmentsBiasV2,
4-
)
1+
from sentry.dynamic_sampling.rules.biases.boost_environments_bias import BoostEnvironmentsBias
52
from sentry.dynamic_sampling.rules.biases.boost_key_transactions_bias import (
63
BoostKeyTransactionsBias,
7-
BoostKeyTransactionsBiasV2,
8-
)
9-
from sentry.dynamic_sampling.rules.biases.boost_latest_releases_bias import (
10-
BoostLatestReleasesBias,
11-
BoostLatestReleasesBiasV2,
12-
)
13-
from sentry.dynamic_sampling.rules.biases.ignore_health_checks_bias import (
14-
IgnoreHealthChecksBias,
15-
IgnoreHealthChecksBiasV2,
164
)
17-
from sentry.dynamic_sampling.rules.biases.uniform_bias import UniformBias, UniformBiasV2
5+
from sentry.dynamic_sampling.rules.biases.boost_latest_releases_bias import BoostLatestReleasesBias
6+
from sentry.dynamic_sampling.rules.biases.ignore_health_checks_bias import IgnoreHealthChecksBias
7+
from sentry.dynamic_sampling.rules.biases.uniform_bias import UniformBias
188
from sentry.dynamic_sampling.rules.combinators.base import BiasesCombinator
199
from sentry.dynamic_sampling.rules.combinators.ordered_combinator import OrderedBiasesCombinator
2010
from sentry.dynamic_sampling.rules.utils import RuleType
2111

2212

2313
def get_relay_biases_combinator() -> BiasesCombinator:
24-
# The default combinator is the ordered combinator, which will keep the insertion order of the rules.
2514
default_combinator = OrderedBiasesCombinator()
2615

27-
# The combination depends on the default_combinator used but in case of the ordered combinator the first combined
28-
# rule will be the first rule in the output (e.g., UNIFORM_RULE will be the last).
29-
#
30-
# The ordering is very important, especially because relay performs matching following a FIFO matching algorithm.
31-
#
32-
# If you need to add any new bias, add it here after having created all the necessary classes.
3316
default_combinator.add(RuleType.BOOST_KEY_TRANSACTIONS_RULE, BoostKeyTransactionsBias())
3417
default_combinator.add(RuleType.IGNORE_HEALTH_CHECKS_RULE, IgnoreHealthChecksBias())
3518

@@ -38,16 +21,3 @@ def get_relay_biases_combinator() -> BiasesCombinator:
3821
default_combinator.add(RuleType.UNIFORM_RULE, UniformBias())
3922

4023
return default_combinator
41-
42-
43-
def get_relay_biases_combinator_v2() -> BiasesCombinator:
44-
default_combinator = OrderedBiasesCombinator()
45-
46-
default_combinator.add(RuleType.BOOST_KEY_TRANSACTIONS_RULE, BoostKeyTransactionsBiasV2())
47-
default_combinator.add(RuleType.IGNORE_HEALTH_CHECKS_RULE, IgnoreHealthChecksBiasV2())
48-
49-
default_combinator.add(RuleType.BOOST_ENVIRONMENTS_RULE, BoostEnvironmentsBiasV2())
50-
default_combinator.add(RuleType.BOOST_LATEST_RELEASES_RULE, BoostLatestReleasesBiasV2())
51-
default_combinator.add(RuleType.UNIFORM_RULE, UniformBiasV2())
52-
53-
return default_combinator

src/sentry/dynamic_sampling/rules/logging.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import sentry_sdk
55

66
from sentry.dynamic_sampling.rules.utils import (
7-
DecayingFnV1,
8-
DecayingFnV2,
7+
DecayingFn,
98
PolymorphicRule,
109
RuleType,
1110
get_rule_hash,
@@ -99,7 +98,7 @@ def _format_rules(
9998

10099
def _extract_info_from_rule(
101100
rule_type: RuleType, rule: PolymorphicRule
102-
) -> Dict[str, Union[DecayingFnV1, DecayingFnV2, List[str], str, None]]:
101+
) -> Dict[str, Union[DecayingFn, List[str], str, None]]:
103102
if rule_type == RuleType.BOOST_ENVIRONMENTS_RULE:
104103
return {"environments": rule["condition"]["inner"][0]["value"]}
105104
elif rule_type == RuleType.BOOST_LATEST_RELEASES_RULE:

0 commit comments

Comments
 (0)