Skip to content

Commit 5014040

Browse files
committed
pass grouphash to should_call_seer_for_grouping
1 parent 9816bc4 commit 5014040

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
lines changed

src/sentry/grouping/ingest/seer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
logger = logging.getLogger("sentry.events.grouping")
3838

3939

40-
def should_call_seer_for_grouping(event: Event, variants: dict[str, BaseVariant]) -> bool:
40+
def should_call_seer_for_grouping(
41+
event: Event, variants: dict[str, BaseVariant], event_grouphash: GroupHash
42+
) -> bool:
4143
"""
4244
Use event content, feature flags, rate limits, killswitches, seer health, etc. to determine
4345
whether a call to Seer should be made.
@@ -366,7 +368,7 @@ def maybe_check_seer_for_matching_grouphash(
366368
) -> GroupHash | None:
367369
seer_matched_grouphash = None
368370

369-
if should_call_seer_for_grouping(event, variants):
371+
if should_call_seer_for_grouping(event, variants, event_grouphash):
370372
record_did_call_seer_metric(event, call_made=True, blocker="none")
371373

372374
try:

tests/sentry/grouping/ingest/test_seer.py

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
maybe_check_seer_for_matching_grouphash,
1616
should_call_seer_for_grouping,
1717
)
18+
from sentry.grouping.utils import hash_from_values
1819
from sentry.grouping.variants import BaseVariant
1920
from sentry.models.grouphash import GroupHash
2021
from sentry.models.grouphashmetadata import GroupHashMetadata
@@ -65,14 +66,16 @@ def setUp(self) -> None:
6566
self.stacktrace_string = get_stacktrace_string(
6667
get_grouping_info_from_variants(self.variants)
6768
)
69+
self.event_grouphash = GroupHash(project_id=self.project.id, hash="908415")
6870

6971
def test_obeys_feature_enablement_check(self) -> None:
7072
for backfill_completed_option, expected_result in [(None, False), (11211231, True)]:
7173
self.project.update_option(
7274
"sentry:similarity_backfill_completed", backfill_completed_option
7375
)
7476
assert (
75-
should_call_seer_for_grouping(self.event, self.variants) is expected_result
77+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
78+
is expected_result
7679
), f"Case {backfill_completed_option} failed."
7780

7881
def test_obeys_content_filter(self) -> None:
@@ -83,21 +86,30 @@ def test_obeys_content_filter(self) -> None:
8386
"sentry.grouping.ingest.seer._event_content_is_seer_eligible",
8487
return_value=content_eligibility,
8588
):
86-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
89+
assert (
90+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
91+
is expected_result
92+
)
8793

8894
def test_obeys_global_seer_killswitch(self) -> None:
8995
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
9096

9197
for killswitch_enabled, expected_result in [(True, False), (False, True)]:
9298
with override_options({"seer.global-killswitch.enabled": killswitch_enabled}):
93-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
99+
assert (
100+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
101+
is expected_result
102+
)
94103

95104
def test_obeys_similarity_service_killswitch(self) -> None:
96105
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
97106

98107
for killswitch_enabled, expected_result in [(True, False), (False, True)]:
99108
with override_options({"seer.similarity-killswitch.enabled": killswitch_enabled}):
100-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
109+
assert (
110+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
111+
is expected_result
112+
)
101113

102114
def test_obeys_project_specific_killswitch(self) -> None:
103115
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
@@ -106,7 +118,10 @@ def test_obeys_project_specific_killswitch(self) -> None:
106118
with override_options(
107119
{"seer.similarity.grouping_killswitch_projects": blocked_projects}
108120
):
109-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
121+
assert (
122+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
123+
is expected_result
124+
)
110125

111126
def test_obeys_global_ratelimit(self) -> None:
112127
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
@@ -118,7 +133,10 @@ def test_obeys_global_ratelimit(self) -> None:
118133
is_enabled if key == "seer:similarity:global-limit" else False
119134
),
120135
):
121-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
136+
assert (
137+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
138+
is expected_result
139+
)
122140

123141
def test_obeys_project_ratelimit(self) -> None:
124142
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
@@ -132,7 +150,10 @@ def test_obeys_project_ratelimit(self) -> None:
132150
else False
133151
),
134152
):
135-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
153+
assert (
154+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
155+
is expected_result
156+
)
136157

137158
def test_obeys_circuit_breaker(self) -> None:
138159
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
@@ -142,7 +163,10 @@ def test_obeys_circuit_breaker(self) -> None:
142163
"sentry.grouping.ingest.seer.CircuitBreaker.should_allow_request",
143164
return_value=request_allowed,
144165
):
145-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
166+
assert (
167+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
168+
is expected_result
169+
)
146170

147171
@with_feature({"organizations:grouping-hybrid-fingerprint-seer-usage": True})
148172
def test_obeys_custom_fingerprint_check_flag_on(self) -> None:
@@ -180,9 +204,11 @@ def test_obeys_custom_fingerprint_check_flag_on(self) -> None:
180204
(custom_fingerprint_event, False),
181205
(built_in_fingerprint_event, False),
182206
]:
183-
207+
grouphash = GroupHash(
208+
project_id=self.project.id, hash=hash_from_values(event.data["fingerprint"])
209+
)
184210
assert (
185-
should_call_seer_for_grouping(event, event.get_grouping_variants())
211+
should_call_seer_for_grouping(event, event.get_grouping_variants(), grouphash)
186212
is expected_result
187213
), f'Case with fingerprint {event.data["fingerprint"]} failed.'
188214

@@ -229,9 +255,11 @@ def test_obeys_customized_fingerprint_check_flag_off(self) -> None:
229255
(custom_fingerprint_event, False),
230256
(built_in_fingerprint_event, False),
231257
]:
232-
258+
grouphash = GroupHash(
259+
project_id=self.project.id, hash=hash_from_values(event.data["fingerprint"])
260+
)
233261
assert (
234-
should_call_seer_for_grouping(event, event.get_grouping_variants())
262+
should_call_seer_for_grouping(event, event.get_grouping_variants(), grouphash)
235263
is expected_result
236264
), f'Case with fingerprint {event.data["fingerprint"]} failed.'
237265

@@ -243,7 +271,10 @@ def test_obeys_excessive_frame_check(self) -> None:
243271
"sentry.grouping.ingest.seer._has_too_many_contributing_frames",
244272
return_value=frame_check_result,
245273
):
246-
assert should_call_seer_for_grouping(self.event, self.variants) is expected_result
274+
assert (
275+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash)
276+
is expected_result
277+
)
247278

248279
@patch("sentry.grouping.ingest.seer.record_did_call_seer_metric")
249280
def test_obeys_empty_stacktrace_string_check(
@@ -261,16 +292,24 @@ def test_obeys_empty_stacktrace_string_check(
261292
},
262293
)
263294
empty_frame_variants = empty_frame_event.get_grouping_variants()
295+
empty_frame_grouphash = GroupHash(project_id=self.project.id, hash="415908")
264296
empty_frame_stacktrace_string = get_stacktrace_string(
265297
get_grouping_info_from_variants(empty_frame_variants)
266298
)
267299

268300
assert self.stacktrace_string != ""
269-
assert should_call_seer_for_grouping(self.event, self.variants) is True
301+
assert (
302+
should_call_seer_for_grouping(self.event, self.variants, self.event_grouphash) is True
303+
)
270304
mock_record_did_call_seer.assert_not_called()
271305

272306
assert empty_frame_stacktrace_string == ""
273-
assert should_call_seer_for_grouping(empty_frame_event, empty_frame_variants) is False
307+
assert (
308+
should_call_seer_for_grouping(
309+
empty_frame_event, empty_frame_variants, empty_frame_grouphash
310+
)
311+
is False
312+
)
274313
mock_record_did_call_seer.assert_any_call(
275314
empty_frame_event, call_made=False, blocker="empty-stacktrace-string"
276315
)

0 commit comments

Comments
 (0)