Skip to content

Commit 91ef3f0

Browse files
authored
ref(sort): Replace betterPriority with priority (#52915)
Now that the betterPriority sort is out and has replaced the old priority, just rename everything to priority for simplicity. Step 1: FE PR: #52910 Step 2: Migration: #52909 Step 3: This PR!
1 parent ecc36c6 commit 91ef3f0

File tree

5 files changed

+44
-52
lines changed

5 files changed

+44
-52
lines changed

src/sentry/constants.py

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def get_all_languages() -> List[str]:
4646
"date": _("Last Seen"),
4747
"new": _("First Seen"),
4848
"freq": _("Frequency"),
49-
"better_priority": _("Better Priority"),
5049
}
5150

5251
SEARCH_SORT_OPTIONS = {

src/sentry/models/savedsearch.py

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class SortOptions:
1818
FREQ = "freq"
1919
USER = "user"
2020
INBOX = "inbox"
21-
BETTER_PRIORITY = "betterPriority"
2221

2322
@classmethod
2423
def as_choices(cls):
@@ -29,7 +28,6 @@ def as_choices(cls):
2928
(cls.FREQ, _("Events")),
3029
(cls.USER, _("Users")),
3130
(cls.INBOX, _("Date Added")),
32-
(cls.BETTER_PRIORITY, _("Better Priority")),
3331
)
3432

3533

src/sentry/search/snuba/executors.py

+16-21
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class PrioritySortWeights(TypedDict):
7676

7777

