Skip to content

Commit ace804c

Browse files
ref: referrer should always be present for snuba calls (#97002)
<!-- Describe your PR here. -->
1 parent 5386faa commit ace804c

File tree

14 files changed

+89
-50
lines changed

14 files changed

+89
-50
lines changed

src/sentry/search/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def query(
3838
date_from: datetime | None = None,
3939
date_to: datetime | None = None,
4040
max_hits: int | None = None,
41-
referrer: str | None = None,
4241
actor: Any | None = None,
4342
aggregate_kwargs: TrendsSortWeights | None = None,
43+
*,
44+
referrer: str,
4445
) -> CursorResult[Group]:
4546
raise NotImplementedError

src/sentry/search/events/builder/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ def get_snql_query(self) -> Request:
15901590

15911591
def run_query(
15921592
self,
1593-
referrer: str | None,
1593+
referrer: str,
15941594
use_cache: bool = False,
15951595
query_source: QuerySource | None = None,
15961596
) -> Any:

src/sentry/search/snuba/backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,10 @@ def query(
379379
date_from: datetime | None = None,
380380
date_to: datetime | None = None,
381381
max_hits: int | None = None,
382-
referrer: str | None = None,
383382
actor: Any | None = None,
384383
aggregate_kwargs: TrendsSortWeights | None = None,
384+
*,
385+
referrer: str,
385386
) -> CursorResult[Group]:
386387
search_filters = search_filters if search_filters is not None else []
387388
# ensure projects are from same org

src/sentry/search/snuba/executors.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ def query(
216216
date_from: datetime | None,
217217
date_to: datetime | None,
218218
max_hits: int | None = None,
219-
referrer: str | None = None,
220219
actor: Any | None = None,
221220
aggregate_kwargs: TrendsSortWeights | None = None,
221+
*,
222+
referrer: str,
222223
) -> CursorResult[Group]:
223224
"""This function runs your actual query and returns the results
224225
We usually return a paginator object, which contains the results and the number of hits"""
@@ -396,9 +397,10 @@ def snuba_search(
396397
offset: int = 0,
397398
get_sample: bool = False,
398399
search_filters: Sequence[SearchFilter] | None = None,
399-
referrer: str | None = None,
400400
actor: Any | None = None,
401401
aggregate_kwargs: TrendsSortWeights | None = None,
402+
*,
403+
referrer: str,
402404
) -> tuple[list[tuple[int, Any]], int]:
403405
"""Queries Snuba for events with associated Groups based on the input criteria.
404406
@@ -747,9 +749,10 @@ def query(
747749
date_from: datetime | None,
748750
date_to: datetime | None,
749751
max_hits: int | None = None,
750-
referrer: str | None = None,
751752
actor: Any | None = None,
752753
aggregate_kwargs: TrendsSortWeights | None = None,
754+
*,
755+
referrer: str,
753756
) -> CursorResult[Group]:
754757
now = timezone.now()
755758
end = None
@@ -903,6 +906,7 @@ def query(
903906
start,
904907
end,
905908
actor,
909+
referrer=referrer,
906910
)
907911
if count_hits and hits == 0:
908912
return self.empty_result
@@ -1046,6 +1050,8 @@ def calculate_hits(
10461050
start: datetime,
10471051
end: datetime,
10481052
actor: Any | None = None,
1053+
*,
1054+
referrer: str,
10491055
) -> int | None:
10501056
"""
10511057
This method should return an integer representing the number of hits (results) of your search.
@@ -1088,7 +1094,11 @@ def calculate_hits(
10881094
# +/-10% @ 95% confidence.
10891095

10901096
sample_size = options.get("snuba.search.hits-sample-size")
1091-
kwargs = dict(
1097+
kwargs = {}
1098+
if not too_many_candidates:
1099+
kwargs["group_ids"] = group_ids
1100+
1101+
snuba_groups, snuba_total = self.snuba_search(
10921102
start=start,
10931103
end=end,
10941104
project_ids=[p.id for p in projects],
@@ -1100,11 +1110,9 @@ def calculate_hits(
11001110
get_sample=True,
11011111
search_filters=search_filters,
11021112
actor=actor,
1113+
referrer=referrer,
1114+
**kwargs,
11031115
)
1104-
if not too_many_candidates:
1105-
kwargs["group_ids"] = group_ids
1106-
1107-
snuba_groups, snuba_total = self.snuba_search(**kwargs)
11081116
snuba_count = len(snuba_groups)
11091117
if snuba_count == 0:
11101118
# Maybe check for 0 hits and return EMPTY_RESULT in ::query? self.empty_result

src/sentry/snuba/discover.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def query(
165165
orderby: list[str] | None = None,
166166
offset: int | None = None,
167167
limit: int = 50,
168-
referrer: str | None = None,
169168
auto_fields: bool = False,
170169
auto_aggregations: bool = False,
171170
include_equation_fields: bool = False,
@@ -185,6 +184,8 @@ def query(
185184
fallback_to_transactions: bool = False,
186185
query_source: QuerySource | None = None,
187186
debug: bool = False,
187+
*,
188+
referrer: str,
188189
) -> EventsResponse:
189190
"""
190191
High-level API for doing arbitrary user queries against events.
@@ -268,7 +269,6 @@ def timeseries_query(
268269
query: str,
269270
snuba_params: SnubaParams,
270271
rollup: int,
271-
referrer: str | None = None,
272272
zerofill_results: bool = True,
273273
comparison_delta: timedelta | None = None,
274274
functions_acl: list[str] | None = None,
@@ -281,6 +281,8 @@ def timeseries_query(
281281
query_source: QuerySource | None = None,
282282
fallback_to_transactions: bool = False,
283283
transform_alias_to_input_format: bool = False,
284+
*,
285+
referrer: str,
284286
) -> SnubaTSResult:
285287
"""
286288
High-level API for doing arbitrary user timeseries queries against events.
@@ -447,7 +449,6 @@ def top_events_timeseries(
447449
limit: int,
448450
organization: Organization,
449451
equations: list[str] | None = None,
450-
referrer: str | None = None,
451452
top_events: EventsResponse | None = None,
452453
allow_empty: bool = True,
453454
zerofill_results: bool = True,
@@ -459,6 +460,8 @@ def top_events_timeseries(
459460
query_source: QuerySource | None = None,
460461
fallback_to_transactions: bool = False,
461462
transform_alias_to_input_format: bool = False,
463+
*,
464+
referrer: str,
462465
) -> dict[str, SnubaTSResult] | SnubaTSResult:
463466
"""
464467
High-level API for doing arbitrary user timeseries queries for a limited number of top events
@@ -805,7 +808,6 @@ def spans_histogram_query(
805808
min_value: float | None = None,
806809
max_value: float | None = None,
807810
data_filter: Literal["exclude_outliers"] | None = None,
808-
referrer: str | None = None,
809811
group_by: list[str] | None = None,
810812
order_by: list[str] | None = None,
811813
limit_by: list[str] | None = None,
@@ -815,6 +817,8 @@ def spans_histogram_query(
815817
on_demand_metrics_enabled: bool = False,
816818
on_demand_metrics_type: MetricSpecType | None = None,
817819
query_source: QuerySource | None = None,
820+
*,
821+
referrer: str,
818822
) -> EventsResponse | SnubaData:
819823
"""
820824
API for generating histograms for span exclusive time.
@@ -894,7 +898,6 @@ def histogram_query(
894898
min_value: float | None = None,
895899
max_value: float | None = None,
896900
data_filter: Literal["exclude_outliers"] | None = None,
897-
referrer: str | None = None,
898901
group_by: list[str] | None = None,
899902
order_by: list[str] | None = None,
900903
limit_by: list[str] | None = None,
@@ -905,6 +908,8 @@ def histogram_query(
905908
on_demand_metrics_enabled: bool = False,
906909
on_demand_metrics_type: MetricSpecType | None = None,
907910
query_source: QuerySource | None = None,
911+
*,
912+
referrer: str,
908913
):
909914
"""
910915
API for generating histograms for numeric columns.

src/sentry/snuba/errors.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def query(
4040
orderby: list[str] | None = None,
4141
offset: int | None = None,
4242
limit: int = 50,
43-
referrer: str | None = None,
4443
auto_fields: bool = False,
4544
auto_aggregations: bool = False,
4645
include_equation_fields: bool = False,
@@ -60,6 +59,8 @@ def query(
6059
fallback_to_transactions: bool = False,
6160
query_source: QuerySource | None = None,
6261
debug: bool = False,
62+
*,
63+
referrer: str,
6364
) -> EventsResponse:
6465
if not selected_columns:
6566
raise InvalidSearchQuery("No columns selected")
@@ -101,7 +102,6 @@ def timeseries_query(
101102
query: str,
102103
snuba_params: SnubaParams,
103104
rollup: int,
104-
referrer: str | None = None,
105105
zerofill_results: bool = True,
106106
comparison_delta: timedelta | None = None,
107107
functions_acl: list[str] | None = None,
@@ -113,6 +113,8 @@ def timeseries_query(
113113
query_source: QuerySource | None = None,
114114
fallback_to_transactions: bool = False,
115115
transform_alias_to_input_format: bool = False,
116+
*,
117+
referrer: str,
116118
):
117119

118120
with sentry_sdk.start_span(op="errors", name="timeseries.filter_transform"):
@@ -211,7 +213,6 @@ def top_events_timeseries(
211213
limit: int,
212214
organization: Organization,
213215
equations: list[str] | None = None,
214-
referrer: str | None = None,
215216
top_events: EventsResponse | None = None,
216217
allow_empty: bool = True,
217218
zerofill_results: bool = True,
@@ -223,6 +224,8 @@ def top_events_timeseries(
223224
query_source: QuerySource | None = None,
224225
fallback_to_transactions: bool = False,
225226
transform_alias_to_input_format: bool = False,
227+
*,
228+
referrer: str,
226229
) -> dict[str, SnubaTSResult] | SnubaTSResult:
227230
"""
228231
High-level API for doing arbitrary user timeseries queries for a limited number of top events

src/sentry/snuba/functions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def query(
2929
offset: int = 0,
3030
limit: int = 50,
3131
limitby: tuple[str, int] | None = None,
32-
referrer: str = "",
3332
auto_fields: bool = False,
3433
auto_aggregations: bool = False,
3534
use_aggregate_conditions: bool = False,
@@ -44,6 +43,8 @@ def query(
4443
fallback_to_transactions=False,
4544
query_source: QuerySource | None = None,
4645
debug: bool = False,
46+
*,
47+
referrer: str,
4748
) -> Any:
4849
if not selected_columns:
4950
raise InvalidSearchQuery("No columns selected")
@@ -82,7 +83,6 @@ def timeseries_query(
8283
query: str | None,
8384
snuba_params: SnubaParams,
8485
rollup: int,
85-
referrer: str = "",
8686
zerofill_results: bool = True,
8787
comparison_delta: timedelta | None = None,
8888
functions_acl: list[str] | None = None,
@@ -94,6 +94,8 @@ def timeseries_query(
9494
query_source: QuerySource | None = None,
9595
fallback_to_transactions: bool = False,
9696
transform_alias_to_input_format: bool = False,
97+
*,
98+
referrer: str,
9799
) -> Any:
98100

99101
builder = ProfileFunctionsTimeseriesQueryBuilder(
@@ -143,7 +145,6 @@ def top_events_timeseries(
143145
limit,
144146
organization,
145147
equations=None,
146-
referrer=None,
147148
top_events=None,
148149
allow_empty=True,
149150
zerofill_results=True,
@@ -155,6 +156,8 @@ def top_events_timeseries(
155156
query_source: QuerySource | None = None,
156157
fallback_to_transactions: bool = False,
157158
transform_alias_to_input_format: bool = False,
159+
*,
160+
referrer: str,
158161
):
159162
assert not include_other, "Other is not supported" # TODO: support other
160163

src/sentry/snuba/issue_platform.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def query(
2323
orderby=None,
2424
offset=None,
2525
limit=50,
26-
referrer=None,
2726
auto_fields=False,
2827
auto_aggregations=False,
2928
include_equation_fields=False,
@@ -41,6 +40,8 @@ def query(
4140
fallback_to_transactions=False,
4241
query_source: QuerySource | None = None,
4342
debug: bool = False,
43+
*,
44+
referrer: str,
4445
) -> EventsResponse:
4546
"""
4647
High-level API for doing arbitrary user queries against events.
@@ -112,7 +113,6 @@ def timeseries_query(
112113
query: str,
113114
snuba_params: SnubaParams,
114115
rollup: int,
115-
referrer: str | None = None,
116116
zerofill_results: bool = True,
117117
comparison_delta: timedelta | None = None,
118118
functions_acl: list[str] | None = None,
@@ -124,6 +124,8 @@ def timeseries_query(
124124
query_source: QuerySource | None = None,
125125
fallback_to_transactions: bool = False,
126126
transform_alias_to_input_format: bool = False,
127+
*,
128+
referrer: str,
127129
):
128130
"""
129131
High-level API for doing arbitrary user timeseries queries against events.

0 commit comments

Comments
 (0)