4
4
from typing import Any
5
5
from unittest .mock import ANY , MagicMock , patch
6
6
7
- from sentry .conf .server import DEFAULT_GROUPING_CONFIG , LEGACY_GROUPING_CONFIG
7
+ from sentry .conf .server import DEFAULT_GROUPING_CONFIG
8
8
from sentry .eventstore .models import Event
9
9
from sentry .grouping .ingest .grouphash_metadata import create_or_update_grouphash_metadata_if_needed
10
10
from sentry .models .grouphash import GroupHash
13
13
from sentry .testutils .helpers .eventprocessing import save_new_event
14
14
from sentry .testutils .helpers .options import override_options
15
15
from sentry .testutils .skips import requires_snuba
16
+ from tests .sentry .grouping import NO_MSG_PARAM_CONFIG
16
17
17
18
pytestmark = [requires_snuba ]
18
19
@@ -100,22 +101,23 @@ def test_stores_expected_properties(self):
100
101
def test_stores_expected_properties_for_secondary_hashes (self ):
101
102
project = self .project
102
103
103
- project .update_option ("sentry:grouping_config" , LEGACY_GROUPING_CONFIG )
104
+ project .update_option ("sentry:grouping_config" , NO_MSG_PARAM_CONFIG )
104
105
105
- # Ensure the legacy grouphash doesn't have metadata added when it's created as the primary
106
- # grouphash, so we can test how the metadata code handles it when it's a seconary grouphash
106
+ # Ensure the older grouphash doesn't have metadata added when it's created as the primary
107
+ # grouphash, so we can test how the metadata code handles it when that same grouphash comes
108
+ # up as a secondary grouphash
107
109
with override_options ({"grouping.grouphash_metadata.ingestion_writes_enabled" : False }):
108
110
event1 = save_new_event (
109
111
{"message" : "Dogs are great! 1231" , "platform" : "python" }, self .project
110
112
)
111
- legacy_config_grouphash = GroupHash .objects .filter (
113
+ older_config_grouphash = GroupHash .objects .filter (
112
114
project = self .project , hash = event1 .get_primary_hash ()
113
115
).first ()
114
- assert legacy_config_grouphash and not legacy_config_grouphash .metadata
116
+ assert older_config_grouphash and not older_config_grouphash .metadata
115
117
116
118
# Update the project's grouping config, and set it in transition mode
117
119
project .update_option ("sentry:grouping_config" , DEFAULT_GROUPING_CONFIG )
118
- project .update_option ("sentry:secondary_grouping_config" , LEGACY_GROUPING_CONFIG )
120
+ project .update_option ("sentry:secondary_grouping_config" , NO_MSG_PARAM_CONFIG )
119
121
project .update_option ("sentry:secondary_grouping_expiry" , time () + 3600 )
120
122
121
123
event2 = save_new_event (
@@ -124,40 +126,41 @@ def test_stores_expected_properties_for_secondary_hashes(self):
124
126
default_config_grouphash = GroupHash .objects .filter (
125
127
project = self .project , hash = event2 .get_primary_hash ()
126
128
).first ()
127
- # The events should end up in the same group, but their hashes should be different, because
128
- # the legacy config won't parameterize the number in the message, while the new one will
129
+ # The events should end up in the same group, but their hashes should be different (because
130
+ # NO_MSG_PARAM_CONFIG won't parameterize the number in the message, while the default config
131
+ # will)
129
132
assert event1 .group_id == event2 .group_id
130
133
assert (
131
134
default_config_grouphash
132
- and default_config_grouphash .hash != legacy_config_grouphash .hash
135
+ and default_config_grouphash .hash != older_config_grouphash .hash
133
136
)
134
137
135
138
# This time metadata was added
136
- legacy_config_grouphash .refresh_from_db ()
137
- assert legacy_config_grouphash .metadata
139
+ older_config_grouphash .refresh_from_db ()
140
+ assert older_config_grouphash .metadata
138
141
self .assert_metadata_values (
139
- legacy_config_grouphash ,
142
+ older_config_grouphash ,
140
143
{
141
144
"schema_version" : GROUPHASH_METADATA_SCHEMA_VERSION ,
142
- "latest_grouping_config" : LEGACY_GROUPING_CONFIG ,
145
+ "latest_grouping_config" : NO_MSG_PARAM_CONFIG ,
143
146
"platform" : "python" ,
144
147
},
145
148
)
146
149
# No hash basis or hashing metadata because secondary grouphashes don't come with variants
147
- assert legacy_config_grouphash .metadata .hash_basis is None
148
- assert legacy_config_grouphash .metadata .hashing_metadata is None
150
+ assert older_config_grouphash .metadata .hash_basis is None
151
+ assert older_config_grouphash .metadata .hashing_metadata is None
149
152
150
153
@override_options ({"grouping.grouphash_metadata.backfill_sample_rate" : 1.0 })
151
154
@patch ("sentry.grouping.ingest.grouphash_metadata.metrics.incr" )
152
155
def test_does_grouping_config_update (self , mock_metrics_incr : MagicMock ):
153
- self .project .update_option ("sentry:grouping_config" , LEGACY_GROUPING_CONFIG )
156
+ self .project .update_option ("sentry:grouping_config" , NO_MSG_PARAM_CONFIG )
154
157
155
158
event1 = save_new_event ({"message" : "Dogs are great!" }, self .project )
156
159
grouphash1 = GroupHash .objects .filter (
157
160
project = self .project , hash = event1 .get_primary_hash ()
158
161
).first ()
159
162
160
- self .assert_metadata_values (grouphash1 , {"latest_grouping_config" : LEGACY_GROUPING_CONFIG })
163
+ self .assert_metadata_values (grouphash1 , {"latest_grouping_config" : NO_MSG_PARAM_CONFIG })
161
164
162
165
# Update the grouping config. Since there's nothing to parameterize in the message, the
163
166
# hash should be the same under both configs, meaning we'll hit the same grouphash.
@@ -177,21 +180,21 @@ def test_does_grouping_config_update(self, mock_metrics_incr: MagicMock):
177
180
"grouping.grouphash_metadata.db_hit" ,
178
181
tags = {
179
182
"reason" : "old_grouping_config" ,
180
- "current_config" : LEGACY_GROUPING_CONFIG ,
183
+ "current_config" : NO_MSG_PARAM_CONFIG ,
181
184
"new_config" : DEFAULT_GROUPING_CONFIG ,
182
185
},
183
186
)
184
187
185
188
@override_options ({"grouping.grouphash_metadata.backfill_sample_rate" : 0.415 })
186
189
def test_updates_obey_sample_rate (self ):
187
- self .project .update_option ("sentry:grouping_config" , LEGACY_GROUPING_CONFIG )
190
+ self .project .update_option ("sentry:grouping_config" , NO_MSG_PARAM_CONFIG )
188
191
189
192
event1 = save_new_event ({"message" : "Dogs are great!" }, self .project )
190
193
grouphash1 = GroupHash .objects .filter (
191
194
project = self .project , hash = event1 .get_primary_hash ()
192
195
).first ()
193
196
194
- self .assert_metadata_values (grouphash1 , {"latest_grouping_config" : LEGACY_GROUPING_CONFIG })
197
+ self .assert_metadata_values (grouphash1 , {"latest_grouping_config" : NO_MSG_PARAM_CONFIG })
195
198
196
199
# Update the grouping config. Since there's nothing to parameterize in the message, the
197
200
# hash should be the same under both configs, meaning we'll hit the same grouphash.
@@ -208,9 +211,7 @@ def test_updates_obey_sample_rate(self):
208
211
assert grouphash1 == grouphash2
209
212
210
213
# Grouping config wasn't updated
211
- self .assert_metadata_values (
212
- grouphash2 , {"latest_grouping_config" : LEGACY_GROUPING_CONFIG }
213
- )
214
+ self .assert_metadata_values (grouphash2 , {"latest_grouping_config" : NO_MSG_PARAM_CONFIG })
214
215
215
216
# Under the sample rate cutoff, so record should be updated
216
217
with patch ("sentry.grouping.ingest.grouphash_metadata.random.random" , return_value = 0.1231 ):
@@ -288,7 +289,7 @@ def test_does_schema_update(self, mock_metrics_incr: MagicMock):
288
289
@override_options ({"grouping.grouphash_metadata.backfill_sample_rate" : 1.0 })
289
290
@patch ("sentry.grouping.ingest.grouphash_metadata.metrics.incr" )
290
291
def test_does_both_updates (self , mock_metrics_incr : MagicMock ):
291
- self .project .update_option ("sentry:grouping_config" , LEGACY_GROUPING_CONFIG )
292
+ self .project .update_option ("sentry:grouping_config" , NO_MSG_PARAM_CONFIG )
292
293
293
294
with patch (
294
295
"sentry.grouping.ingest.grouphash_metadata.GROUPHASH_METADATA_SCHEMA_VERSION" , "11"
@@ -301,7 +302,7 @@ def test_does_both_updates(self, mock_metrics_incr: MagicMock):
301
302
self .assert_metadata_values (
302
303
grouphash1 ,
303
304
{
304
- "latest_grouping_config" : LEGACY_GROUPING_CONFIG ,
305
+ "latest_grouping_config" : NO_MSG_PARAM_CONFIG ,
305
306
"schema_version" : "11" ,
306
307
"hashing_metadata" : {
307
308
"message_source" : "message" ,
@@ -346,7 +347,7 @@ def test_does_both_updates(self, mock_metrics_incr: MagicMock):
346
347
"grouping.grouphash_metadata.db_hit" ,
347
348
tags = {
348
349
"reason" : "config_and_schema" ,
349
- "current_config" : LEGACY_GROUPING_CONFIG ,
350
+ "current_config" : NO_MSG_PARAM_CONFIG ,
350
351
"new_config" : DEFAULT_GROUPING_CONFIG ,
351
352
"current_version" : "11" ,
352
353
"new_version" : "12" ,
0 commit comments