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

ref(relay): Make cardinality limits more configurable #68158

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sentry-arroyo>=2.16.5
sentry-kafka-schemas>=0.1.65
sentry-ophio==0.2.6
sentry-redis-tools>=0.1.7
sentry-relay>=0.8.55
sentry-relay>=0.8.56
sentry-sdk>=1.44.0
snuba-sdk>=2.0.31
simplejson>=3.17.6
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ sentry-forked-djangorestframework-stubs==3.14.5.post1
sentry-kafka-schemas==0.1.65
sentry-ophio==0.2.6
sentry-redis-tools==0.1.7
sentry-relay==0.8.55
sentry-relay==0.8.56
sentry-sdk==1.44.0
sentry-usage-accountant==0.0.10
simplejson==3.17.6
Expand Down
2 changes: 1 addition & 1 deletion requirements-frozen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ sentry-arroyo==2.16.5
sentry-kafka-schemas==0.1.65
sentry-ophio==0.2.6
sentry-redis-tools==0.1.7
sentry-relay==0.8.55
sentry-relay==0.8.56
sentry-sdk==1.44.0
sentry-usage-accountant==0.0.10
simplejson==3.17.6
Expand Down
9 changes: 9 additions & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,15 @@
register(
"relay.cardinality-limiter.error-sample-rate", default=0.01, flags=FLAG_AUTOMATOR_MODIFIABLE
)
# List of additional cardinality limits and selectors.
#
# ```
# {
# "rollout_rate": 0.001,
# "limit": { .. Cardinality Limit .. }
# }
# ```
register("relay.cardinality-limiter.limits", default=[], flags=FLAG_AUTOMATOR_MODIFIABLE)

# Controls the encoding used in Relay for encoding distributions and sets
# when writing to Kafka.
Expand Down
20 changes: 17 additions & 3 deletions src/sentry/relay/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ class CardinalityLimit(TypedDict):
namespace: str | None


class CardinalityLimitOption(TypedDict):
rollout_rate: NotRequired[float]
limit: CardinalityLimit


def get_metrics_config(timeout: TimeChecker, project: Project) -> Mapping[str, Any] | None:
metrics_config = {}

Expand Down Expand Up @@ -280,6 +285,18 @@ def get_metrics_config(timeout: TimeChecker, project: Project) -> Mapping[str, A
if id in passive_limits:
limit["passive"] = True
cardinality_limits.append(limit)

clos: list[CardinalityLimitOption] = options.get("relay.cardinality-limiter.limits")
for clo in clos:
rollout_rate = clo.get("rollout_rate", 1.0)
if (project.organization.id % 100000) / 100000 >= rollout_rate:
continue

try:
cardinality_limits.append(clo["limit"])
except KeyError:
pass

metrics_config["cardinalityLimits"] = cardinality_limits

if features.has("organizations:metrics-blocking", project.organization):
Expand Down Expand Up @@ -828,9 +845,6 @@ def _get_project_config(
if _should_extract_abnormal_mechanism(project)
else EXTRACT_METRICS_VERSION
),
"drop": features.has(
"organizations:release-health-drop-sessions", project.organization
),
}

performance_score_profiles = [
Expand Down
3 changes: 1 addition & 2 deletions tests/sentry/api/endpoints/test_relay_projectconfigs_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_session_metrics_extraction(call_endpoint, task_runner, drop_sessions):

for config in result["configs"].values():
config = config["config"]
assert config["sessionMetrics"] == {"version": 1, "drop": drop_sessions}
assert config["sessionMetrics"] == {"version": 1}


@django_db_all
Expand All @@ -378,5 +378,4 @@ def test_session_metrics_abnormal_mechanism_tag_extraction(
config = config["config"]
assert config["sessionMetrics"] == {
"version": 2 if abnormal_mechanism_rollout else 1,
"drop": False,
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ cardinalityLimits:
window:
granularitySeconds: 600
windowSeconds: 3600
- id: test2
limit: 80
report: true
scope: name
window:
granularitySeconds: 800
windowSeconds: 8000
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ cardinalityLimits:
window:
granularitySeconds: 600
windowSeconds: 3600
- id: test2
limit: 80
report: true
scope: name
window:
granularitySeconds: 800
windowSeconds: 8000
23 changes: 22 additions & 1 deletion tests/sentry/relay/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ def test_project_config_with_organizations_metrics_extraction(
session_metrics = get_path(cfg, "config", "sessionMetrics")
if has_metrics_extraction:
assert session_metrics == {
"drop": False,
"version": 2 if abnormal_mechanism_rollout else 1,
}
else:
Expand Down Expand Up @@ -957,6 +956,28 @@ def test_project_config_cardinality_limits(default_project, insta_snapshot, pass
]
}

options["relay.cardinality-limiter.limits"] = [
{
"rollout_rate": 0,
"limit": {
"id": "test1",
"window": {"windowSeconds": 7000, "granularitySeconds": 700},
"limit": 70,
"scope": "name",
},
},
{
"rollout_rate": 1,
"limit": {
"id": "test2",
"window": {"windowSeconds": 8000, "granularitySeconds": 800},
"limit": 80,
"scope": "name",
"report": True,
},
},
]

features = Feature({"organizations:relay-cardinality-limiter": True})

with override_options(options), features:
Expand Down
Loading