Skip to content

Commit e094d24

Browse files
authored
ref(similarity): Add killswitch to delete record task (#74212)
Move similarity killswitch check into utils file Check killswitch before calling record delete functions
1 parent a0f089a commit e094d24

File tree

3 files changed

+52
-38
lines changed

3 files changed

+52
-38
lines changed

src/sentry/grouping/ingest/seer.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
event_content_is_seer_eligible,
1515
filter_null_from_event_title,
1616
get_stacktrace_string,
17+
killswitch_enabled,
1718
)
1819
from sentry.utils import metrics
1920
from sentry.utils.safe import get_path
@@ -53,7 +54,7 @@ def should_call_seer_for_grouping(event: Event, primary_hashes: CalculatedHashes
5354
# and rate limiting friends instead happens in the `with_circuit_breaker` helper used where
5455
# `get_seer_similar_issues` is actually called. (It has to be there in order for it to track
5556
# errors arising from that call.)
56-
if _killswitch_enabled(event, project) or _ratelimiting_enabled(event, project):
57+
if killswitch_enabled(project.id, event) or _ratelimiting_enabled(event, project):
5758
return False
5859

5960
return True
@@ -96,42 +97,6 @@ def _has_customized_fingerprint(event: Event, primary_hashes: CalculatedHashes)
9697
return False
9798

9899

99-
def _killswitch_enabled(event: Event, project: Project) -> bool:
100-
"""
101-
Check both the global and similarity-specific Seer killswitches.
102-
"""
103-
104-
logger_extra = {"event_id": event.event_id, "project_id": project.id}
105-
106-
if options.get("seer.global-killswitch.enabled"):
107-
logger.warning(
108-
"should_call_seer_for_grouping.seer_global_killswitch_enabled",
109-
extra=logger_extra,
110-
)
111-
metrics.incr("grouping.similarity.seer_global_killswitch_enabled")
112-
metrics.incr(
113-
"grouping.similarity.did_call_seer",
114-
sample_rate=1.0,
115-
tags={"call_made": False, "blocker": "global-killswitch"},
116-
)
117-
return True
118-
119-
if options.get("seer.similarity-killswitch.enabled"):
120-
logger.warning(
121-
"should_call_seer_for_grouping.seer_similarity_killswitch_enabled",
122-
extra=logger_extra,
123-
)
124-
metrics.incr("grouping.similarity.seer_similarity_killswitch_enabled")
125-
metrics.incr(
126-
"grouping.similarity.did_call_seer",
127-
sample_rate=1.0,
128-
tags={"call_made": False, "blocker": "similarity-killswitch"},
129-
)
130-
return True
131-
132-
return False
133-
134-
135100
def _ratelimiting_enabled(event: Event, project: Project) -> bool:
136101
"""
137102
Check both the global and project-based Seer similarity ratelimits.

src/sentry/seer/similarity/utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import logging
22
from typing import Any, TypeVar
33

4+
from sentry import options
45
from sentry.eventstore.models import Event
6+
from sentry.utils import metrics
57
from sentry.utils.safe import get_path
68

79
logger = logging.getLogger(__name__)
@@ -118,6 +120,42 @@ def event_content_is_seer_eligible(event: Event) -> bool:
118120
return True
119121

120122

123+
def killswitch_enabled(project_id: int, event: Event | None = None) -> bool:
124+
"""
125+
Check both the global and similarity-specific Seer killswitches.
126+
"""
127+
128+
logger_extra = {"event_id": event.event_id if event else None, "project_id": project_id}
129+
130+
if options.get("seer.global-killswitch.enabled"):
131+
logger.warning(
132+
"should_call_seer_for_grouping.seer_global_killswitch_enabled",
133+
extra=logger_extra,
134+
)
135+
metrics.incr("grouping.similarity.seer_global_killswitch_enabled")
136+
metrics.incr(
137+
"grouping.similarity.did_call_seer",
138+
sample_rate=1.0,
139+
tags={"call_made": False, "blocker": "global-killswitch"},
140+
)
141+
return True
142+
143+
if options.get("seer.similarity-killswitch.enabled"):
144+
logger.warning(
145+
"should_call_seer_for_grouping.seer_similarity_killswitch_enabled",
146+
extra=logger_extra,
147+
)
148+
metrics.incr("grouping.similarity.seer_similarity_killswitch_enabled")
149+
metrics.incr(
150+
"grouping.similarity.did_call_seer",
151+
sample_rate=1.0,
152+
tags={"call_made": False, "blocker": "similarity-killswitch"},
153+
)
154+
return True
155+
156+
return False
157+
158+
121159
def filter_null_from_event_title(title: str) -> str:
122160
"""
123161
Filter out null bytes from event title so that it can be saved in records table.

src/sentry/tasks/delete_seer_grouping_records.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
delete_grouping_records_by_hash,
99
delete_project_grouping_records,
1010
)
11+
from sentry.seer.similarity.utils import killswitch_enabled
1112
from sentry.silo.base import SiloMode
1213
from sentry.tasks.base import instrumented_task
1314

@@ -33,6 +34,9 @@ def delete_seer_grouping_records_by_hash(
3334
Task to delete seer grouping records by hash list.
3435
Calls the seer delete by hash endpoint with batches of hashes of size `BATCH_SIZE`.
3536
"""
37+
if killswitch_enabled(project_id):
38+
return
39+
3640
batch_size = options.get("embeddings-grouping.seer.delete-record-batch-size")
3741
len_hashes = len(hashes)
3842
end_index = min(last_deleted_index + batch_size, len_hashes)
@@ -48,7 +52,11 @@ def call_delete_seer_grouping_records_by_hash(
4852
if group_ids:
4953
group = Group.objects.get(id=group_ids[0])
5054
project = group.project if group else None
51-
if project and features.has("projects:similarity-embeddings-delete-by-hash", project):
55+
if (
56+
project
57+
and features.has("projects:similarity-embeddings-delete-by-hash", project)
58+
and not killswitch_enabled(project.id)
59+
):
5260
# TODO (jangjodi): once we store seer grouping info in GroupHash, we should filter by that here
5361
group_hash_objects = GroupHash.objects.filter(
5462
project_id=project.id, group__id__in=group_ids
@@ -75,5 +83,8 @@ def call_seer_delete_project_grouping_records(
7583
*args: Any,
7684
**kwargs: Any,
7785
) -> None:
86+
if killswitch_enabled(project_id):
87+
return
88+
7889
logger.info("calling seer delete records by project", extra={"project_id": project_id})
7990
delete_project_grouping_records(project_id)

0 commit comments

Comments
 (0)