Skip to content

Commit 44939cf

Browse files
Dav1ddewedamija
authored andcommitted
ref(relay): Remove cardinality limiter config from project configs (#112658)
Removes the cardinality limiting configs from the project config. Follow Ups: - Remove cardinality limiter from Relay - Remove cardinality limiting options from options automator - Remove options from Sentry
1 parent e1f87db commit 44939cf

File tree

8 files changed

+1
-531
lines changed

8 files changed

+1
-531
lines changed

src/sentry/models/options/project_option.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"mail:subject_template",
8989
"filters:react-hydration-errors",
9090
"filters:chunk-load-error",
91-
"relay.cardinality-limiter.limits",
9291
]
9392
)
9493

src/sentry/relay/config/__init__.py

Lines changed: 1 addition & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import uuid
55
from collections.abc import Iterable, Mapping, MutableMapping, Sequence
66
from datetime import datetime, timezone
7-
from typing import Any, Literal, NotRequired, TypedDict
7+
from typing import Any, Literal, TypedDict
88

99
import sentry_sdk
1010
from sentry_sdk import capture_exception
@@ -46,7 +46,6 @@
4646
from sentry.relay.datascrubbing import get_datascrubbing_settings, get_pii_config
4747
from sentry.relay.types.generic_filters import GenericFilter
4848
from sentry.relay.utils import to_camel_case_name
49-
from sentry.sentry_metrics.use_case_id_registry import CARDINALITY_LIMIT_USE_CASES
5049
from sentry.utils import metrics
5150
from sentry.utils.http import get_origins
5251
from sentry.utils.options import sample_modulo
@@ -218,103 +217,6 @@ def get_quotas(project: Project, keys: Iterable[ProjectKey] | None = None) -> li
218217
return computed_quotas
219218

220219

221-
class SlidingWindow(TypedDict):
222-
windowSeconds: int
223-
granularitySeconds: int
224-
225-
226-
class CardinalityLimit(TypedDict):
227-
id: str
228-
passive: NotRequired[bool]
229-
window: SlidingWindow
230-
limit: int
231-
scope: Literal["organization", "project"]
232-
namespace: str | None
233-
234-
235-
class CardinalityLimitOption(TypedDict):
236-
rollout_rate: NotRequired[float]
237-
limit: CardinalityLimit
238-
projects: NotRequired[list[int]]
239-
240-
241-
def get_metrics_config(timeout: TimeChecker, project: Project) -> Mapping[str, Any] | None:
242-
metrics_config = {}
243-
244-
if cardinality_limits := get_cardinality_limits(timeout, project):
245-
metrics_config["cardinalityLimits"] = cardinality_limits
246-
247-
return metrics_config or None
248-
249-
250-
def get_cardinality_limits(timeout: TimeChecker, project: Project) -> list[CardinalityLimit] | None:
251-
if options.get("relay.cardinality-limiter.mode") == "disabled":
252-
return None
253-
254-
passive_limits = options.get("relay.cardinality-limiter.passive-limits-by-org").get(
255-
str(project.organization.id), []
256-
)
257-
258-
existing_ids: set[str] = set()
259-
cardinality_limits: list[CardinalityLimit] = []
260-
for namespace in CARDINALITY_LIMIT_USE_CASES:
261-
timeout.check()
262-
option = options.get(f"sentry-metrics.cardinality-limiter.limits.{namespace.value}.per-org")
263-
if not option or not len(option) == 1:
264-
# Multiple quotas are not supported
265-
continue
266-
267-
quota = option[0]
268-
id = namespace.value
269-
270-
limit: CardinalityLimit = {
271-
"id": id,
272-
"window": {
273-
"windowSeconds": quota["window_seconds"],
274-
"granularitySeconds": quota["granularity_seconds"],
275-
},
276-
"limit": quota["limit"],
277-
"scope": "organization",
278-
"namespace": namespace.value,
279-
}
280-
if id in passive_limits:
281-
limit["passive"] = True
282-
cardinality_limits.append(limit)
283-
existing_ids.add(id)
284-
285-
project_limit_options: list[CardinalityLimitOption] = project.get_option(
286-
"relay.cardinality-limiter.limits", []
287-
)
288-
organization_limit_options: list[CardinalityLimitOption] = project.organization.get_option(
289-
"relay.cardinality-limiter.limits", []
290-
)
291-
option_limit_options: list[CardinalityLimitOption] = options.get(
292-
"relay.cardinality-limiter.limits"
293-
)
294-
295-
for clo in project_limit_options + organization_limit_options + option_limit_options:
296-
rollout_rate = clo.get("rollout_rate", 1.0)
297-
if (project.organization.id % 100000) / 100000 >= rollout_rate:
298-
continue
299-
300-
projects = clo.get("projects")
301-
if projects is not None and project.id not in projects:
302-
# projects list is defined but the current project is not in the list
303-
continue
304-
305-
try:
306-
limit = clo["limit"]
307-
if clo["limit"]["id"] in existing_ids:
308-
# skip if a limit with the same id already exists
309-
continue
310-
cardinality_limits.append(limit)
311-
existing_ids.add(clo["limit"]["id"])
312-
except KeyError:
313-
pass
314-
315-
return cardinality_limits
316-
317-
318220
def get_project_config(
319221
project: Project, project_keys: Iterable[ProjectKey] | None = None
320222
) -> ProjectConfig:
@@ -1046,8 +948,6 @@ def _get_project_config(
1046948

1047949
config["breakdownsV2"] = project.get_option("sentry:breakdowns")
1048950

1049-
add_experimental_config(config, "metrics", get_metrics_config, project)
1050-
1051951
if _should_extract_transaction_metrics(project):
1052952
add_experimental_config(
1053953
config,

tests/sentry/core/endpoints/test_project_details.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -795,21 +795,6 @@ def test_options(self) -> None:
795795
assert project.get_option("filters:react-hydration-errors", "1")
796796
assert project.get_option("filters:chunk-load-error", "1")
797797

798-
self.project.update_option(
799-
"relay.cardinality-limiter.limits",
800-
[
801-
{
802-
"limit": {
803-
"id": "project-override-custom",
804-
"window": {"windowSeconds": 3600, "granularitySeconds": 600},
805-
"limit": 1000,
806-
"namespace": "custom",
807-
"scope": "name",
808-
}
809-
}
810-
],
811-
)
812-
813798
def test_preprod_snapshot_pr_comments_option(self) -> None:
814799
self.get_success_response(
815800
self.org_slug, self.proj_slug, preprodSnapshotPrCommentsEnabled=False

tests/sentry/relay/snapshots/test_config/test_project_config_cardinality_limits/False/REGION.pysnap

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/sentry/relay/snapshots/test_config/test_project_config_cardinality_limits/False/REGION.pysnap.new

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/sentry/relay/snapshots/test_config/test_project_config_cardinality_limits/True/REGION.pysnap

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/sentry/relay/snapshots/test_config/test_project_config_cardinality_limits/True/REGION.pysnap.new

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)