7878
@dataclass
79-
class BetterPriorityParams:
79+
class PriorityParams:
8080
# (event or issue age_hours) / (event or issue halflife hours)
8181
# any event or issue age that is greater than max_pow times the half-life hours will get clipped
8282
max_pow: int
@@ -238,7 +238,7 @@ def _prepare_aggregations(
238238
end: datetime,
239239
having: Sequence[Sequence[Any]],
240240
aggregate_kwargs: Optional[PrioritySortWeights] = None,
241-
replace_better_priority_aggregation: Optional[bool] = False,
241+
replace_priority_aggregation: Optional[bool] = False,
242242
) -> list[Any]:
243243
extra_aggregations = self.dependency_aggregations.get(sort_field, [])
244244
required_aggregations = set([sort_field, "total"] + extra_aggregations)
@@ -249,8 +249,8 @@ def _prepare_aggregations(
249249
aggregations = []
250250
for alias in required_aggregations:
251251
aggregation = self.aggregation_defs[alias]
252-
if replace_better_priority_aggregation and alias in ["priority", "better_priority"]:
253-
aggregation = self.aggregation_defs["better_priority_issue_platform"]
252+
if replace_priority_aggregation and alias == "priority":
253+
aggregation = self.aggregation_defs["priority_issue_platform"]
254254
if callable(aggregation):
255255
if aggregate_kwargs:
256256
aggregation = aggregation(start, end, aggregate_kwargs.get(alias, {}))
@@ -302,10 +302,7 @@ def _prepare_params_for_category(
302302
else:
303303
conditions.append(converted_filter)
304304

305-
if (
306-
sort_field in ["priority", "better_priority"]
307-
and group_category is not GroupCategory.ERROR.value
308-
):
305+
if sort_field == "priority" and group_category is not GroupCategory.ERROR.value:
309306
aggregations = self._prepare_aggregations(
310307
sort_field, start, end, having, aggregate_kwargs, True
311308
)
@@ -503,13 +500,13 @@ def has_sort_strategy(self, sort_by: str) -> bool:
503500
return sort_by in self.sort_strategies.keys()
504501

505502

506-
def better_priority_aggregation(
503+
def priority_aggregation(
507504
start: datetime,
508505
end: datetime,
509506
aggregate_kwargs: PrioritySortWeights,
510507
) -> Sequence[str]:
511-
return better_priority_aggregation_impl(
512-
BetterPriorityParams(
508+
return priority_aggregation_impl(
509+
PriorityParams(
513510
max_pow=16,
514511
min_score=0.01,
515512
event_age_weight=1,
@@ -529,13 +526,13 @@ def better_priority_aggregation(
529526
)
530527

531528

532-
def better_priority_issue_platform_aggregation(
529+
def priority_issue_platform_aggregation(
533530
start: datetime,
534531
end: datetime,
535532
aggregate_kwargs: PrioritySortWeights,
536533
) -> Sequence[str]:
537-
return better_priority_aggregation_impl(
538-
BetterPriorityParams(
534+
return priority_aggregation_impl(
535+
PriorityParams(
539536
max_pow=16,
540537
min_score=0.01,
541538
event_age_weight=1,
@@ -555,8 +552,8 @@ def better_priority_issue_platform_aggregation(
555552
)
556553

557554

558-
def better_priority_aggregation_impl(
559-
params: BetterPriorityParams,
555+
def priority_aggregation_impl(
556+
params: PriorityParams,
560557
timestamp_column: str,
561558
use_stacktrace: bool,
562559
start: datetime,
@@ -695,24 +692,22 @@ class PostgresSnubaQueryExecutor(AbstractQueryExecutor):
695692
"date": "last_seen",
696693
"freq": "times_seen",
697694
"new": "first_seen",
698-
"priority": "better_priority",
695+
"priority": "priority",
699696
"user": "user_count",
700697
# We don't need a corresponding snuba field here, since this sort only happens
701698
# in Postgres
702699
"inbox": "",
703-
"betterPriority": "better_priority",
704700
}
705701

706702
aggregation_defs = {
707703
"times_seen": ["count()", ""],
708704
"first_seen": ["multiply(toUInt64(min(timestamp)), 1000)", ""],
709705
"last_seen": ["multiply(toUInt64(max(timestamp)), 1000)", ""],
710-
"priority": better_priority_aggregation,
706+
"priority": priority_aggregation,
711707
# Only makes sense with WITH TOTALS, returns 1 for an individual group.
712708
"total": ["uniq", ISSUE_FIELD_NAME],
713709
"user_count": ["uniq", "tags[sentry:user]"],
714-
"better_priority": better_priority_aggregation,
715-
"better_priority_issue_platform": better_priority_issue_platform_aggregation,
710+
"priority_issue_platform": priority_issue_platform_aggregation,
716711
}
717712

718713
@property

tests/snuba/api/endpoints/test_organization_group_index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_query_for_archived(self):
114114
assert len(response.data) == 1
115115
assert response.data[0]["id"] == str(group.id)
116116

117-
def test_sort_by_better_priority(self):
117+
def test_sort_by_priority(self):
118118
group = self.store_event(
119119
data={
120120
"timestamp": iso_format(before_now(seconds=10)),
@@ -164,7 +164,7 @@ def test_sort_by_better_priority(self):
164164
}
165165

166166
response = self.get_success_response(
167-
sort="betterPriority",
167+
sort="priority",
168168
query="is:unresolved",
169169
limit=25,
170170
start=iso_format(before_now(days=1)),

tests/snuba/search/test_backend.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def make_query(
7979
if limit is not None:
8080
kwargs["limit"] = limit
8181
if aggregate_kwargs:
82-
kwargs["aggregate_kwargs"] = {"better_priority": {**aggregate_kwargs}}
82+
kwargs["aggregate_kwargs"] = {"priority": {**aggregate_kwargs}}
8383

8484
return self.backend.query(
8585
projects,
@@ -364,7 +364,7 @@ def test_sort(self):
364364
results = self.make_query(sort_by="user")
365365
assert list(results) == [self.group1, self.group2]
366366

367-
def test_better_priority_sort(self):
367+
def test_priority_sort(self):
368368
weights: PrioritySortWeights = {
369369
"log_level": 5,
370370
"has_stacktrace": 5,
@@ -375,7 +375,7 @@ def test_better_priority_sort(self):
375375
"norm": False,
376376
}
377377
results = self.make_query(
378-
sort_by="betterPriority",
378+
sort_by="priority",
379379
aggregate_kwargs=weights,
380380
)
381381
assert list(results) == [self.group2, self.group1]
@@ -2597,12 +2597,12 @@ def test_error_main_thread_no_results(self):
25972597
assert len(results) == 0
25982598

25992599

2600-
class EventsBetterPriorityTest(SharedSnubaTest, OccurrenceTestMixin):
2600+
class EventsPriorityTest(SharedSnubaTest, OccurrenceTestMixin):
26012601
@property
26022602
def backend(self):
26032603
return EventsDatasetSnubaSearchBackend()
26042604

2605-
def test_better_priority_sort_old_and_new_events(self):
2605+
def test_priority_sort_old_and_new_events(self):
26062606
"""Test that an issue with only one old event is ranked lower than an issue with only one new event"""
26072607
new_project = self.create_project(organization=self.project.organization)
26082608
base_datetime = (datetime.utcnow() - timedelta(days=3)).replace(tzinfo=pytz.utc)
@@ -2644,15 +2644,15 @@ def test_better_priority_sort_old_and_new_events(self):
26442644
"norm": False,
26452645
}
26462646
results = self.make_query(
2647-
sort_by="betterPriority",
2647+
sort_by="priority",
26482648
projects=[new_project],
26492649
aggregate_kwargs=weights,
26502650
)
26512651
recent_group = Group.objects.get(id=recent_event.group.id)
26522652
old_group = Group.objects.get(id=old_event.group.id)
26532653
assert list(results) == [recent_group, old_group]
26542654

2655-
def test_better_priority_sort_v2(self):
2655+
def test_priority_sort_v2(self):
26562656
"""Test that the v2 formula works."""
26572657
new_project = self.create_project(organization=self.project.organization)
26582658
base_datetime = (datetime.utcnow() - timedelta(days=3)).replace(tzinfo=pytz.utc)
@@ -2694,15 +2694,15 @@ def test_better_priority_sort_v2(self):
26942694
"norm": False,
26952695
}
26962696
results = self.make_query(
2697-
sort_by="betterPriority",
2697+
sort_by="priority",
26982698
projects=[new_project],
26992699
aggregate_kwargs=weights,
27002700
)
27012701
recent_group = Group.objects.get(id=recent_event.group.id)
27022702
old_group = Group.objects.get(id=old_event.group.id)
27032703
assert list(results) == [recent_group, old_group]
27042704

2705-
def test_better_priority_log_level_results(self):
2705+
def test_priority_log_level_results(self):
27062706
"""Test that the scoring results change when we pass in different log level weights"""
27072707
base_datetime = (datetime.utcnow() - timedelta(hours=1)).replace(tzinfo=pytz.utc)
27082708
event1 = self.store_event(
@@ -2733,7 +2733,7 @@ def test_better_priority_log_level_results(self):
27332733
group2 = Group.objects.get(id=event2.group.id)
27342734

27352735
agg_kwargs = {
2736-
"better_priority": {
2736+
"priority": {
27372737
"log_level": 0,
27382738
"has_stacktrace": 0,
27392739
"relative_volume": 1,
@@ -2749,7 +2749,7 @@ def test_better_priority_log_level_results(self):
27492749
end=None,
27502750
project_ids=[self.project.id],
27512751
environment_ids=[],
2752-
sort_field="better_priority",
2752+
sort_field="priority",
27532753
organization=self.organization,
27542754
group_ids=[group1.id, group2.id],
27552755
limit=150,
@@ -2760,14 +2760,14 @@ def test_better_priority_log_level_results(self):
27602760
# initially group 2's score is higher since it has a more recent event
27612761
assert group2_score_before > group1_score_before
27622762

2763-
agg_kwargs["better_priority"].update({"log_level": 5})
2763+
agg_kwargs["priority"].update({"log_level": 5})
27642764

27652765
results2 = query_executor.snuba_search(
27662766
start=None,
27672767
end=None,
27682768
project_ids=[self.project.id],
27692769
environment_ids=[],
2770-
sort_field="better_priority",
2770+
sort_field="priority",
27712771
organization=self.organization,
27722772
group_ids=[group1.id, group2.id],
27732773
limit=150,
@@ -2778,11 +2778,11 @@ def test_better_priority_log_level_results(self):
27782778
# ensure fatal has a higher score than error
27792779
assert group1_score_after > group2_score_after
27802780

2781-
def test_better_priority_has_stacktrace_results(self):
2781+
def test_priority_has_stacktrace_results(self):
27822782
"""Test that the scoring results change when we pass in different has_stacktrace weights"""
27832783
base_datetime = (datetime.utcnow() - timedelta(hours=1)).replace(tzinfo=pytz.utc)
27842784
agg_kwargs = {
2785-
"better_priority": {
2785+
"priority": {
27862786
"log_level": 0,
27872787
"has_stacktrace": 0,
27882788
"relative_volume": 1,
@@ -2833,7 +2833,7 @@ def test_better_priority_has_stacktrace_results(self):
28332833
end=None,
28342834
project_ids=[self.project.id],
28352835
environment_ids=[],
2836-
sort_field="better_priority",
2836+
sort_field="priority",
28372837
organization=self.organization,
28382838
group_ids=[group1.id, group2.id],
28392839
limit=150,
@@ -2843,13 +2843,13 @@ def test_better_priority_has_stacktrace_results(self):
28432843
group2_score = results[1][1]
28442844
assert group1_score == group2_score
28452845

2846-
agg_kwargs["better_priority"].update({"has_stacktrace": 3})
2846+
agg_kwargs["priority"].update({"has_stacktrace": 3})
28472847
results = query_executor.snuba_search(
28482848
start=None,
28492849
end=None,
28502850
project_ids=[self.project.id],
28512851
environment_ids=[],
2852-
sort_field="better_priority",
2852+
sort_field="priority",
28532853
organization=self.organization,
28542854
group_ids=[group1.id, group2.id],
28552855
limit=150,
@@ -2860,7 +2860,7 @@ def test_better_priority_has_stacktrace_results(self):
28602860
# check that a group with an event with a stacktrace has a higher weight than one without
28612861
assert group1_score < group2_score
28622862

2863-
def test_better_priority_event_halflife_results(self):
2863+
def test_priority_event_halflife_results(self):
28642864
"""Test that the scoring results change when we pass in different event halflife weights"""
28652865
base_datetime = (datetime.utcnow() - timedelta(hours=1)).replace(tzinfo=pytz.utc)
28662866
event1 = self.store_event(
@@ -2891,7 +2891,7 @@ def test_better_priority_event_halflife_results(self):
28912891
group2 = Group.objects.get(id=event2.group.id)
28922892

28932893
agg_kwargs = {
2894-
"better_priority": {
2894+
"priority": {
28952895
"log_level": 0,
28962896
"has_stacktrace": 0,
28972897
"relative_volume": 1,
@@ -2907,7 +2907,7 @@ def test_better_priority_event_halflife_results(self):
29072907
end=None,
29082908
project_ids=[self.project.id],
29092909
environment_ids=[],
2910-
sort_field="better_priority",
2910+
sort_field="priority",
29112911
organization=self.organization,
29122912
group_ids=[group1.id, group2.id],
29132913
limit=150,
@@ -2918,13 +2918,13 @@ def test_better_priority_event_halflife_results(self):
29182918
# initially group 2's score is higher since it has a more recent event
29192919
assert group2_score_before > group1_score_before
29202920

2921-
agg_kwargs["better_priority"].update({"event_halflife_hours": 2})
2921+
agg_kwargs["priority"].update({"event_halflife_hours": 2})
29222922
results = query_executor.snuba_search(
29232923
start=None,
29242924
end=None,
29252925
project_ids=[self.project.id],
29262926
environment_ids=[],
2927-
sort_field="better_priority",
2927+
sort_field="priority",
29282928
organization=self.organization,
29292929
group_ids=[group1.id, group2.id],
29302930
limit=150,
@@ -2934,7 +2934,7 @@ def test_better_priority_event_halflife_results(self):
29342934
group2_score_after = results[1][1]
29352935
assert group1_score_after < group2_score_after
29362936

2937-
def test_better_priority_mixed_group_types(self):
2937+
def test_priority_mixed_group_types(self):
29382938
base_datetime = (datetime.utcnow() - timedelta(hours=1)).replace(tzinfo=pytz.utc)
29392939

29402940
error_event = self.store_event(
@@ -2967,7 +2967,7 @@ def test_better_priority_mixed_group_types(self):
29672967
profile_group_1 = group_info.group
29682968

29692969
agg_kwargs = {
2970-
"better_priority": {
2970+
"priority": {
29712971
"log_level": 0,
29722972
"has_stacktrace": 0,
29732973
"relative_volume": 1,
@@ -2989,7 +2989,7 @@ def test_better_priority_mixed_group_types(self):
29892989
end=None,
29902990
project_ids=[self.project.id],
29912991
environment_ids=[],
2992-
sort_field="better_priority",
2992+
sort_field="priority",
29932993
organization=self.organization,
29942994
group_ids=[profile_group_1.id, error_group.id],
29952995
limit=150,

0 commit comments

Comments
 (0)