diff --git a/src/sentry/api/endpoints/organization_events.py b/src/sentry/api/endpoints/organization_events.py index 839be2e7899fa3..cf4fb43330d9f8 100644 --- a/src/sentry/api/endpoints/organization_events.py +++ b/src/sentry/api/endpoints/organization_events.py @@ -399,6 +399,7 @@ def _data_fn(scoped_dataset, offset, limit, query) -> dict[str, Any]: return scoped_dataset.query( selected_columns=self.get_field_list(organization, request), query=query, + params={}, snuba_params=snuba_params, equations=self.get_equation_list(organization, request), orderby=self.get_orderby(request), diff --git a/src/sentry/api/endpoints/organization_events_facets.py b/src/sentry/api/endpoints/organization_events_facets.py index 1704d7086a4853..6ed3ca45e7aa64 100644 --- a/src/sentry/api/endpoints/organization_events_facets.py +++ b/src/sentry/api/endpoints/organization_events_facets.py @@ -36,6 +36,7 @@ def data_fn(offset, limit): with handle_query_errors(): facets = discover.get_facets( query=request.GET.get("query"), + params={}, snuba_params=snuba_params, referrer="api.organization-events-facets.top-tags", per_page=limit, diff --git a/src/sentry/api/endpoints/organization_events_facets_performance.py b/src/sentry/api/endpoints/organization_events_facets_performance.py index 4ee603dd1d4fa6..bc49eb19ab1709 100644 --- a/src/sentry/api/endpoints/organization_events_facets_performance.py +++ b/src/sentry/api/endpoints/organization_events_facets_performance.py @@ -344,6 +344,7 @@ def query_top_tags( "array_join(tags.value) as tags_value", ], query=filter_query, + params={}, snuba_params=snuba_params, orderby=orderby, conditions=[ @@ -523,6 +524,7 @@ def query_facet_performance_key_histogram( results = discover.histogram_query( fields=[aggregate_column], user_query=filter_query, + params={}, snuba_params=snuba_params, num_buckets=num_buckets_per_key, precision=precision, diff --git a/src/sentry/api/endpoints/organization_events_has_measurements.py b/src/sentry/api/endpoints/organization_events_has_measurements.py index 96e18e20ece727..bd3c2a2f9956a0 100644 --- a/src/sentry/api/endpoints/organization_events_has_measurements.py +++ b/src/sentry/api/endpoints/organization_events_has_measurements.py @@ -111,6 +111,7 @@ def get(self, request: Request, organization) -> Response: results = discover.query( selected_columns=["id"], query=query, + params={}, snuba_params=snuba_params, limit=1, # Just want to check for existence of such an event referrer="api.events.measurements", diff --git a/src/sentry/api/endpoints/organization_events_histogram.py b/src/sentry/api/endpoints/organization_events_histogram.py index 86a244f0a2eedd..2a929d7d4217f4 100644 --- a/src/sentry/api/endpoints/organization_events_histogram.py +++ b/src/sentry/api/endpoints/organization_events_histogram.py @@ -81,6 +81,7 @@ def get(self, request: Request, organization) -> Response: results = dataset.histogram_query( fields=data["field"], user_query=data.get("query"), + params={}, snuba_params=snuba_params, num_buckets=data["numBuckets"], precision=data["precision"], diff --git a/src/sentry/api/endpoints/organization_events_meta.py b/src/sentry/api/endpoints/organization_events_meta.py index 1de0006a2488f0..e7d868637c6674 100644 --- a/src/sentry/api/endpoints/organization_events_meta.py +++ b/src/sentry/api/endpoints/organization_events_meta.py @@ -38,6 +38,7 @@ def get(self, request: Request, organization) -> Response: with handle_query_errors(): result = dataset.query( selected_columns=["count()"], + params={}, snuba_params=snuba_params, query=request.query_params.get("query"), referrer=Referrer.API_ORGANIZATION_EVENTS_META.value, @@ -152,6 +153,7 @@ def get(self, request: Request, organization) -> Response: f"p50({column}) as first_bound", f"p95({column}) as second_bound", ], + params={}, snuba_params=snuba_params, query=request.query_params.get("query"), referrer=Referrer.API_SPAN_SAMPLE_GET_BOUNDS.value, @@ -174,6 +176,7 @@ def get(self, request: Request, organization) -> Response: "profile_id", ], orderby=["-profile_id"], + params={}, snuba_params=snuba_params, query=request.query_params.get("query"), referrer=Referrer.API_SPAN_SAMPLE_GET_SPAN_IDS.value, @@ -197,6 +200,7 @@ def get(self, request: Request, organization) -> Response: result = spans_indexed.query( selected_columns=selected_columns, orderby=["timestamp"], + params={}, snuba_params=snuba_params, query=query, limit=9, diff --git a/src/sentry/api/endpoints/organization_events_root_cause_analysis.py b/src/sentry/api/endpoints/organization_events_root_cause_analysis.py index e5bd4f68ff464e..4f42779a36da1d 100644 --- a/src/sentry/api/endpoints/organization_events_root_cause_analysis.py +++ b/src/sentry/api/endpoints/organization_events_root_cause_analysis.py @@ -199,6 +199,7 @@ def get(self, request, organization): transaction_count_query = metrics_query( ["count()"], f'event.type:transaction transaction:"{transaction_name}"', + params={}, referrer=BASE_REFERRER, snuba_params=snuba_params, ) diff --git a/src/sentry/api/endpoints/organization_events_spans_histogram.py b/src/sentry/api/endpoints/organization_events_spans_histogram.py index af54c6ecbfc88d..0b321e9fef8f3e 100644 --- a/src/sentry/api/endpoints/organization_events_spans_histogram.py +++ b/src/sentry/api/endpoints/organization_events_spans_histogram.py @@ -64,6 +64,7 @@ def get(self, request: Request, organization) -> Response: results = discover.spans_histogram_query( span=data["span"], user_query=data.get("query"), + params={}, snuba_params=snuba_params, num_buckets=data["numBuckets"], precision=data["precision"], diff --git a/src/sentry/api/endpoints/organization_events_stats.py b/src/sentry/api/endpoints/organization_events_stats.py index fd2ba775d83c61..cc761acba80ee7 100644 --- a/src/sentry/api/endpoints/organization_events_stats.py +++ b/src/sentry/api/endpoints/organization_events_stats.py @@ -288,6 +288,7 @@ def _get_event_stats( selected_columns=self.get_field_list(organization, request), equations=self.get_equation_list(organization, request), user_query=query, + params={}, snuba_params=snuba_params, orderby=self.get_orderby(request), rollup=rollup, @@ -305,6 +306,7 @@ def _get_event_stats( return scoped_dataset.timeseries_query( selected_columns=query_columns, query=query, + params={}, snuba_params=snuba_params, rollup=rollup, referrer=referrer, diff --git a/src/sentry/api/endpoints/organization_events_trends.py b/src/sentry/api/endpoints/organization_events_trends.py index 63274f5cc45e07..1e1e55ab80af3a 100644 --- a/src/sentry/api/endpoints/organization_events_trends.py +++ b/src/sentry/api/endpoints/organization_events_trends.py @@ -544,11 +544,12 @@ def get_event_stats( query_columns, selected_columns, query, - snuba_params, + {}, orderby, rollup, min(5, len(events_results["data"])), organization, + snuba_params=snuba_params, top_events=events_results, referrer="api.trends.get-event-stats", zerofill_results=zerofill_results, diff --git a/src/sentry/api/endpoints/organization_events_trends_v2.py b/src/sentry/api/endpoints/organization_events_trends_v2.py index 31ab540df79d00..b1cb83b4947b5b 100644 --- a/src/sentry/api/endpoints/organization_events_trends_v2.py +++ b/src/sentry/api/endpoints/organization_events_trends_v2.py @@ -102,6 +102,7 @@ def get_top_events(user_query, snuba_params, event_limit, referrer): return metrics_query( top_event_columns, query=user_query, + params={}, snuba_params=snuba_params, orderby=["-count()"], limit=event_limit, @@ -148,6 +149,7 @@ def get_timeseries(top_events, _, rollup, zerofill_results): result = metrics_performance.bulk_timeseries_query( timeseries_columns, queries, + params={}, snuba_params=pruned_snuba_params, rollup=rollup, zerofill_results=zerofill_results, diff --git a/src/sentry/api/endpoints/organization_events_vitals.py b/src/sentry/api/endpoints/organization_events_vitals.py index 0dc36ffed38ee8..975846cebc3cbf 100644 --- a/src/sentry/api/endpoints/organization_events_vitals.py +++ b/src/sentry/api/endpoints/organization_events_vitals.py @@ -69,6 +69,7 @@ def get(self, request: Request, organization) -> Response: events_results = dataset.query( selected_columns=selected_columns, query=request.GET.get("query"), + params={}, snuba_params=snuba_params, # Results should only ever have 1 result limit=1, diff --git a/src/sentry/api/endpoints/organization_metrics_meta.py b/src/sentry/api/endpoints/organization_metrics_meta.py index 5668647c3b791c..2148ff3fdc2091 100644 --- a/src/sentry/api/endpoints/organization_metrics_meta.py +++ b/src/sentry/api/endpoints/organization_metrics_meta.py @@ -47,6 +47,7 @@ def get(self, request: Request, organization: Organization) -> Response: count_null, count_has_txn, ], + params={}, snuba_params=snuba_params, query=f"{count_null}:0 AND {count_has_txn}:>0", referrer="api.organization-events-metrics-compatibility.compatible", @@ -93,6 +94,7 @@ def get(self, request: Request, organization: Organization) -> Response: with handle_query_errors(): sum_metrics = metrics_performance.query( selected_columns=[COUNT_UNPARAM, COUNT_NULL, "count()"], + params={}, snuba_params=snuba_params, query="", referrer="api.organization-events-metrics-compatibility.sum_metrics", diff --git a/src/sentry/api/endpoints/organization_on_demand_metrics_estimation_stats.py b/src/sentry/api/endpoints/organization_on_demand_metrics_estimation_stats.py index fc9f1c3c4fe670..cb46e3ab3256c2 100644 --- a/src/sentry/api/endpoints/organization_on_demand_metrics_estimation_stats.py +++ b/src/sentry/api/endpoints/organization_on_demand_metrics_estimation_stats.py @@ -180,6 +180,7 @@ def get_discover_stats( return module.timeseries_query( selected_columns=query_columns, query=query, + params={}, snuba_params=snuba_params, rollup=rollup, referrer=Referrer.API_ORGANIZATION_METRICS_ESTIMATION_STATS.value, diff --git a/src/sentry/api/endpoints/organization_profiling_functions.py b/src/sentry/api/endpoints/organization_profiling_functions.py index 60504290081e42..71a53fbe73862d 100644 --- a/src/sentry/api/endpoints/organization_profiling_functions.py +++ b/src/sentry/api/endpoints/organization_profiling_functions.py @@ -103,6 +103,7 @@ def get(self, request: Request, organization: Organization) -> Response: "examples()", ], query=data.get("query"), + params={}, snuba_params=snuba_params, orderby=["-count()"], limit=TOP_FUNCTIONS_LIMIT, @@ -153,6 +154,7 @@ def get_event_stats( formatted_results = functions.format_top_events_timeseries_results( result, builder, + params={}, rollup=rollup, snuba_params=snuba_params, top_events={"data": chunk}, diff --git a/src/sentry/api/endpoints/organization_sdk_updates.py b/src/sentry/api/endpoints/organization_sdk_updates.py index c33e9aee5c0de1..b0a6acc07a7837 100644 --- a/src/sentry/api/endpoints/organization_sdk_updates.py +++ b/src/sentry/api/endpoints/organization_sdk_updates.py @@ -14,7 +14,6 @@ from sentry.api.bases.organization import OrganizationEndpoint from sentry.api.utils import handle_query_errors from sentry.sdk_updates import SdkIndexState, SdkSetupState, get_sdk_index, get_suggested_updates -from sentry.search.events.types import SnubaParams from sentry.snuba import discover from sentry.utils.numbers import format_grouped_length @@ -99,12 +98,12 @@ def get(self, request: Request, organization) -> Response: "last_seen()", ], orderby=["-project"], - snuba_params=SnubaParams( - start=timezone.now() - timedelta(days=1), - end=timezone.now(), - organization=organization, - projects=projects, - ), + params={ + "start": timezone.now() - timedelta(days=1), + "end": timezone.now(), + "organization_id": organization.id, + "project_id": [p.id for p in projects], + }, referrer="api.organization-sdk-updates", ) diff --git a/src/sentry/api/endpoints/organization_transaction_anomaly_detection.py b/src/sentry/api/endpoints/organization_transaction_anomaly_detection.py index 6eda19aa3f5227..e28a29ce3a9d7c 100644 --- a/src/sentry/api/endpoints/organization_transaction_anomaly_detection.py +++ b/src/sentry/api/endpoints/organization_transaction_anomaly_detection.py @@ -133,6 +133,7 @@ def get(self, request: Request, organization) -> Response: snuba_response = timeseries_query( selected_columns=["count()"], query=query, + params={}, snuba_params=snuba_params, rollup=time_params.granularity, referrer="transaction-anomaly-detection", diff --git a/src/sentry/api/serializers/models/project.py b/src/sentry/api/serializers/models/project.py index 468be3452be971..56ff409bf28c75 100644 --- a/src/sentry/api/serializers/models/project.py +++ b/src/sentry/api/serializers/models/project.py @@ -38,7 +38,6 @@ from sentry.models.userreport import UserReport from sentry.release_health.base import CurrentAndPreviousCrashFreeRate from sentry.roles import organization_roles -from sentry.search.events.types import SnubaParams from sentry.snuba import discover from sentry.users.models.user import User @@ -345,9 +344,9 @@ def measure_span(op_tag): project_ids = [o.id for o in item_list] if self.stats_period: - stats = self.get_stats(item_list, "!event.type:transaction") + stats = self.get_stats(project_ids, "!event.type:transaction") if self._expand("transaction_stats"): - transaction_stats = self.get_stats(item_list, "event.type:transaction") + transaction_stats = self.get_stats(project_ids, "event.type:transaction") if self._expand("session_stats"): session_stats = self.get_session_stats(project_ids) @@ -392,26 +391,26 @@ def measure_span(op_tag): serialized["options"] = options[project.id] return result - def get_stats(self, projects, query): + def get_stats(self, project_ids, query): # we need to compute stats at 1d (1h resolution), and 14d segments, interval = STATS_PERIOD_CHOICES[self.stats_period] now = timezone.now() - snuba_params = SnubaParams( - projects=projects, - start=now - ((segments - 1) * interval), - end=now, - ) + params = { + "project_id": project_ids, + "start": now - ((segments - 1) * interval), + "end": now, + } if self.environment_id: query = f"{query} environment:{self.environment_id}" # Generate a query result to skip the top_events.find query - top_events = {"data": [{"project_id": p.id} for p in projects]} + top_events = {"data": [{"project_id": p} for p in project_ids]} stats = self.dataset.top_events_timeseries( timeseries_columns=["count()"], selected_columns=["project_id"], user_query=query, - snuba_params=snuba_params, + params=params, orderby="project_id", rollup=int(interval.total_seconds()), limit=10000, @@ -420,13 +419,13 @@ def get_stats(self, projects, query): top_events=top_events, ) results = {} - for project in projects: + for project_id in project_ids: serialized = [] - str_id = str(project.id) + str_id = str(project_id) if str_id in stats: for item in stats[str_id].data["data"]: serialized.append((item["time"], item.get("count", 0))) - results[project.id] = serialized + results[project_id] = serialized return results def get_session_stats( diff --git a/src/sentry/data_export/endpoints/data_export.py b/src/sentry/data_export/endpoints/data_export.py index 01106118b2f5e2..d9b538213efbcb 100644 --- a/src/sentry/data_export/endpoints/data_export.py +++ b/src/sentry/data_export/endpoints/data_export.py @@ -102,7 +102,7 @@ def validate(self, data): # validate the query string by trying to parse it processor = DiscoverProcessor( discover_query=query_info, - organization=organization, + organization_id=organization.id, ) try: query_builder_cls = DiscoverQueryBuilder @@ -111,8 +111,7 @@ def validate(self, data): builder = query_builder_cls( SUPPORTED_DATASETS[dataset], - params={}, - snuba_params=processor.snuba_params, + processor.params, query=query_info["query"], selected_columns=fields.copy(), equations=equations, diff --git a/src/sentry/data_export/processors/discover.py b/src/sentry/data_export/processors/discover.py index 3bb3fab43ff4f7..f487ca4d746fbf 100644 --- a/src/sentry/data_export/processors/discover.py +++ b/src/sentry/data_export/processors/discover.py @@ -7,7 +7,7 @@ from sentry.models.group import Group from sentry.models.project import Project from sentry.search.events.fields import get_function_alias -from sentry.search.events.types import SnubaParams +from sentry.search.events.types import ParamsType from sentry.snuba import discover from sentry.snuba.utils import get_dataset @@ -21,20 +21,20 @@ class DiscoverProcessor: Processor for exports of discover data based on a provided query """ - def __init__(self, organization, discover_query): - self.projects = self.get_projects(organization.id, discover_query) - self.environments = self.get_environments(organization.id, discover_query) + def __init__(self, organization_id, discover_query): + self.projects = self.get_projects(organization_id, discover_query) + self.environments = self.get_environments(organization_id, discover_query) self.start, self.end = get_date_range_from_params(discover_query) - self.snuba_params = SnubaParams( - organization=organization, - projects=self.projects, - start=self.start, - end=self.end, - ) + self.params: ParamsType = { + "organization_id": organization_id, + "project_id": [project.id for project in self.projects], + "start": self.start, + "end": self.end, + } # make sure to only include environment if any are given # an empty list DOES NOT work if self.environments: - self.snuba_params.environments = self.environments + self.params["environment"] = self.environments equations = discover_query.get("equations", []) self.header_fields = [get_function_alias(x) for x in discover_query["field"]] + equations @@ -45,7 +45,7 @@ def __init__(self, organization, discover_query): fields=discover_query["field"], equations=equations, query=discover_query["query"], - snuba_params=self.snuba_params, + params=self.params, sort=discover_query.get("sort"), dataset=discover_query.get("dataset"), ) @@ -76,10 +76,10 @@ def get_environments(organization_id, query): if set(requested_environments) != set(environment_names): raise ExportError("Requested environment does not exist") - return environments + return environment_names @staticmethod - def get_data_fn(fields, equations, query, snuba_params, sort, dataset): + def get_data_fn(fields, equations, query, params, sort, dataset): dataset = get_dataset(dataset) if dataset is None: dataset = discover @@ -89,7 +89,7 @@ def data_fn(offset, limit): selected_columns=fields, equations=equations, query=query, - snuba_params=snuba_params, + params=params, offset=offset, orderby=sort, limit=limit, @@ -112,8 +112,8 @@ def handle_fields(self, result_list): i.id: i.qualified_short_id for i in Group.objects.filter( id__in=issue_ids, - project__in=self.snuba_params.project_ids, - project__organization_id=self.snuba_params.organization_id, + project__in=self.params["project_id"], + project__organization_id=self.params["organization_id"], ) } for result in new_result_list: diff --git a/src/sentry/data_export/tasks.py b/src/sentry/data_export/tasks.py index a0d9d301555f8e..fb74d620e2d58e 100644 --- a/src/sentry/data_export/tasks.py +++ b/src/sentry/data_export/tasks.py @@ -210,7 +210,7 @@ def get_processor(data_export, environment_id): elif data_export.query_type == ExportQueryType.DISCOVER: return DiscoverProcessor( discover_query=data_export.query_info, - organization=data_export.organization, + organization_id=data_export.organization_id, ) else: raise ExportError(f"No processor found for this query type: {data_export.query_type}") diff --git a/src/sentry/dynamic_sampling/tasks/custom_rule_notifications.py b/src/sentry/dynamic_sampling/tasks/custom_rule_notifications.py index 64ce77d6c17328..5d2dd1e0e38c6f 100644 --- a/src/sentry/dynamic_sampling/tasks/custom_rule_notifications.py +++ b/src/sentry/dynamic_sampling/tasks/custom_rule_notifications.py @@ -15,7 +15,7 @@ dynamic_sampling_task_with_context, ) from sentry.models.dynamicsampling import CustomDynamicSamplingRule -from sentry.search.events.types import SnubaParams +from sentry.search.events.types import ParamsType from sentry.silo.base import SiloMode from sentry.snuba import discover from sentry.tasks.base import instrumented_task @@ -88,16 +88,17 @@ def get_num_samples(rule: CustomDynamicSamplingRule) -> int: project_id.append(project.id) project_objects.append(project) - params = SnubaParams( - start=rule.start_date, - end=rule.end_date, - projects=project_objects, - organization=rule.organization, - ) + params: ParamsType = { + "start": rule.start_date, + "end": rule.end_date, + "project_id": project_id, + "project_objects": project_objects, + "organization_id": rule.organization.id, + } result = discover.query( selected_columns=["count()"], - snuba_params=params, + params=params, query=rule.query if rule.query is not None else "", referrer="dynamic_sampling.tasks.custom_rule_notifications", ) diff --git a/src/sentry/profiles/flamegraph.py b/src/sentry/profiles/flamegraph.py index c9d2b241733fd5..0f1ad2c5dc9daa 100644 --- a/src/sentry/profiles/flamegraph.py +++ b/src/sentry/profiles/flamegraph.py @@ -79,6 +79,7 @@ def get_profiles_with_function( result = functions.query( selected_columns=["timestamp", "unique_examples()"], query=" ".join(cond for cond in conditions if cond), + params={}, snuba_params=snuba_params, limit=100, orderby=["-timestamp"], diff --git a/src/sentry/replays/endpoints/organization_replay_events_meta.py b/src/sentry/replays/endpoints/organization_replay_events_meta.py index 0bbfa691b648ca..783e412f38f5cd 100644 --- a/src/sentry/replays/endpoints/organization_replay_events_meta.py +++ b/src/sentry/replays/endpoints/organization_replay_events_meta.py @@ -53,6 +53,7 @@ def data_fn(offset, limit): query_details = { "selected_columns": self.get_field_list(organization, request), "query": request.GET.get("query"), + "params": {}, "snuba_params": snuba_params, "equations": self.get_equation_list(organization, request), "orderby": self.get_orderby(request), diff --git a/src/sentry/replays/usecases/replay_counts.py b/src/sentry/replays/usecases/replay_counts.py index 97a0c3269b5c2c..667a7b82bb2f6e 100644 --- a/src/sentry/replays/usecases/replay_counts.py +++ b/src/sentry/replays/usecases/replay_counts.py @@ -106,6 +106,7 @@ def _get_replay_id_mappings( return {} results = search_query_func( + params={}, snuba_params=snuba_params, selected_columns=["group_uniq_array(100,replay.id)", select_column], query=query, diff --git a/src/sentry/seer/anomaly_detection/store_data.py b/src/sentry/seer/anomaly_detection/store_data.py index 4d8cfd61e1091a..7390b773c2208c 100644 --- a/src/sentry/seer/anomaly_detection/store_data.py +++ b/src/sentry/seer/anomaly_detection/store_data.py @@ -10,7 +10,6 @@ from sentry.incidents.models.alert_rule import AlertRule, AlertRuleStatus from sentry.models.project import Project from sentry.net.http import connection_from_url -from sentry.search.events.types import SnubaParams from sentry.seer.anomaly_detection.types import ( AlertInSeer, AnomalyDetectionConfig, @@ -157,12 +156,13 @@ def fetch_historical_data( historical_data = dataset.timeseries_query( selected_columns=[snuba_query.aggregate], query=snuba_query.query, - snuba_params=SnubaParams( - organization=alert_rule.organization, - projects=[project], - start=start, - end=end, - ), + params={ + "organization_id": alert_rule.organization.id, + "project_id": [project.id], + "granularity": granularity, + "start": start, + "end": end, + }, rollup=granularity, referrer=Referrer.ANOMALY_DETECTION_HISTORICAL_DATA_QUERY.value, zerofill_results=True, diff --git a/src/sentry/snuba/discover.py b/src/sentry/snuba/discover.py index 0e1ff0f42e8293..73b29a53ad1346 100644 --- a/src/sentry/snuba/discover.py +++ b/src/sentry/snuba/discover.py @@ -3,6 +3,7 @@ import random from collections import namedtuple from collections.abc import Callable, Mapping, Sequence +from copy import deepcopy from datetime import datetime, timedelta from typing import Any, Literal, cast @@ -29,6 +30,7 @@ from sentry.search.events.types import ( EventsResponse, HistogramParams, + ParamsType, QueryBuilderConfig, SnubaData, SnubaParams, @@ -180,7 +182,8 @@ def transform_tips(tips: dict[str, set[str]]) -> dict[str, str | None]: def query( selected_columns: list[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, orderby: list[str] | None = None, offset: int | None = None, @@ -217,7 +220,7 @@ def query( selected_columns - List of public aliases to fetch. query - Filter query string to create conditions from. - snuba_params - Filtering parameters with start, end, project_id, environment + params - Filtering parameters with start, end, project_id, environment equations - List of equations to calculate for the query orderby - The field to order results by. offset - The record offset to read. @@ -241,6 +244,9 @@ def query( if not selected_columns: raise InvalidSearchQuery("No columns selected") + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + assert dataset in [ Dataset.Discover, Dataset.Transactions, @@ -248,7 +254,7 @@ def query( builder = DiscoverQueryBuilder( dataset, - params={}, + params, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -283,13 +289,14 @@ def query( def _query_temp_do_not_use( selected_columns: list[str], query_string: str, - snuba_params: SnubaParams, + snuba_params: SnubaParams | None = None, referrer: str | None = None, ): """There's a single function call in getsentry that we need to support as we remove params""" return query( selected_columns=selected_columns, query=query_string, + params={}, snuba_params=snuba_params, referrer=referrer, ) @@ -298,8 +305,9 @@ def _query_temp_do_not_use( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, + snuba_params: SnubaParams | None = None, referrer: str | None = None, zerofill_results: bool = True, comparison_delta: timedelta | None = None, @@ -327,7 +335,7 @@ def timeseries_query( selected_columns - List of public aliases to fetch. query - Filter query string to create conditions from. - snuba_params - Filtering parameters with start, end, project_id, environment, + params - Filtering parameters with start, end, project_id, environment, rollup - The bucket width in seconds referrer - A referrer string to help locate the origin of this query. comparison_delta - A timedelta used to convert this into a comparison query. We make a second @@ -340,13 +348,22 @@ def timeseries_query( Dataset.Transactions, ], "A dataset is required to query discover" + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + + if ( + "start" not in params + or params["start"] is None + or "end" not in params + or params["end"] is None + ): + InvalidSearchQuery("Start and End is required to query timeseries") with sentry_sdk.start_span(op="discover.discover", description="timeseries.filter_transform"): equations, columns = categorize_columns(selected_columns) base_builder = TimeseriesQueryBuilder( dataset, - params={}, - interval=rollup, - snuba_params=snuba_params, + params, + rollup, query=query, selected_columns=columns, equations=equations, @@ -359,16 +376,13 @@ def timeseries_query( if comparison_delta: if len(base_builder.aggregates) != 1: raise InvalidSearchQuery("Only one column can be selected for comparison queries") - comp_query_params = snuba_params.copy() - assert comp_query_params.start is not None, "start is required" - assert comp_query_params.end is not None, "end is required" - comp_query_params.start -= comparison_delta - comp_query_params.end -= comparison_delta + comp_query_params = deepcopy(params) + comp_query_params["start"] -= comparison_delta + comp_query_params["end"] -= comparison_delta comparison_builder = TimeseriesQueryBuilder( dataset, - params={}, - interval=rollup, - snuba_params=comp_query_params, + comp_query_params, + rollup, query=query, selected_columns=columns, equations=equations, @@ -422,8 +436,8 @@ def timeseries_query( } }, }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -461,11 +475,12 @@ def top_events_timeseries( timeseries_columns: list[str], selected_columns: list[str], user_query: str, - snuba_params: SnubaParams, + params: ParamsType, orderby: list[str], rollup: int, limit: int, organization: Organization, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, referrer: str | None = None, top_events: EventsResponse | None = None, @@ -490,7 +505,7 @@ def top_events_timeseries( this is to determine what the top events are user_query - Filter query string to create conditions from. needs to be user_query to not conflict with the function query - snuba_params - Filtering parameters with start, end, project_id, environment, + params - Filtering parameters with start, end, project_id, environment, orderby - The fields to order results by. rollup - The bucket width in seconds limit - The number of events to get timeseries for @@ -505,12 +520,15 @@ def top_events_timeseries( Dataset.Transactions, ], "A dataset is required to query discover" + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if top_events is None: with sentry_sdk.start_span(op="discover.discover", description="top_events.fetch_events"): top_events = query( selected_columns, query=user_query, - snuba_params=snuba_params, + params=params, equations=equations, orderby=orderby, limit=limit, @@ -525,10 +543,9 @@ def top_events_timeseries( top_events_builder = TopEventsQueryBuilder( dataset, - params={}, - interval=rollup, - snuba_params=snuba_params, - top_events=top_events["data"], + params, + rollup, + top_events["data"], other=False, query=user_query, selected_columns=selected_columns, @@ -542,10 +559,9 @@ def top_events_timeseries( if len(top_events["data"]) == limit and include_other: other_events_builder = TopEventsQueryBuilder( dataset, - params={}, - interval=rollup, - top_events=top_events["data"], - snuba_params=snuba_params, + params, + rollup, + top_events["data"], other=True, query=user_query, selected_columns=selected_columns, @@ -568,13 +584,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - zerofill([], snuba_params.start_date, snuba_params.end_date, rollup, ["time"]) + zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) with sentry_sdk.start_span( @@ -587,7 +603,7 @@ def top_events_timeseries( if "issue" in selected_columns: issues = Group.objects.get_issues_mapping( {cast(int, event["issue.id"]) for event in top_events["data"]}, - snuba_params.project_ids, + params["project_id"], organization, ) translated_groupby = top_events_builder.translated_groupby @@ -616,20 +632,14 @@ def top_events_timeseries( top_events_results[key] = SnubaTSResult( { "data": ( - zerofill( - item["data"], - snuba_params.start_date, - snuba_params.end_date, - rollup, - ["time"], - ) + zerofill(item["data"], params["start"], params["end"], rollup, ["time"]) if zerofill_results else item["data"] ), "order": item["order"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -638,8 +648,9 @@ def top_events_timeseries( def get_facets( query: str, - snuba_params: SnubaParams, + params: ParamsType, referrer: str, + snuba_params: SnubaParams | None = None, per_page: int | None = TOP_KEYS_DEFAULT_LIMIT, cursor: int | None = 0, ) -> list[FacetResult]: @@ -657,13 +668,16 @@ def get_facets( cursor - The number of records to skip. """ - sample = len(snuba_params.project_ids) > 2 - fetch_projects = len(snuba_params.project_ids) > 1 + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + + sample = len(params["project_id"]) > 2 + fetch_projects = len(params["project_id"]) > 1 with sentry_sdk.start_span(op="discover.discover", description="facets.frequent_tags"): key_name_builder = DiscoverQueryBuilder( Dataset.Discover, - params={}, + params, snuba_params=snuba_params, query=query, selected_columns=["tags_key", "count()"], @@ -709,7 +723,7 @@ def get_facets( with sentry_sdk.start_span(op="discover.discover", description="facets.projects"): project_value_builder = DiscoverQueryBuilder( Dataset.Discover, - params={}, + params, snuba_params=snuba_params, query=query, selected_columns=["count()", "project_id"], @@ -748,7 +762,7 @@ def get_facets( tag = f"tags[{tag_name}]" tag_value_builder = DiscoverQueryBuilder( Dataset.Discover, - params={}, + params, snuba_params=snuba_params, query=query, selected_columns=["count()", tag], @@ -770,7 +784,7 @@ def get_facets( with sentry_sdk.start_span(op="discover.discover", description="facets.aggregate_tags"): aggregate_value_builder = DiscoverQueryBuilder( Dataset.Discover, - params={}, + params, snuba_params=snuba_params, query=(query if query is not None else "") + f" tags_key:[{','.join(aggregate_tags)}]", @@ -805,8 +819,9 @@ def get_facets( def spans_histogram_query( span: Span, user_query: str, - snuba_params: SnubaParams, + params: ParamsType, num_buckets: int, + snuba_params: SnubaParams | None = None, precision: int = 0, min_value: float | None = None, max_value: float | None = None, @@ -827,7 +842,7 @@ def spans_histogram_query( :param span: A span for which you want to generate histograms for. :param user_query: Filter query string to create conditions from. - :param snuba_params: Filtering parameters with start, end, project_id, environment + :param params: Filtering parameters with start, end, project_id, environment :param num_buckets: The number of buckets the histogram should contain. :param precision: The number of decimal places to preserve, default 0. :param min_value: The minimum value allowed to be in the histogram. @@ -847,8 +862,11 @@ def spans_histogram_query( # to be inclusive. So we adjust the specified max_value using the multiplier. max_value -= 0.1 / multiplier + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + min_value, max_value = find_span_histogram_min_max( - span, min_value, max_value, user_query, snuba_params, data_filter + span, min_value, max_value, user_query, params, data_filter ) key_column = None @@ -867,8 +885,7 @@ def spans_histogram_query( group_by, # Arguments for QueryBuilder Dataset.Discover, - params={}, - snuba_params=snuba_params, + params, query=user_query, selected_columns=[""], orderby=order_by, @@ -894,9 +911,10 @@ def spans_histogram_query( def histogram_query( fields: list[str], user_query: str, - snuba_params: SnubaParams, + params: ParamsType, num_buckets: int, precision: int = 0, + snuba_params: SnubaParams | None = None, min_value: float | None = None, max_value: float | None = None, data_filter: Literal["exclude_outliers"] | None = None, @@ -922,7 +940,7 @@ def histogram_query( :param fields: The list of fields for which you want to generate histograms for. :param user_query: Filter query string to create conditions from. - :param snuba_params: Filtering parameters with start, end, project_id, environment + :param params: Filtering parameters with start, end, project_id, environment :param num_buckets: The number of buckets the histogram should contain. :param precision: The number of decimal places to preserve, default 0. :param min_value: The minimum value allowed to be in the histogram. @@ -938,6 +956,9 @@ def histogram_query( :param normalize_results: Indicate whether to normalize the results by column into bins. """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + multiplier = int(10**precision) if max_value is not None: # We want the specified max_value to be exclusive, and the queried max_value @@ -949,7 +970,7 @@ def histogram_query( min_value, max_value, user_query, - snuba_params, + params, data_filter, ) @@ -991,8 +1012,7 @@ def histogram_query( group_by, # Arguments for QueryBuilder Dataset.Discover, - params={}, - snuba_params=snuba_params, + params, query=user_query, selected_columns=fields, orderby=order_by, @@ -1089,21 +1109,21 @@ def find_span_histogram_min_max( min_value: float | None, max_value: float | None, user_query: str, - snuba_params: SnubaParams, + params: ParamsType, data_filter: Literal["exclude_outliers"] | None = None, ) -> tuple[float | None, float | None]: """ Find the min/max value of the specified span. If either min/max is already specified, it will be used and not queried for. - :param span: A span for which you want to generate the histograms for. - :param min_value: The minimum value allowed to be in the histogram. + :param [Span] span: A span for which you want to generate the histograms for. + :param float min_value: The minimum value allowed to be in the histogram. If left unspecified, it is queried using `user_query` and `params`. - :param max_value: The maximum value allowed to be in the histogram. + :param float max_value: The maximum value allowed to be in the histogram. If left unspecified, it is queried using `user_query` and `params`. - :param user_query: Filter query string to create conditions from. - :param snuba_params: Filtering parameters with start, end, project_id, environment - :param data_filter: Indicate the filter strategy to be applied to the data. + :param str user_query: Filter query string to create conditions from. + :param {str: str} params: Filtering parameters with start, end, project_id, environment + :param str data_filter: Indicate the filter strategy to be applied to the data. """ if min_value is not None and max_value is not None: return min_value, max_value @@ -1128,7 +1148,7 @@ def find_span_histogram_min_max( results = query( selected_columns=selected_columns, query=user_query, - snuba_params=snuba_params, + params=params, limit=1, referrer="api.organization-spans-histogram-min-max", functions_acl=["fn_span_exclusive_time"], @@ -1196,21 +1216,21 @@ def find_span_op_count_histogram_min_max( min_value: float | None, max_value: float | None, user_query: str, - snuba_params: SnubaParams, + params: ParamsType, data_filter: Literal["exclude_outliers"] | None = None, ) -> tuple[float | None, float | None]: """ Find the min/max value of the specified span op count. If either min/max is already specified, it will be used and not queried for. - :param span_op: A span op for which count you want to generate the histograms for. - :param min_value: The minimum value allowed to be in the histogram. + :param str span_op: A span op for which count you want to generate the histograms for. + :param float min_value: The minimum value allowed to be in the histogram. If left unspecified, it is queried using `user_query` and `params`. - :param max_value: The maximum value allowed to be in the histogram. + :param float max_value: The maximum value allowed to be in the histogram. If left unspecified, it is queried using `user_query` and `params`. - :param user_query: Filter query string to create conditions from. - :param params: Filtering parameters with start, end, project_id, environment - :param data_filter: Indicate the filter strategy to be applied to the data. + :param str user_query: Filter query string to create conditions from. + :param {str: str} params: Filtering parameters with start, end, project_id, environment + :param str data_filter: Indicate the filter strategy to be applied to the data. """ if min_value is not None and max_value is not None: return min_value, max_value @@ -1235,7 +1255,7 @@ def find_span_op_count_histogram_min_max( results = query( selected_columns=selected_columns, query=user_query, - snuba_params=snuba_params, + params=params, limit=1, referrer="api.organization-spans-histogram-min-max", functions_acl=["fn_span_count"], @@ -1303,7 +1323,7 @@ def find_histogram_min_max( min_value: float | None, max_value: float | None, user_query: str, - snuba_params: SnubaParams, + params: ParamsType, data_filter: Literal["exclude_outliers"] | None = None, query_fn: Callable | None = None, ) -> tuple[float | None, float | None]: @@ -1311,14 +1331,14 @@ def find_histogram_min_max( Find the min/max value of the specified fields. If either min/max is already specified, it will be used and not queried for. - :param fields: The list of fields for which you want to generate the histograms for. - :param min_value: The minimum value allowed to be in the histogram. + :param [str] fields: The list of fields for which you want to generate the histograms for. + :param float min_value: The minimum value allowed to be in the histogram. If left unspecified, it is queried using `user_query` and `params`. - :param max_value: The maximum value allowed to be in the histogram. + :param float max_value: The maximum value allowed to be in the histogram. If left unspecified, it is queried using `user_query` and `params`. - :param user_query: Filter query string to create conditions from. - :param params: Filtering parameters with start, end, project_id, environment - :param data_filter: Indicate the filter strategy to be applied to the data. + :param str user_query: Filter query string to create conditions from. + :param {str: str} params: Filtering parameters with start, end, project_id, environment + :param str data_filter: Indicate the filter strategy to be applied to the data. """ if min_value is not None and max_value is not None: @@ -1343,7 +1363,7 @@ def find_histogram_min_max( results = query_fn( selected_columns=min_columns + max_columns + quartiles, query=user_query, - snuba_params=snuba_params, + params=params, limit=1, referrer="api.organization-events-histogram-min-max", ) diff --git a/src/sentry/snuba/errors.py b/src/sentry/snuba/errors.py index 346f943cbf5895..eec2d32a8d888a 100644 --- a/src/sentry/snuba/errors.py +++ b/src/sentry/snuba/errors.py @@ -1,5 +1,6 @@ import logging from collections.abc import Mapping, Sequence +from copy import deepcopy from datetime import timedelta from typing import cast @@ -15,7 +16,7 @@ ErrorsTopEventsQueryBuilder, ) from sentry.search.events.fields import get_json_meta_type -from sentry.search.events.types import EventsResponse, QueryBuilderConfig, SnubaParams +from sentry.search.events.types import EventsResponse, ParamsType, QueryBuilderConfig, SnubaParams from sentry.snuba.dataset import Dataset from sentry.snuba.discover import OTHER_KEY, create_result_key, transform_tips, zerofill from sentry.snuba.metrics.extraction import MetricSpecType @@ -33,7 +34,8 @@ def query( selected_columns, query, - snuba_params, + params, + snuba_params=None, equations=None, orderby=None, offset=None, @@ -61,7 +63,7 @@ def query( builder = ErrorsQueryBuilder( Dataset.Events, - params={}, + params, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -92,8 +94,9 @@ def query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, + snuba_params: SnubaParams | None = None, referrer: str | None = None, zerofill_results: bool = True, comparison_delta: timedelta | None = None, @@ -106,12 +109,15 @@ def timeseries_query( query_source: QuerySource | None = None, ): + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + with sentry_sdk.start_span(op="errors", description="timeseries.filter_transform"): equations, columns = categorize_columns(selected_columns) base_builder = ErrorsTimeseriesQueryBuilder( Dataset.Events, - params={}, - interval=rollup, + params, + rollup, snuba_params=snuba_params, query=query, selected_columns=columns, @@ -126,9 +132,9 @@ def timeseries_query( if comparison_delta: if len(base_builder.aggregates) != 1: raise InvalidSearchQuery("Only one column can be selected for comparison queries") - comp_query_params = snuba_params.copy() - comp_query_params.start -= comparison_delta - comp_query_params.end -= comparison_delta + comp_query_params = deepcopy(params) + comp_query_params["start"] -= comparison_delta + comp_query_params["end"] -= comparison_delta comparison_builder = ErrorsTimeseriesQueryBuilder( Dataset.Events, comp_query_params, @@ -187,8 +193,8 @@ def timeseries_query( } }, }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -197,11 +203,12 @@ def top_events_timeseries( timeseries_columns: list[str], selected_columns: list[str], user_query: str, - snuba_params: SnubaParams, + params: ParamsType, orderby: list[str], rollup: int, limit: int, organization: Organization, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, referrer: str | None = None, top_events: EventsResponse | None = None, @@ -236,11 +243,15 @@ def top_events_timeseries( represent the top events matching the query. Useful when you have found the top events earlier and want to save a query. """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if top_events is None: with sentry_sdk.start_span(op="discover.errors", description="top_events.fetch_events"): top_events = query( selected_columns, query=user_query, + params=params, equations=equations, orderby=orderby, limit=limit, @@ -255,9 +266,9 @@ def top_events_timeseries( top_events_builder = ErrorsTopEventsQueryBuilder( Dataset.Events, - params={}, - interval=rollup, - top_events=top_events["data"], + params, + rollup, + top_events["data"], other=False, query=user_query, selected_columns=selected_columns, @@ -272,9 +283,9 @@ def top_events_timeseries( if len(top_events["data"]) == limit and include_other: other_events_builder = ErrorsTopEventsQueryBuilder( Dataset.Events, - params={}, - interval=rollup, - top_events=top_events["data"], + params, + rollup, + top_events["data"], other=True, query=user_query, selected_columns=selected_columns, @@ -298,13 +309,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - zerofill([], snuba_params.start_date, snuba_params.end_date, rollup, ["time"]) + zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) with sentry_sdk.start_span( @@ -317,7 +328,7 @@ def top_events_timeseries( if "issue" in selected_columns: issues = Group.objects.get_issues_mapping( {cast(int, event["issue.id"]) for event in top_events["data"]}, - snuba_params.project_ids, + params["project_id"], organization, ) translated_groupby = top_events_builder.translated_groupby @@ -346,20 +357,14 @@ def top_events_timeseries( top_events_results[key] = SnubaTSResult( { "data": ( - zerofill( - item["data"], - snuba_params.start_date, - snuba_params.end_date, - rollup, - ["time"], - ) + zerofill(item["data"], params["start"], params["end"], rollup, ["time"]) if zerofill_results else item["data"] ), "order": item["order"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) diff --git a/src/sentry/snuba/functions.py b/src/sentry/snuba/functions.py index 74fcc5681398cd..a8e26f83e7d713 100644 --- a/src/sentry/snuba/functions.py +++ b/src/sentry/snuba/functions.py @@ -11,7 +11,7 @@ ProfileTopFunctionsTimeseriesQueryBuilder, ) from sentry.search.events.fields import get_json_meta_type -from sentry.search.events.types import QueryBuilderConfig, SnubaParams +from sentry.search.events.types import ParamsType, QueryBuilderConfig, SnubaParams from sentry.snuba.dataset import Dataset from sentry.snuba.discover import transform_tips, zerofill from sentry.snuba.metrics.extraction import MetricSpecType @@ -24,7 +24,8 @@ def query( selected_columns: list[str], query: str | None, - snuba_params: SnubaParams, + params: ParamsType, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, orderby: list[str] | None = None, offset: int = 0, @@ -50,7 +51,7 @@ def query( builder = ProfileFunctionsQueryBuilder( dataset=Dataset.Functions, - params={}, + params=params, query=query, snuba_params=snuba_params, selected_columns=selected_columns, @@ -78,9 +79,10 @@ def query( def timeseries_query( selected_columns: list[str], query: str | None, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str = "", + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, comparison_delta: datetime | None = None, functions_acl: list[str] | None = None, @@ -92,9 +94,12 @@ def timeseries_query( query_source: QuerySource | None = None, ) -> Any: + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + builder = ProfileFunctionsTimeseriesQueryBuilder( dataset=Dataset.Functions, - params={}, + params=params, snuba_params=snuba_params, query=query, interval=rollup, @@ -111,8 +116,8 @@ def timeseries_query( "data": ( zerofill( results["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ["time"], ) @@ -126,8 +131,8 @@ def timeseries_query( } }, }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -136,11 +141,12 @@ def top_events_timeseries( timeseries_columns, selected_columns, user_query, - snuba_params, + params, orderby, rollup, limit, organization, + snuba_params=None, equations=None, referrer=None, top_events=None, @@ -160,6 +166,7 @@ def top_events_timeseries( top_events = query( selected_columns, query=user_query, + params=params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -172,7 +179,7 @@ def top_events_timeseries( top_functions_builder = ProfileTopFunctionsTimeseriesQueryBuilder( dataset=Dataset.Functions, - params={}, + params=params, snuba_params=snuba_params, interval=rollup, top_events=top_events["data"], @@ -195,8 +202,9 @@ def top_events_timeseries( return format_top_events_timeseries_results( result, top_functions_builder, - snuba_params, + params, rollup, + snuba_params=snuba_params, top_events=top_events, allow_empty=allow_empty, zerofill_results=zerofill_results, @@ -207,8 +215,9 @@ def top_events_timeseries( def format_top_events_timeseries_results( result, query_builder, - snuba_params, + params, rollup, + snuba_params=None, top_events=None, allow_empty=True, zerofill_results=True, @@ -217,17 +226,21 @@ def format_top_events_timeseries_results( if top_events is None: assert top_events, "Need to provide top events" # TODO: support this use case + if snuba_params is not None and len(params) == 0: + # Compatibility so its easier to convert to SnubaParams + params = snuba_params.filter_params + if not allow_empty and not len(result.get("data", [])): return SnubaTSResult( { "data": ( - zerofill([], snuba_params.start_date, snuba_params.end_date, rollup, ["time"]) + zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -262,13 +275,7 @@ def format_top_events_timeseries_results( key: SnubaTSResult( { "data": ( - zerofill( - item["data"], - snuba_params.start_date, - snuba_params.end_date, - rollup, - ["time"], - ) + zerofill(item["data"], params["start"], params["end"], rollup, ["time"]) if zerofill_results else item["data"] ), @@ -282,8 +289,8 @@ def format_top_events_timeseries_results( } }, }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) for key, item in results.items() diff --git a/src/sentry/snuba/issue_platform.py b/src/sentry/snuba/issue_platform.py index 62d6397c520b2d..ee2bbb40b478e6 100644 --- a/src/sentry/snuba/issue_platform.py +++ b/src/sentry/snuba/issue_platform.py @@ -1,4 +1,5 @@ from collections.abc import Sequence +from copy import deepcopy from datetime import timedelta import sentry_sdk @@ -19,7 +20,8 @@ def query( selected_columns, query, - snuba_params, + params, + snuba_params=None, equations=None, orderby=None, offset=None, @@ -78,7 +80,7 @@ def query( builder = DiscoverQueryBuilder( Dataset.IssuePlatform, - {}, + params, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -108,8 +110,9 @@ def query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: dict[str, str], rollup: int, + snuba_params: SnubaParams | None = None, referrer: str | None = None, zerofill_results: bool = True, comparison_delta: timedelta | None = None, @@ -145,11 +148,14 @@ def timeseries_query( allow_metric_aggregates (bool) Ignored here, only used in metric enhanced performance """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + with sentry_sdk.start_span(op="issueplatform", description="timeseries.filter_transform"): equations, columns = categorize_columns(selected_columns) base_builder = IssuePlatformTimeseriesQueryBuilder( Dataset.IssuePlatform, - {}, + params, rollup, snuba_params=snuba_params, query=query, @@ -164,14 +170,13 @@ def timeseries_query( if comparison_delta: if len(base_builder.aggregates) != 1: raise InvalidSearchQuery("Only one column can be selected for comparison queries") - comp_query_params = snuba_params.copy() - comp_query_params.start -= comparison_delta - comp_query_params.end -= comparison_delta + comp_query_params = deepcopy(params) + comp_query_params["start"] -= comparison_delta + comp_query_params["end"] -= comparison_delta comparison_builder = IssuePlatformTimeseriesQueryBuilder( Dataset.IssuePlatform, - {}, + comp_query_params, rollup, - snuba_params=comp_query_params, query=query, selected_columns=columns, equations=equations, @@ -224,7 +229,7 @@ def timeseries_query( } }, }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) diff --git a/src/sentry/snuba/metrics_enhanced_performance.py b/src/sentry/snuba/metrics_enhanced_performance.py index acc8a7d28663ae..884089538effeb 100644 --- a/src/sentry/snuba/metrics_enhanced_performance.py +++ b/src/sentry/snuba/metrics_enhanced_performance.py @@ -11,7 +11,7 @@ from sentry.discover.arithmetic import categorize_columns from sentry.exceptions import IncompatibleMetricsQuery, InvalidSearchQuery from sentry.models.organization import Organization -from sentry.search.events.types import EventsResponse, SnubaParams +from sentry.search.events.types import EventsResponse, ParamsType, SnubaParams from sentry.snuba import discover, transactions from sentry.snuba.metrics.extraction import MetricSpecType from sentry.snuba.metrics_performance import histogram_query as metrics_histogram_query @@ -25,7 +25,8 @@ def query( selected_columns: list[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, orderby: list[str] | None = None, offset: int | None = None, @@ -57,6 +58,7 @@ def query( result = metrics_query( selected_columns, query, + params, snuba_params, equations, orderby, @@ -99,6 +101,7 @@ def query( results = dataset.query( selected_columns, query, + params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -126,9 +129,10 @@ def query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -146,13 +150,17 @@ def timeseries_query( equations, columns = categorize_columns(selected_columns) metrics_compatible = not equations + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if metrics_compatible: try: return metrics_timeseries_query( selected_columns, query, - snuba_params, + params, rollup, + snuba_params=snuba_params, referrer=referrer, zerofill_results=zerofill_results, allow_metric_aggregates=allow_metric_aggregates, @@ -177,7 +185,8 @@ def timeseries_query( return discover.timeseries_query( selected_columns, query, - snuba_params, + params, + snuba_params=snuba_params, rollup=rollup, referrer=referrer, zerofill_results=zerofill_results, @@ -189,15 +198,13 @@ def timeseries_query( return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, ["time"] - ) + discover.zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -206,11 +213,12 @@ def top_events_timeseries( timeseries_columns: list[str], selected_columns: list[str], user_query: str, - snuba_params: SnubaParams, + params: ParamsType, orderby: list[str], rollup: int, limit: int, organization: Organization, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, referrer: str | None = None, top_events: EventsResponse | None = None, @@ -227,17 +235,21 @@ def top_events_timeseries( if not equations: metrics_compatible = True + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if metrics_compatible: try: return metrics_top_events_timeseries( timeseries_columns, selected_columns, user_query, - snuba_params, + params, orderby, rollup, limit, organization, + snuba_params, equations, referrer, top_events, @@ -264,11 +276,12 @@ def top_events_timeseries( timeseries_columns, selected_columns, user_query, - snuba_params, + params, orderby, rollup, limit, organization, + snuba_params, equations, referrer, top_events, @@ -281,15 +294,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, ["time"] - ) + discover.zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -297,8 +308,9 @@ def top_events_timeseries( def histogram_query( fields, user_query, - snuba_params, + params, num_buckets, + snuba_params=None, precision=0, min_value=None, max_value=None, @@ -326,8 +338,9 @@ def histogram_query( return metrics_histogram_query( fields, user_query, - snuba_params, + params, num_buckets, + snuba_params, precision, min_value, max_value, @@ -356,8 +369,9 @@ def histogram_query( return discover.histogram_query( fields, user_query, - snuba_params, + params, num_buckets, + snuba_params, precision, min_value, max_value, diff --git a/src/sentry/snuba/metrics_performance.py b/src/sentry/snuba/metrics_performance.py index 2b5eaa1f007a57..824d5897f515a2 100644 --- a/src/sentry/snuba/metrics_performance.py +++ b/src/sentry/snuba/metrics_performance.py @@ -17,7 +17,7 @@ TopMetricsQueryBuilder, ) from sentry.search.events.fields import get_function_alias -from sentry.search.events.types import EventsResponse, QueryBuilderConfig, SnubaParams +from sentry.search.events.types import EventsResponse, ParamsType, QueryBuilderConfig, SnubaParams from sentry.snuba import discover from sentry.snuba.dataset import Dataset from sentry.snuba.metrics.extraction import MetricSpecType @@ -32,6 +32,7 @@ def query( selected_columns, query, + params, snuba_params=None, equations=None, orderby=None, @@ -55,8 +56,8 @@ def query( ): with sentry_sdk.start_span(op="mep", description="MetricQueryBuilder"): metrics_query = MetricsQueryBuilder( + params, dataset=Dataset.PerformanceMetrics, - params={}, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -93,9 +94,10 @@ def query( def bulk_timeseries_query( selected_columns: Sequence[str], queries: list[str], - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -116,9 +118,10 @@ def bulk_timeseries_query( def bulk_timeseries_query( selected_columns: Sequence[str], queries: list[str], - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -136,9 +139,10 @@ def bulk_timeseries_query( def bulk_timeseries_query( selected_columns: Sequence[str], queries: list[str], - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -161,14 +165,16 @@ def bulk_timeseries_query( if comparison_delta is None and not equations: metrics_compatible = True + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if metrics_compatible: with sentry_sdk.start_span(op="mep", description="TimeseriesMetricQueryBuilder"): metrics_queries = [] for query in queries: metrics_query = TimeseriesMetricQueryBuilder( - {}, + params, rollup, - snuba_params=snuba_params, dataset=Dataset.PerformanceMetrics, query=query, selected_columns=columns, @@ -202,16 +208,16 @@ def bulk_timeseries_query( result["data"] = ( discover.zerofill( result["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ["time"], ) if zerofill_results else discover.format_time( result["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ["time"], ) @@ -223,22 +229,20 @@ def bulk_timeseries_query( "isMetricsData": True, "meta": result["meta"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, ["time"] - ) + discover.zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -246,9 +250,10 @@ def bulk_timeseries_query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -267,12 +272,14 @@ def timeseries_query( equations, columns = categorize_columns(selected_columns) metrics_compatible = not equations - def run_metrics_query(inner_params: SnubaParams): + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + + def run_metrics_query(inner_params: ParamsType): with sentry_sdk.start_span(op="mep", description="TimeseriesMetricQueryBuilder"): metrics_query = TimeseriesMetricQueryBuilder( - params={}, - interval=rollup, - snuba_params=inner_params, + inner_params, + rollup, dataset=Dataset.PerformanceMetrics, query=query, selected_columns=columns, @@ -292,8 +299,8 @@ def run_metrics_query(inner_params: SnubaParams): result["data"] = ( discover.zerofill( result["data"], - inner_params.start_date, - inner_params.end_date, + inner_params["start"], + inner_params["end"], rollup, ["time"], ) @@ -319,14 +326,15 @@ def run_metrics_query(inner_params: SnubaParams): # # In case we want to support multiple aggregate comparisons, we can just remove the condition below and rework # the implementation of the `comparisonCount` field. - result = run_metrics_query(inner_params=snuba_params) + result = run_metrics_query(inner_params=params) if comparison_delta: - comparison_params = snuba_params.copy() - assert comparison_params.start is not None, "start is required" - assert comparison_params.end is not None, "end is required" - comparison_params.start -= comparison_delta - comparison_params.end -= comparison_delta - result_to_compare = run_metrics_query(inner_params=comparison_params) + result_to_compare = run_metrics_query( + inner_params={ + **params, + "start": params["start"] - comparison_delta, + "end": params["end"] - comparison_delta, + } + ) aliased_columns = [ get_function_alias(selected_column) for selected_column in selected_columns @@ -365,8 +373,8 @@ def run_metrics_query(inner_params: SnubaParams): "meta": result["meta"], }, # We keep the params passed in the function as the time interval. - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -374,15 +382,13 @@ def run_metrics_query(inner_params: SnubaParams): return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, ["time"] - ) + discover.zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -391,11 +397,12 @@ def top_events_timeseries( timeseries_columns, selected_columns, user_query, - snuba_params, + params, orderby, rollup, limit, organization, + snuba_params=None, equations=None, referrer=None, top_events=None, @@ -408,10 +415,14 @@ def top_events_timeseries( query_source: QuerySource | None = None, ) -> SnubaTSResult | dict[str, Any]: + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if top_events is None: top_events = query( selected_columns, query=user_query, + params=params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -426,9 +437,9 @@ def top_events_timeseries( top_events_builder = TopMetricsQueryBuilder( Dataset.PerformanceMetrics, - params={}, - interval=rollup, - top_events=top_events["data"], + params, + rollup, + top_events["data"], snuba_params=snuba_params, other=False, query=user_query, @@ -443,9 +454,9 @@ def top_events_timeseries( if len(top_events["data"]) == limit and include_other: other_events_builder = TopMetricsQueryBuilder( Dataset.PerformanceMetrics, - params={}, - interval=rollup, - top_events=top_events["data"], + params, + rollup, + top_events["data"], snuba_params=snuba_params, other=True, query=user_query, @@ -471,15 +482,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, ["time"] - ) + discover.zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -510,11 +519,7 @@ def top_events_timeseries( { "data": ( discover.zerofill( - item["data"], - snuba_params.start_date, - snuba_params.end_date, - rollup, - ["time"], + item["data"], params["start"], params["end"], rollup, ["time"] ) if zerofill_results else item["data"] @@ -524,8 +529,8 @@ def top_events_timeseries( # This could mislead downstream consumers of the meta data "meta": {"isMetricsExtractedData": top_events_builder.use_on_demand}, }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -535,8 +540,9 @@ def top_events_timeseries( def histogram_query( fields, user_query, - snuba_params, + params, num_buckets, + snuba_params=None, precision=0, min_value=None, max_value=None, @@ -577,6 +583,9 @@ def histogram_query( :param bool normalize_results: Indicate whether to normalize the results by column into bins. """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if data_filter == "exclude_outliers": if user_query is None: user_query = INLIER_QUERY_CLAUSE @@ -590,7 +599,7 @@ def histogram_query( max_value -= 0.1 / multiplier min_value, max_value = discover.find_histogram_min_max( - fields, min_value, max_value, user_query, snuba_params, data_filter, query_fn=query + fields, min_value, max_value, user_query, params, data_filter, query_fn=query ) if min_value is None or max_value is None: return {"meta": {"isMetricsData": True}} @@ -601,7 +610,7 @@ def histogram_query( histogram_params, # Arguments for QueryBuilder dataset=Dataset.PerformanceMetrics, - params={}, + params=params, snuba_params=snuba_params, query=user_query, selected_columns=[f"histogram({field})" for field in fields], diff --git a/src/sentry/snuba/profile_functions_metrics.py b/src/sentry/snuba/profile_functions_metrics.py index a7b2feb060187e..d0865141342144 100644 --- a/src/sentry/snuba/profile_functions_metrics.py +++ b/src/sentry/snuba/profile_functions_metrics.py @@ -9,7 +9,7 @@ TimeseriesProfileFunctionsMetricsQueryBuilder, TopProfileFunctionsMetricsQueryBuilder, ) -from sentry.search.events.types import EventsResponse, QueryBuilderConfig, SnubaParams +from sentry.search.events.types import EventsResponse, ParamsType, QueryBuilderConfig, SnubaParams from sentry.snuba import discover from sentry.snuba.dataset import Dataset from sentry.snuba.metrics.extraction import MetricSpecType @@ -23,6 +23,7 @@ def query( selected_columns: list[str], query: str, referrer: str, + params: ParamsType, snuba_params: SnubaParams | None = None, equations: list[str] | None = None, orderby: list[str] | None = None, @@ -48,7 +49,7 @@ def query( ): builder = ProfileFunctionsMetricsQueryBuilder( dataset=Dataset.PerformanceMetrics, - params={}, + params=params, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -77,9 +78,10 @@ def query( def timeseries_query( selected_columns: list[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -96,8 +98,11 @@ def timeseries_query( this API should match that of sentry.snuba.discover.timeseries_query """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + metrics_query = TimeseriesProfileFunctionsMetricsQueryBuilder( - {}, + params, rollup, snuba_params=snuba_params, dataset=Dataset.PerformanceMetrics, @@ -116,8 +121,8 @@ def timeseries_query( result["data"] = ( discover.zerofill( result["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ["time"], ) @@ -133,8 +138,8 @@ def timeseries_query( "isMetricsData": True, "meta": result["meta"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -143,12 +148,13 @@ def top_events_timeseries( timeseries_columns: list[str], selected_columns: list[str], user_query: str, - snuba_params: SnubaParams, + params: ParamsType, orderby: list[str], rollup: int, limit: int, referrer: str, organization: sentry.models.Organization, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, top_events: EventsResponse | None = None, allow_empty: bool = True, @@ -181,10 +187,14 @@ def top_events_timeseries( the top events earlier and want to save a query. """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if top_events is None: top_events = query( selected_columns, query=user_query, + params=params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -198,7 +208,7 @@ def top_events_timeseries( top_events_builder = TopProfileFunctionsMetricsQueryBuilder( Dataset.PerformanceMetrics, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -214,7 +224,7 @@ def top_events_timeseries( if len(top_events["data"]) == limit and include_other: other_events_builder = TopProfileFunctionsMetricsQueryBuilder( Dataset.PerformanceMetrics, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -238,15 +248,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, ["time"] - ) + discover.zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -278,19 +286,15 @@ def top_events_timeseries( { "data": ( discover.zerofill( - item["data"], - snuba_params.start_date, - snuba_params.end_date, - rollup, - ["time"], + item["data"], params["start"], params["end"], rollup, ["time"] ) if zerofill_results else item["data"] ), "order": item["order"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) diff --git a/src/sentry/snuba/profiles.py b/src/sentry/snuba/profiles.py index cb9ed181ba96a8..fad4d3772af68c 100644 --- a/src/sentry/snuba/profiles.py +++ b/src/sentry/snuba/profiles.py @@ -7,7 +7,7 @@ ProfilesTimeseriesQueryBuilder, ) from sentry.search.events.fields import get_json_meta_type -from sentry.search.events.types import QueryBuilderConfig, SnubaParams +from sentry.search.events.types import ParamsType, QueryBuilderConfig, SnubaParams from sentry.snuba.dataset import Dataset from sentry.snuba.discover import transform_tips, zerofill from sentry.snuba.metrics.extraction import MetricSpecType @@ -18,7 +18,8 @@ def query( selected_columns: list[str], query: str | None, - snuba_params: SnubaParams, + params: ParamsType, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, orderby: list[str] | None = None, offset: int = 0, @@ -42,7 +43,7 @@ def query( builder = ProfilesQueryBuilder( dataset=Dataset.Profiles, - params={}, + params=params, query=query, snuba_params=snuba_params, selected_columns=selected_columns, @@ -65,9 +66,10 @@ def query( def timeseries_query( selected_columns: list[str], query: str | None, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, referrer: str = "", + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, comparison_delta: datetime | None = None, functions_acl: list[str] | None = None, @@ -78,9 +80,13 @@ def timeseries_query( on_demand_metrics_type: MetricSpecType | None = None, query_source: QuerySource | None = None, ) -> Any: + + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + builder = ProfilesTimeseriesQueryBuilder( dataset=Dataset.Profiles, - params={}, + params=params, snuba_params=snuba_params, query=query, interval=rollup, @@ -96,8 +102,8 @@ def timeseries_query( "data": ( zerofill( results["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ["time"], ) @@ -111,7 +117,7 @@ def timeseries_query( } }, }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) diff --git a/src/sentry/snuba/spans_eap.py b/src/sentry/snuba/spans_eap.py index 0c810746eb32d4..630a68f8f2157b 100644 --- a/src/sentry/snuba/spans_eap.py +++ b/src/sentry/snuba/spans_eap.py @@ -12,7 +12,7 @@ TimeseriesSpanIndexedQueryBuilder, TopEventsSpanIndexedQueryBuilder, ) -from sentry.search.events.types import EventsResponse, QueryBuilderConfig, SnubaParams +from sentry.search.events.types import EventsResponse, ParamsType, QueryBuilderConfig, SnubaParams from sentry.snuba import discover from sentry.snuba.dataset import Dataset from sentry.snuba.metrics.extraction import MetricSpecType @@ -25,7 +25,8 @@ def query( selected_columns: list[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, orderby: list[str] | None = None, offset: int | None = None, @@ -52,7 +53,7 @@ def query( ): builder = SpansEAPQueryBuilder( Dataset.SpansEAP, - {}, + params, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -82,8 +83,9 @@ def query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params, + params: ParamsType, rollup: int, + snuba_params: SnubaParams | None = None, referrer: str | None = None, zerofill_results: bool = True, comparison_delta: timedelta | None = None, @@ -102,10 +104,13 @@ def timeseries_query( """ equations, columns = categorize_columns(selected_columns) + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + with sentry_sdk.start_span(op="spans_indexed", description="TimeseriesSpanIndexedQueryBuilder"): querybuilder = TimeseriesSpanIndexedQueryBuilder( Dataset.SpansEAP, - {}, + params, rollup, snuba_params=snuba_params, query=query, @@ -120,8 +125,8 @@ def timeseries_query( result["data"] = ( discover.zerofill( result["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ["time"], ) @@ -134,8 +139,8 @@ def timeseries_query( "data": result["data"], "meta": result["meta"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -144,11 +149,12 @@ def top_events_timeseries( timeseries_columns: list[str], selected_columns: list[str], user_query: str, - snuba_params: SnubaParams, + params: ParamsType, orderby: list[str], rollup: int, limit: int, organization: Organization, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, referrer: str | None = None, top_events: EventsResponse | None = None, @@ -171,6 +177,7 @@ def top_events_timeseries( top_events = query( selected_columns, query=user_query, + params=params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -185,7 +192,7 @@ def top_events_timeseries( top_events_builder = TopEventsSpanIndexedQueryBuilder( Dataset.SpansEAP, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -202,7 +209,7 @@ def top_events_timeseries( if len(top_events["data"]) == limit and include_other: other_events_builder = TopEventsSpanIndexedQueryBuilder( Dataset.SpansEAP, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -228,15 +235,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, ["time"] - ) + discover.zerofill([], params["start"], params["end"], rollup, ["time"]) if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) with sentry_sdk.start_span( @@ -272,19 +277,15 @@ def top_events_timeseries( { "data": ( discover.zerofill( - result_item["data"], - snuba_params.start_date, - snuba_params.end_date, - rollup, - ["time"], + result_item["data"], params["start"], params["end"], rollup, ["time"] ) if zerofill_results else result_item["data"] ), "order": result_item["order"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) diff --git a/src/sentry/snuba/spans_indexed.py b/src/sentry/snuba/spans_indexed.py index 3991906fe68c79..59d340b7b2e5fe 100644 --- a/src/sentry/snuba/spans_indexed.py +++ b/src/sentry/snuba/spans_indexed.py @@ -23,6 +23,7 @@ def query( selected_columns, query, + params, snuba_params=None, equations=None, orderby=None, @@ -49,7 +50,7 @@ def query( ): builder = SpansIndexedQueryBuilder( Dataset.SpansIndexed, - {}, + params, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -79,9 +80,10 @@ def query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: dict[str, str], rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -98,10 +100,13 @@ def timeseries_query( """ equations, columns = categorize_columns(selected_columns) + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + with sentry_sdk.start_span(op="spans_indexed", description="TimeseriesSpanIndexedQueryBuilder"): query = TimeseriesSpanIndexedQueryBuilder( Dataset.SpansIndexed, - {}, + params, rollup, snuba_params=snuba_params, query=query, @@ -116,8 +121,8 @@ def timeseries_query( result["data"] = ( discover.zerofill( result["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, "time", ) @@ -130,8 +135,8 @@ def timeseries_query( "data": result["data"], "meta": result["meta"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -140,11 +145,12 @@ def top_events_timeseries( timeseries_columns, selected_columns, user_query, - snuba_params, + params, orderby, rollup, limit, organization, + snuba_params=None, equations=None, referrer=None, top_events=None, @@ -162,11 +168,14 @@ def top_events_timeseries( this API should match that of sentry.snuba.discover.top_events_timeseries """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params if top_events is None: with sentry_sdk.start_span(op="spans_indexed", description="top_events.fetch_events"): top_events = query( selected_columns, query=user_query, + params=params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -181,7 +190,7 @@ def top_events_timeseries( top_events_builder = TopEventsSpanIndexedQueryBuilder( Dataset.SpansIndexed, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -198,7 +207,7 @@ def top_events_timeseries( if len(top_events["data"]) == limit and include_other: other_events_builder = TopEventsSpanIndexedQueryBuilder( Dataset.SpansIndexed, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -224,15 +233,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, "time" - ) + discover.zerofill([], params["start"], params["end"], rollup, "time") if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) with sentry_sdk.start_span( @@ -267,19 +274,15 @@ def top_events_timeseries( { "data": ( discover.zerofill( - item["data"], - snuba_params.start_date, - snuba_params.end_date, - rollup, - "time", + item["data"], params["start"], params["end"], rollup, "time" ) if zerofill_results else item["data"] ), "order": item["order"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) diff --git a/src/sentry/snuba/spans_metrics.py b/src/sentry/snuba/spans_metrics.py index 2153696713a3c3..c344a7656d1dd4 100644 --- a/src/sentry/snuba/spans_metrics.py +++ b/src/sentry/snuba/spans_metrics.py @@ -22,6 +22,7 @@ def query( selected_columns, query, + params, snuba_params=None, equations=None, orderby=None, @@ -48,7 +49,7 @@ def query( ): builder = SpansMetricsQueryBuilder( dataset=Dataset.PerformanceMetrics, - params={}, + params=params, snuba_params=snuba_params, query=query, selected_columns=selected_columns, @@ -79,9 +80,10 @@ def query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: dict[str, str], rollup: int, referrer: str, + snuba_params: SnubaParams | None = None, zerofill_results: bool = True, allow_metric_aggregates=True, comparison_delta: timedelta | None = None, @@ -98,9 +100,12 @@ def timeseries_query( this API should match that of sentry.snuba.discover.timeseries_query """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + metrics_query = TimeseriesSpansMetricsQueryBuilder( - params={}, - interval=rollup, + params, + rollup, snuba_params=snuba_params, dataset=Dataset.PerformanceMetrics, query=query, @@ -118,8 +123,8 @@ def timeseries_query( result["data"] = ( discover.zerofill( result["data"], - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, "time", ) @@ -135,8 +140,8 @@ def timeseries_query( "isMetricsData": True, "meta": result["meta"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -145,11 +150,12 @@ def top_events_timeseries( timeseries_columns, selected_columns, user_query, - snuba_params, + params, orderby, rollup, limit, organization, + snuba_params=None, equations=None, referrer=None, top_events=None, @@ -184,10 +190,14 @@ def top_events_timeseries( the top events earlier and want to save a query. """ + if len(params) == 0 and snuba_params is not None: + params = snuba_params.filter_params + if top_events is None: top_events = query( selected_columns, query=user_query, + params=params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -202,7 +212,7 @@ def top_events_timeseries( top_events_builder = TopSpansMetricsQueryBuilder( Dataset.PerformanceMetrics, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -218,7 +228,7 @@ def top_events_timeseries( if len(top_events["data"]) == limit and include_other: other_events_builder = TopSpansMetricsQueryBuilder( Dataset.PerformanceMetrics, - {}, + params, rollup, top_events["data"], snuba_params=snuba_params, @@ -242,15 +252,13 @@ def top_events_timeseries( return SnubaTSResult( { "data": ( - discover.zerofill( - [], snuba_params.start_date, snuba_params.end_date, rollup, "time" - ) + discover.zerofill([], params["start"], params["end"], rollup, "time") if zerofill_results else [] ), }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) @@ -280,16 +288,14 @@ def top_events_timeseries( results[key] = SnubaTSResult( { "data": ( - discover.zerofill( - item["data"], snuba_params.start_date, snuba_params.end_date, rollup, "time" - ) + discover.zerofill(item["data"], params["start"], params["end"], rollup, "time") if zerofill_results else item["data"] ), "order": item["order"], }, - snuba_params.start_date, - snuba_params.end_date, + params["start"], + params["end"], rollup, ) diff --git a/src/sentry/snuba/transactions.py b/src/sentry/snuba/transactions.py index c8286394cf277c..3b5a10f7083082 100644 --- a/src/sentry/snuba/transactions.py +++ b/src/sentry/snuba/transactions.py @@ -5,7 +5,7 @@ from snuba_sdk import Column, Condition from sentry.models.organization import Organization -from sentry.search.events.types import EventsResponse, SnubaParams +from sentry.search.events.types import EventsResponse, ParamsType, SnubaParams from sentry.snuba import discover from sentry.snuba.dataset import Dataset from sentry.snuba.metrics.extraction import MetricSpecType @@ -18,7 +18,8 @@ def query( selected_columns: list[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, orderby: list[str] | None = None, offset: int | None = None, @@ -46,6 +47,7 @@ def query( return discover.query( selected_columns, query, + params, snuba_params=snuba_params, equations=equations, orderby=orderby, @@ -76,8 +78,9 @@ def query( def timeseries_query( selected_columns: Sequence[str], query: str, - snuba_params: SnubaParams, + params: ParamsType, rollup: int, + snuba_params: SnubaParams | None = None, referrer: str | None = None, zerofill_results: bool = True, comparison_delta: timedelta | None = None, @@ -96,9 +99,10 @@ def timeseries_query( return discover.timeseries_query( selected_columns, query, - snuba_params, + params, rollup, referrer=referrer, + snuba_params=snuba_params, zerofill_results=zerofill_results, allow_metric_aggregates=allow_metric_aggregates, comparison_delta=comparison_delta, @@ -116,11 +120,12 @@ def top_events_timeseries( timeseries_columns: list[str], selected_columns: list[str], user_query: str, - snuba_params: SnubaParams, + params: ParamsType, orderby: list[str], rollup: int, limit: int, organization: Organization, + snuba_params: SnubaParams | None = None, equations: list[str] | None = None, referrer: str | None = None, top_events: EventsResponse | None = None, @@ -136,11 +141,12 @@ def top_events_timeseries( timeseries_columns, selected_columns, user_query, - snuba_params, + params, orderby, rollup, limit, organization, + snuba_params=snuba_params, equations=equations, referrer=referrer, top_events=top_events, diff --git a/src/sentry/tasks/check_am2_compatibility.py b/src/sentry/tasks/check_am2_compatibility.py index 8cb9eb035d839f..1f67c9efeedb6c 100644 --- a/src/sentry/tasks/check_am2_compatibility.py +++ b/src/sentry/tasks/check_am2_compatibility.py @@ -482,6 +482,7 @@ def get_sdks_version_used(cls, organization, project_objects): results = discover_query( selected_columns=selected_columns, query="event.type:transaction", + params={}, snuba_params=params, referrer="api.organization-events", ) diff --git a/src/sentry/tasks/statistical_detectors.py b/src/sentry/tasks/statistical_detectors.py index 624bd6e8b8060a..90b4e4da2856bf 100644 --- a/src/sentry/tasks/statistical_detectors.py +++ b/src/sentry/tasks/statistical_detectors.py @@ -523,6 +523,7 @@ def emit_function_regression_issue( result = functions.query( selected_columns=["project.id", "fingerprint", "examples()"], query="is_application:1", + params={}, snuba_params=params, orderby=["project.id"], limit=len(regressions), @@ -894,6 +895,7 @@ def query_functions(projects: list[Project], start: datetime) -> list[DetectorPa "p95()", ], query="is_application:1", + params={}, snuba_params=params, orderby=["project.id", "-count()"], limitby=("project.id", FUNCTIONS_PER_PROJECT), @@ -945,6 +947,7 @@ def query_functions_timeseries( timeseries_columns=[agg_function], selected_columns=["project.id", "fingerprint"], user_query="is_application:1", + params={}, snuba_params=params, orderby=None, # unused because top events is specified rollup=interval, diff --git a/tests/sentry/data_export/processors/test_discover.py b/tests/sentry/data_export/processors/test_discover.py index a73cb941495123..57b9b38cc210a1 100644 --- a/tests/sentry/data_export/processors/test_discover.py +++ b/tests/sentry/data_export/processors/test_discover.py @@ -36,7 +36,9 @@ def test_get_projects(self): DiscoverProcessor.get_projects(organization_id=self.org.id, query={"project": [-1]}) def test_handle_issue_id_fields(self): - processor = DiscoverProcessor(organization=self.org, discover_query=self.discover_query) + processor = DiscoverProcessor( + organization_id=self.org.id, discover_query=self.discover_query + ) assert processor.header_fields == ["count_id", "fake_field", "issue"] result_list = [{"issue": self.group.id, "issue.id": self.group.id}] new_result_list = processor.handle_fields(result_list) @@ -48,7 +50,9 @@ def test_handle_transaction_status_fields(self): **self.discover_query, "field": ["title", "event.type", "transaction.status"], } - processor = DiscoverProcessor(organization=self.org, discover_query=self.discover_query) + processor = DiscoverProcessor( + organization_id=self.org.id, discover_query=self.discover_query + ) assert processor.header_fields == ["title", "event.type", "transaction.status"] result_list = [ {"transaction.status": SPAN_STATUS_NAME_TO_CODE.get("ok")}, @@ -59,7 +63,9 @@ def test_handle_transaction_status_fields(self): assert new_result_list[1]["transaction.status"] == "not_found" def test_handle__fields(self): - processor = DiscoverProcessor(organization=self.org, discover_query=self.discover_query) + processor = DiscoverProcessor( + organization_id=self.org.id, discover_query=self.discover_query + ) assert processor.header_fields == ["count_id", "fake_field", "issue"] result_list = [{"issue": self.group.id, "issue.id": self.group.id}] new_result_list = processor.handle_fields(result_list) @@ -69,7 +75,9 @@ def test_handle__fields(self): def test_handle_equations(self): self.discover_query["field"] = ["count(id)", "fake(field)"] self.discover_query["equations"] = ["count(id) / fake(field)", "count(id) / 2"] - processor = DiscoverProcessor(organization=self.org, discover_query=self.discover_query) + processor = DiscoverProcessor( + organization_id=self.org.id, discover_query=self.discover_query + ) assert processor.header_fields == [ "count_id", "fake_field", @@ -95,7 +103,9 @@ def test_handle_transactions_dataset(self): "field": ["title", "transaction.status"], "dataset": "transactions", } - processor = DiscoverProcessor(organization=self.org, discover_query=self.discover_query) + processor = DiscoverProcessor( + organization_id=self.org.id, discover_query=self.discover_query + ) data = processor.data_fn(offset=0, limit=2)["data"] assert data[0] == { "title": "test transaction", @@ -115,7 +125,9 @@ def test_handle_errors_dataset(self): "field": ["title"], "dataset": "errors", } - processor = DiscoverProcessor(organization=self.org, discover_query=self.discover_query) + processor = DiscoverProcessor( + organization_id=self.org.id, discover_query=self.discover_query + ) data = processor.data_fn(offset=0, limit=2)["data"] assert data[0] == { "title": error_event.message, @@ -135,7 +147,7 @@ def test_handle_dataset(self): query["field"] = ["title", "count()"] query["dataset"] = "issuePlatform" self.create_performance_issue() - processor = DiscoverProcessor(organization=self.organization, discover_query=query) + processor = DiscoverProcessor(organization_id=self.organization.id, discover_query=query) assert processor.header_fields == [ "title", "count", diff --git a/tests/sentry/snuba/test_discover.py b/tests/sentry/snuba/test_discover.py index 4e3b1dc89cbc6c..9dd5e11ae42b5e 100644 --- a/tests/sentry/snuba/test_discover.py +++ b/tests/sentry/snuba/test_discover.py @@ -13,7 +13,7 @@ PROJECT_THRESHOLD_CONFIG_INDEX_ALIAS, PROJECT_THRESHOLD_OVERRIDE_CONFIG_INDEX_ALIAS, ) -from sentry.search.events.types import EventsResponse, HistogramParams, SnubaParams +from sentry.search.events.types import EventsResponse, HistogramParams from sentry.snuba import discover from sentry.snuba.dataset import Dataset from sentry.testutils.cases import TestCase @@ -40,7 +40,7 @@ def test_query_parse_error(self, mock_query): discover.query( selected_columns=[], query="foo(id):<1dino", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, ) assert mock_query.call_count == 0 @@ -54,7 +54,7 @@ def test_query_no_fields(self, mock_query): discover.query( selected_columns=[], query="event.type:transaction", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, ) assert "No columns selected" in str(err) assert mock_query.call_count == 0 @@ -66,9 +66,7 @@ def test_selected_columns_field_alias_macro(self, mock_query): "data": [{"user": "a@example.org", "project_id": self.project.id}], } discover.query( - selected_columns=["user", "project"], - query="", - snuba_params=SnubaParams(projects=[self.project]), + selected_columns=["user", "project"], query="", params={"project_id": [self.project.id]} ) mock_query.assert_called_with( selected_columns=[ @@ -109,7 +107,7 @@ def test_project_filter_limits_automatic_fields(self, mock_query): discover.query( selected_columns=["title", "project"], query=f"project:{project2.slug}", - snuba_params=SnubaParams(projects=[self.project, project2]), + params={"project_id": [self.project.id, project2.id]}, ) mock_query.assert_called_with( selected_columns=[ @@ -150,7 +148,7 @@ def test_project_with_aggregate_grouping(self, mock_query): discover.query( selected_columns=["title", "project", "p99()"], query=f"project:{project2.slug}", - snuba_params=SnubaParams(projects=[self.project, project2]), + params={"project_id": [self.project.id, project2.id]}, ) mock_query.assert_called_with( selected_columns=[ @@ -190,7 +188,7 @@ def test_selected_columns_no_auto_fields(self, mock_query): discover.query( selected_columns=["count()"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=False, ) mock_query.assert_called_with( @@ -222,7 +220,7 @@ def test_selected_columns_aliasing_in_function(self, mock_query): "count_unique(transaction.duration)", ], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -250,7 +248,7 @@ def test_selected_columns_aggregate_alias(self, mock_query): discover.query( selected_columns=["transaction", "p95()", "count_unique(transaction)"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -281,7 +279,7 @@ def test_selected_columns_failure_rate_alias(self, mock_query): discover.query( selected_columns=["transaction", "failure_rate()"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -323,7 +321,7 @@ def test_selected_columns_apdex_new_alias(self, mock_query): "apdex()", ], query="", - snuba_params=SnubaParams(projects=[self.project], organization=self.organization), + params={"project_id": [self.project.id], "organization_id": self.organization.id}, auto_fields=True, ) mock_query.assert_called_with( @@ -364,7 +362,7 @@ def test_selected_columns_user_misery_alias(self, mock_query): discover.query( selected_columns=["transaction", "user_misery(300)"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -412,7 +410,7 @@ def test_selected_columns_user_misery_new_alias(self, mock_query): "user_misery()", ], query="", - snuba_params=SnubaParams(projects=[self.project], organization=self.organization), + params={"project_id": [self.project.id], "organization_id": self.organization.id}, auto_fields=True, ) mock_query.assert_called_with( @@ -453,7 +451,7 @@ def test_selected_columns_count_miserable_alias(self, mock_query): discover.query( selected_columns=["transaction", "count_miserable(user, 300)"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -487,7 +485,7 @@ def test_selected_columns_count_miserable_allows_zero_threshold(self, mock_query discover.query( selected_columns=["transaction", "count_miserable(user,0)"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -521,7 +519,7 @@ def test_apdex_allows_zero_threshold(self, mock_query): discover.query( selected_columns=["transaction", "apdex(0)"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -569,7 +567,7 @@ def test_selected_columns_project_threshold_config_alias_no_configured_threshold "project_threshold_config", ], query="", - snuba_params=SnubaParams(projects=[self.project], organization=self.organization), + params={"project_id": [self.project.id], "organization_id": self.organization.id}, auto_fields=True, ) @@ -636,7 +634,7 @@ def test_threshold_config_selected_with_project_threshold_configured(self, mock_ "project_threshold_config", ], query="", - snuba_params=SnubaParams(projects=[self.project], organization=self.organization), + params={"project_id": [self.project.id], "organization_id": self.organization.id}, auto_fields=True, ) @@ -728,7 +726,7 @@ def test_threshold_config_selected_with_txn_threshold_configured(self, mock_quer "project_threshold_config", ], query="", - snuba_params=SnubaParams(projects=[self.project], organization=self.organization), + params={"project_id": [self.project.id], "organization_id": self.organization.id}, auto_fields=True, ) @@ -855,7 +853,7 @@ def test_threshold_config_selected_with_project_and_txn_thresholds_configured(se "project_threshold_config", ], query="", - snuba_params=SnubaParams(projects=[self.project], organization=self.organization), + params={"project_id": [self.project.id], "organization_id": self.organization.id}, auto_fields=True, ) @@ -1001,7 +999,7 @@ def test_selected_columns_count_miserable_new_alias(self, mock_query): "count_miserable(user)", ], query="", - snuba_params=SnubaParams(projects=[self.project], organization=self.organization), + params={"project_id": [self.project.id], "organization_id": self.organization.id}, auto_fields=True, ) @@ -1059,7 +1057,7 @@ def test_selected_columns_percentile_range_function(self, mock_query): "percentile_range(transaction.duration, 0.5, greater, 2020-05-02T14:45:01) as percentile_range_1", ], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -1099,7 +1097,7 @@ def test_selected_columns_avg_range_function(self, mock_query): "avg_range(transaction.duration, greater, 2020-05-02T14:45:01) as avg_range_1", ], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -1138,7 +1136,7 @@ def test_percentile_function(self, mock_query): discover.query( selected_columns=["transaction", "percentile(transaction.duration, 0.75)"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, ) mock_query.assert_called_with( @@ -1166,7 +1164,7 @@ def test_orderby_limit_offset(self, mock_query): discover.query( selected_columns=["project.id", "title"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, orderby=["project.id"], offset=100, limit=200, @@ -1193,7 +1191,7 @@ def test_orderby_must_be_selected_if_aggregate(self, mock_query): discover.query( selected_columns=["transaction", "transaction.duration"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, orderby=["count()"], ) assert mock_query.call_count == 0 @@ -1207,7 +1205,7 @@ def test_orderby_aggregate_alias(self, mock_query): discover.query( selected_columns=["count(id)", "project.id", "id"], query="", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, orderby=["count_id"], ) mock_query.assert_called_with( @@ -1235,7 +1233,7 @@ def test_conditions_order_and_groupby_aliasing(self, mock_query): discover.query( selected_columns=["timestamp", "transaction", "transaction.duration", "count()"], query="transaction.op:ok transaction.duration:200 sdk.name:python tags[projectid]:123", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, orderby=["-timestamp", "-count"], ) mock_query.assert_called_with( @@ -1268,7 +1266,7 @@ def test_conditions_nested_function_aliasing(self, mock_query): discover.query( selected_columns=["transaction", "count()"], query="event.type:transaction user.email:*@sentry.io message:recent-searches", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, ) mock_query.assert_called_with( selected_columns=["transaction"], @@ -1299,7 +1297,7 @@ def test_condition_transform(self, mock_query): discover.query( selected_columns=["transaction", "transaction.duration"], query="http.method:GET", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, ) mock_query.assert_called_with( selected_columns=["transaction", "duration"], @@ -1328,7 +1326,7 @@ def test_condition_projectid_transform(self, mock_query): discover.query( selected_columns=["transaction", "transaction.duration"], query="project_id:1", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, ) mock_query.assert_called_with( selected_columns=["transaction", "duration"], @@ -1359,7 +1357,7 @@ def test_condition_projectname_transform(self, mock_query): discover.query( selected_columns=["transaction", "transaction.duration"], query=f"project.name:{project2.slug}", - snuba_params=SnubaParams(projects=[self.project, project2]), + params={"project_id": [self.project.id, project2.id]}, ) mock_query.assert_called_with( selected_columns=["transaction", "duration"], @@ -1388,7 +1386,7 @@ def test_params_forward(self, mock_query): discover.query( selected_columns=["transaction", "transaction.duration"], query="http.method:GET", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, ) mock_query.assert_called_with( selected_columns=["transaction", "duration"], @@ -1417,7 +1415,7 @@ def test_aggregate_conditions(self, mock_query): discover.query( selected_columns=["transaction", "avg(transaction.duration)"], query="http.method:GET avg(transaction.duration):>5", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, ) mock_query.assert_called_with( @@ -1447,7 +1445,7 @@ def test_alias_aggregate_conditions(self, mock_query): discover.query( selected_columns=["transaction", "p95()"], query="http.method:GET p95():>5", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, ) @@ -1489,7 +1487,7 @@ def test_duration_aliases(self, mock_query): discover.query( selected_columns=["transaction", "p95()"], query=f"http.method:GET p95():>{query_string}", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, ) @@ -1520,7 +1518,7 @@ def test_alias_aggregate_conditions_with_brackets(self, mock_query): discover.query( selected_columns=["transaction", "p95()"], query="http.method:GET p95():>5", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, ) @@ -1557,7 +1555,7 @@ def test_aggregate_date_conditions(self, mock_query): "max(timestamp)", ], query="http.method:GET max(timestamp):>2019-12-01", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, ) mock_query.assert_called_with( @@ -1604,7 +1602,7 @@ def test_aggregate_duration_alias(self, mock_query): "max(timestamp)", ], query=f"http.method:GET avg(transaction.duration):>{query_string}", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, ) mock_query.assert_called_with( @@ -1640,7 +1638,7 @@ def test_aggregate_condition_missing_selected_column(self, mock_query): discover.query( selected_columns=["transaction"], query="http.method:GET max(timestamp):>5", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, ) @@ -1657,7 +1655,7 @@ def test_aggregate_condition_missing_with_auto(self, mock_query): discover.query( selected_columns=["transaction"], query="http.method:GET max(timestamp):>5", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, auto_aggregations=True, ) @@ -1675,7 +1673,7 @@ def test_no_aggregate_conditions_with_auto(self, mock_query): discover.query( selected_columns=["transaction"], query="http.method:GET max(timestamp):>5", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=False, auto_aggregations=True, ) @@ -1692,7 +1690,7 @@ def test_auto_aggregation(self, mock_query): discover.query( selected_columns=["transaction", "p95()"], query="http.method:GET max(timestamp):>5", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, auto_aggregations=True, ) @@ -1727,7 +1725,7 @@ def test_auto_aggregation_with_boolean_conditions(self, mock_query): discover.query( selected_columns=["transaction", "min(timestamp)"], query="max(timestamp):>5 AND min(timestamp):<10", - snuba_params=SnubaParams(projects=[self.project], start=start_time, end=end_time), + params={"project_id": [self.project.id], "start": start_time, "end": end_time}, use_aggregate_conditions=True, auto_aggregations=True, ) @@ -1761,7 +1759,7 @@ def test_function_conditions(self, mock_query): discover.query( selected_columns=["transaction", "percentile(transaction.duration, 0.75)"], query="percentile(transaction.duration, 0.75):>100", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, auto_fields=True, use_aggregate_conditions=True, ) @@ -1788,22 +1786,14 @@ def test_find_histogram_min_max(self, mock_query): # no rows returned from snuba mock_query.side_effect = [{"meta": [], "data": []}] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - None, - None, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], None, None, "", {"project_id": [self.project.id]} ) assert values == (None, None), f"failing for {array_column}" # more than 2 rows returned snuba mock_query.side_effect = [{"meta": [], "data": [{}, {}]}] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - None, - None, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], None, None, "", {"project_id": [self.project.id]} ) assert values == (None, None), f"failing for {array_column}" @@ -1818,21 +1808,13 @@ def test_find_histogram_min_max(self, mock_query): }, ] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - None, - None, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], None, None, "", {"project_id": [self.project.id]} ) assert values == (None, None), f"failing for {array_column}" # use the given min/max values = discover.find_histogram_min_max( - [f"{alias}.foo"], - 1, - 2, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], 1, 2, "", {"project_id": [self.project.id]} ) assert values == (1, 2), f"failing for {array_column}" @@ -1844,11 +1826,7 @@ def test_find_histogram_min_max(self, mock_query): }, ] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - 1.23, - None, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], 1.23, None, "", {"project_id": [self.project.id]} ) assert values == ( 1.23, @@ -1864,11 +1842,7 @@ def test_find_histogram_min_max(self, mock_query): }, ] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - 3.5, - None, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], 3.5, None, "", {"project_id": [self.project.id]} ) assert values == ( 3.5, @@ -1884,11 +1858,7 @@ def test_find_histogram_min_max(self, mock_query): }, ] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - None, - 3.4, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], None, 3.4, "", {"project_id": [self.project.id]} ) assert values == ( 3.4, @@ -1903,11 +1873,7 @@ def test_find_histogram_min_max(self, mock_query): }, ] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - None, - 3.45, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], None, 3.45, "", {"project_id": [self.project.id]} ) assert values == ( 1.23, @@ -1925,11 +1891,7 @@ def test_find_histogram_min_max(self, mock_query): }, ] values = discover.find_histogram_min_max( - [f"{alias}.foo"], - None, - None, - "", - SnubaParams(projects=[self.project]), + [f"{alias}.foo"], None, None, "", {"project_id": [self.project.id]} ) assert values == ( 1.23, @@ -1964,7 +1926,7 @@ def test_find_histogram_min_max(self, mock_query): None, None, "", - SnubaParams(projects=[self.project]), + {"project_id": [self.project.id]}, ) assert values == ( 1.23, @@ -1999,7 +1961,7 @@ def test_find_histogram_min_max(self, mock_query): None, None, "", - SnubaParams(projects=[self.project]), + {"project_id": [self.project.id]}, ) assert values == ( 1.23, @@ -2422,7 +2384,7 @@ def test_histogram_query(self, mock_query): results = discover.histogram_query( [f"{alias}.bar", f"{alias}.foo"], "", - SnubaParams(projects=[self.project]), + {"project_id": [self.project.id]}, 3, 0, ) @@ -2446,7 +2408,7 @@ def test_histogram_query_with_bad_fields(self): discover.histogram_query( [f"{alias}.bar", "transaction.duration"], "", - SnubaParams(projects=[self.project]), + {"project_id": [self.project.id]}, 3, 0, ) @@ -2499,7 +2461,7 @@ def test_histogram_query_with_optionals(self, mock_query): results = discover.histogram_query( [f"{alias}.bar", f"{alias}.foo"], "", - SnubaParams(projects=[self.project]), + {"project_id": [self.project.id]}, 3, 1, min_value=0.5, diff --git a/tests/sentry/snuba/test_discover_facets_query.py b/tests/sentry/snuba/test_discover_facets_query.py index 125043152e823b..7bf64f39f4d883 100644 --- a/tests/sentry/snuba/test_discover_facets_query.py +++ b/tests/sentry/snuba/test_discover_facets_query.py @@ -1,7 +1,7 @@ import pytest from sentry.exceptions import InvalidSearchQuery -from sentry.search.events.types import SnubaParams +from sentry.search.events.types import ParamsType from sentry.snuba import discover from sentry.testutils.cases import SnubaTestCase, TestCase from sentry.testutils.helpers.datetime import before_now, iso_format @@ -19,14 +19,14 @@ def test_invalid_query(self): with pytest.raises(InvalidSearchQuery): discover.get_facets( "\n", - SnubaParams(projects=[self.project], end=self.min_ago, start=self.day_ago), + {"project_id": [self.project.id], "end": self.min_ago, "start": self.day_ago}, "testing.get-facets-test", ) def test_no_results(self): results = discover.get_facets( "", - SnubaParams(projects=[self.project], end=self.min_ago, start=self.day_ago), + {"project_id": [self.project.id], "end": self.min_ago, "start": self.day_ago}, "testing.get-facets-test", ) assert results == [] @@ -52,7 +52,7 @@ def test_single_project(self): ) result = discover.get_facets( "", - SnubaParams(projects=[self.project], start=self.day_ago, end=self.min_ago), + {"project_id": [self.project.id], "start": self.day_ago, "end": self.min_ago}, "testing.get-facets-test", ) assert len(result) == 5 @@ -80,15 +80,21 @@ def test_project_filter(self): }, project_id=other_project.id, ) - params = SnubaParams(projects=[self.project], start=self.day_ago, end=self.min_ago) + params: ParamsType = { + "project_id": [self.project.id], + "start": self.day_ago, + "end": self.min_ago, + } result = discover.get_facets("", params, "testing.get-facets-test") keys = {r.key for r in result} assert keys == {"color", "level"} # Query more than one project. - params = SnubaParams( - projects=[self.project, other_project], start=self.day_ago, end=self.min_ago - ) + params = { + "project_id": [self.project.id, other_project.id], + "start": self.day_ago, + "end": self.min_ago, + } result = discover.get_facets("", params, "testing.get-facets-test") keys = {r.key for r in result} assert keys == {"level", "toy", "color", "project"} @@ -109,7 +115,7 @@ def test_environment_promoted_tag(self): ) result = discover.get_facets( "", - SnubaParams(projects=[self.project], start=self.day_ago, end=self.min_ago), + {"project_id": [self.project.id], "start": self.day_ago, "end": self.min_ago}, "testing.get-facets-test", ) keys = {r.key for r in result} @@ -136,7 +142,11 @@ def test_query_string(self): }, project_id=self.project.id, ) - params = SnubaParams(projects=[self.project], start=self.day_ago, end=self.min_ago) + params: ParamsType = { + "project_id": [self.project.id], + "start": self.day_ago, + "end": self.min_ago, + } result = discover.get_facets("bad", params, "testing.get-facets-test") keys = {r.key for r in result} assert "color" in keys @@ -166,7 +176,11 @@ def test_query_string_with_aggregate_condition(self): }, project_id=self.project.id, ) - params = SnubaParams(projects=[self.project], start=self.day_ago, end=self.min_ago) + params: ParamsType = { + "project_id": [self.project.id], + "start": self.day_ago, + "end": self.min_ago, + } result = discover.get_facets("bad", params, "testing.get-facets-test") keys = {r.key for r in result} assert "color" in keys @@ -198,7 +212,7 @@ def test_date_params(self): ) result = discover.get_facets( "", - SnubaParams(projects=[self.project], start=self.day_ago, end=self.min_ago), + {"project_id": [self.project.id], "start": self.day_ago, "end": self.min_ago}, "testing.get-facets-test", ) keys = {r.key for r in result} @@ -228,7 +242,7 @@ def test_count_sorting(self): ) result = discover.get_facets( "", - SnubaParams(projects=[self.project], start=self.day_ago, end=self.min_ago), + {"project_id": [self.project.id], "start": self.day_ago, "end": self.min_ago}, "testing.get-facets-test", ) first = result[0] diff --git a/tests/sentry/snuba/test_discover_query.py b/tests/sentry/snuba/test_discover_query.py index 072676a3b6a0b0..fa5f6f790c6fc3 100644 --- a/tests/sentry/snuba/test_discover_query.py +++ b/tests/sentry/snuba/test_discover_query.py @@ -70,6 +70,7 @@ def test_project_mapping(self): result = discover.query( selected_columns=["project", "message"], query="", + params={}, snuba_params=self.params, orderby=["project"], referrer="discover", @@ -94,6 +95,7 @@ def test_sorting_project_name(self): result = discover.query( selected_columns=["project", "message"], query="", + params={}, snuba_params=self.params, orderby=["project"], referrer="test_discover_query", @@ -117,6 +119,7 @@ def test_reverse_sorting_project_name(self): result = discover.query( selected_columns=["project", "message"], query="", + params={}, snuba_params=self.params, orderby=["-project"], referrer="test_discover_query", @@ -140,6 +143,7 @@ def test_using_project_and_project_name(self): result = discover.query( selected_columns=["project.name", "message", "project"], query="", + params={}, snuba_params=self.params, orderby=["project.name"], referrer="test_discover_query", @@ -172,6 +176,7 @@ def test_missing_project(self): result = discover.query( selected_columns=["message", "project"], query="", + params={}, snuba_params=self.params, orderby=["project"], referrer="test_discover_query", @@ -193,6 +198,7 @@ def test_issue_short_id_mapping(self): selected_columns=[column], query=query, referrer="discover", + params={}, snuba_params=self.params, ) data = result["data"] @@ -213,6 +219,7 @@ def test_issue_filters(self): result = discover.query( selected_columns=["issue", "issue.id"], query=query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -247,6 +254,7 @@ def test_tags_orderby(self): result = discover.query( selected_columns=[column], query="", + params={}, snuba_params=self.params, orderby=[orderby], referrer="test_discover_query", @@ -295,6 +303,7 @@ def test_tags_filter(self): result = discover.query( selected_columns=[column], query=query, + params={}, snuba_params=self.params, orderby=[column], referrer="test_discover_query", @@ -328,6 +337,7 @@ def test_tags_colliding_with_fields(self): result = discover.query( selected_columns=[column], query=query, + params={}, snuba_params=self.params, orderby=[column], referrer="test_discover_query", @@ -360,6 +370,7 @@ def test_reverse_sorting_issue(self): result = discover.query( selected_columns=[column], query="", + params={}, snuba_params=self.params, orderby=[f"{direction}{column}"], referrer="discover", @@ -375,6 +386,7 @@ def test_timestamp_rounding_fields(self): result = discover.query( selected_columns=["timestamp.to_hour", "timestamp.to_day"], query="", + params={}, snuba_params=self.params, referrer="test_discover_query", ) @@ -407,6 +419,7 @@ def test_timestamp_rounding_filters(self): result = discover.query( selected_columns=["timestamp.to_hour", "timestamp.to_day"], query=f"timestamp.to_hour:<{iso_format(one_day_ago)} timestamp.to_day:<{iso_format(one_day_ago)}", + params={}, snuba_params=self.params, referrer="test_discover_query", ) @@ -461,6 +474,7 @@ def test_user_display(self): result = discover.query( selected_columns=["user.display"], query="", + params={}, snuba_params=self.params, referrer="test_discover_query", ) @@ -490,6 +504,7 @@ def test_user_display_filter(self): result = discover.query( selected_columns=["user.display"], query="has:user.display user.display:bruce@example.com", + params={}, snuba_params=self.params, referrer="test_discover_query", ) @@ -519,6 +534,7 @@ def test_message_orderby(self): result = discover.query( selected_columns=["message"], query="", + params={}, snuba_params=self.params, orderby=[orderby], referrer="test_discover_query", @@ -558,6 +574,7 @@ def test_message_filter(self): result = discover.query( selected_columns=["message"], query=query, + params={}, snuba_params=self.params, orderby=["message"], referrer="test_discover_query", @@ -613,6 +630,7 @@ def test_team_key_transactions(self): result = discover.query( selected_columns=["transaction", "team_key_transaction"], query=query, + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -690,6 +708,7 @@ def test_snql_wip_project_threshold_config(self): result = discover.query( selected_columns=["project", "transaction", "project_threshold_config"], query="", + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -721,6 +740,7 @@ def test_snql_wip_project_threshold_config(self): result = discover.query( selected_columns=["project", "transaction", "project_threshold_config"], query="", + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -773,6 +793,7 @@ def test_to_other_function(self): selected_columns=cols, query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -827,6 +848,7 @@ def test_count_if_function(self): result = discover.query( selected_columns=cols, query=query, + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -873,6 +895,7 @@ def test_count_if_function_with_unicode(self): result = discover.query( selected_columns=cols, query=query, + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -919,6 +942,7 @@ def test_failure_count_function(self): selected_columns=["transaction", "failure_count()"], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -994,6 +1018,7 @@ def test_apdex_function(self): query=query, orderby=["transaction"], referrer="discover", + params={}, snuba_params=SnubaParams( start=before_now(minutes=30), end=before_now(minutes=2), @@ -1084,6 +1109,7 @@ def test_count_miserable_function(self): query=query, orderby=["transaction"], referrer="discover", + params={}, snuba_params=SnubaParams( start=before_now(minutes=30), end=before_now(minutes=2), @@ -1177,6 +1203,7 @@ def test_user_misery_function(self): referrer="discover", query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=30), end=before_now(minutes=2), @@ -1214,6 +1241,7 @@ def test_count(self): selected_columns=["transaction", "count()"], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -1271,6 +1299,7 @@ def test_compare_numeric_aggregate_function(self): selected_columns=selected, query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -1310,6 +1339,7 @@ def test_last_seen(self): query=query, referrer="discover", orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -1340,6 +1370,7 @@ def test_latest_event(self): query="", orderby=["transaction"], referrer="discover", + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -1385,6 +1416,7 @@ def test_failure_rate(self): selected_columns=["transaction", "failure_rate()"], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -1434,6 +1466,7 @@ def test_percentile(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=20), end=before_now(minutes=2), @@ -1469,6 +1502,7 @@ def test_p50(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=20), end=before_now(minutes=2), @@ -1502,6 +1536,7 @@ def test_p75(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=20), end=before_now(minutes=2), @@ -1536,6 +1571,7 @@ def test_p95(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=20), end=before_now(minutes=2), @@ -1570,6 +1606,7 @@ def test_p99(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=20), end=before_now(minutes=2), @@ -1604,6 +1641,7 @@ def test_p100(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=20), end=before_now(minutes=2), @@ -1647,6 +1685,7 @@ def test_p100_with_measurement(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=20), end=before_now(minutes=2), @@ -1674,6 +1713,7 @@ def test_count_unique(self): result = discover.query( selected_columns=["count_unique(user.display)", "count_unique(foo)"], query="", + params={}, snuba_params=SnubaParams( start=before_now(minutes=4), end=before_now(minutes=2), @@ -1706,6 +1746,7 @@ def test_min_max(self): "max(transaction.duration)", ], query="", + params={}, snuba_params=SnubaParams( start=before_now(minutes=4), end=before_now(minutes=2), @@ -1751,6 +1792,7 @@ def test_stats_functions(self): result = discover.query( selected_columns=[column], query="", + params={}, snuba_params=SnubaParams( start=before_now(minutes=4), end=before_now(minutes=2), @@ -1782,6 +1824,7 @@ def test_count_at_least(self): "count_at_least(transaction.duration,120000)", ], query="", + params={}, snuba_params=SnubaParams( start=before_now(minutes=4), end=before_now(minutes=2), @@ -1830,6 +1873,7 @@ def test_eps(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=4), end=before_now(minutes=2), @@ -1883,6 +1927,7 @@ def test_epm(self): ], query=query, orderby=["transaction"], + params={}, snuba_params=SnubaParams( start=before_now(minutes=4), end=before_now(minutes=2), @@ -1921,6 +1966,7 @@ def test_transaction_status(self): result = discover.query( selected_columns=["transaction.status"], query="", + params={}, snuba_params=self.params, referrer="discover", ) @@ -1948,6 +1994,7 @@ def run_query(query, expected_statuses, message): result = discover.query( selected_columns=["transaction.status"], query=query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -2004,6 +2051,7 @@ def test_error_handled_alias(self): result = discover.query( selected_columns=["error.handled"], query=query, + params={}, snuba_params=SnubaParams( start=before_now(minutes=12), end=before_now(minutes=8), @@ -2047,6 +2095,7 @@ def test_error_unhandled_alias(self): result = discover.query( selected_columns=["error.unhandled"], query=query, + params={}, snuba_params=SnubaParams( start=before_now(minutes=12), end=before_now(minutes=8), @@ -2084,6 +2133,7 @@ def test_array_fields(self): result = discover.query( selected_columns=["stack.filename"], query=query, + params={}, snuba_params=SnubaParams( start=before_now(minutes=12), end=before_now(minutes=8), @@ -2104,6 +2154,7 @@ def test_array_fields(self): selected_columns=["stack.filename"], query="stack.filename:[raven.js]", referrer="discover", + params={}, snuba_params=SnubaParams( start=before_now(minutes=12), end=before_now(minutes=8), @@ -2143,6 +2194,7 @@ def test_spans_op_array_field(self): result = discover.query( selected_columns=["spans_op"], query=query, + params={}, snuba_params=SnubaParams( start=before_now(minutes=12), end=before_now(minutes=8), @@ -2181,6 +2233,7 @@ def test_orderby_field_alias(self): selected_columns=["transaction", "error.unhandled"], query="", orderby=orderby, + params={}, snuba_params=SnubaParams( start=before_now(minutes=12), end=before_now(minutes=8), @@ -2230,6 +2283,7 @@ def test_orderby_aggregate_function(self): selected_columns=["transaction", "failure_count()"], query="", orderby=orderby, + params={}, snuba_params=SnubaParams( start=before_now(minutes=10), end=before_now(minutes=2), @@ -2245,6 +2299,7 @@ def test_field_aliasing_in_selected_columns(self): result = discover.query( selected_columns=["project.id", "user", "release", "timestamp.to_hour"], query="", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2269,6 +2324,7 @@ def test_field_alias_with_component(self): result = discover.query( selected_columns=["project.id", "user", "user.email"], query="", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2289,6 +2345,7 @@ def test_field_aliasing_in_aggregate_functions_and_groupby(self): result = discover.query( selected_columns=["project.id", "count_unique(user.email)"], query="", + params={}, snuba_params=self.params, auto_fields=True, referrer="discover", @@ -2302,6 +2359,7 @@ def test_field_aliasing_in_conditions(self): result = discover.query( selected_columns=["project.id", "user.email"], query="user.email:bruce@example.com", + params={}, snuba_params=self.params, referrer="discover", auto_fields=True, @@ -2316,6 +2374,7 @@ def test_auto_fields_simple_fields(self): selected_columns=["user.email", "release"], referrer="discover", query="", + params={}, snuba_params=self.params, auto_fields=True, ) @@ -2339,6 +2398,7 @@ def test_auto_fields_aggregates(self): selected_columns=["count_unique(user.email)"], referrer="discover", query="", + params={}, snuba_params=self.params, auto_fields=True, ) @@ -2350,6 +2410,7 @@ def test_release_condition(self): result = discover.query( selected_columns=["id", "message"], query=f"release:{self.create_release(self.project).version}", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2358,6 +2419,7 @@ def test_release_condition(self): result = discover.query( selected_columns=["id", "message"], query=f"release:{self.release.version}", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2400,6 +2462,7 @@ def test_semver_condition(self): result = discover.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:>1.2.3", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2412,6 +2475,7 @@ def test_semver_condition(self): result = discover.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:>=1.2.3", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2426,6 +2490,7 @@ def test_semver_condition(self): result = discover.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:<1.2.4", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2433,6 +2498,7 @@ def test_semver_condition(self): result = discover.query( selected_columns=["id"], query=f"!{SEMVER_ALIAS}:1.2.3", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2496,6 +2562,7 @@ def test_release_stage_condition(self): result = discover.query( selected_columns=["id"], query=f"{RELEASE_STAGE_ALIAS}:{ReleaseStages.ADOPTED.value}", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2507,6 +2574,7 @@ def test_release_stage_condition(self): result = discover.query( selected_columns=["id"], query=f"!{RELEASE_STAGE_ALIAS}:{ReleaseStages.LOW_ADOPTION.value}", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2519,6 +2587,7 @@ def test_release_stage_condition(self): result = discover.query( selected_columns=["id"], query=f"{RELEASE_STAGE_ALIAS}:[{ReleaseStages.ADOPTED.value}, {ReleaseStages.REPLACED.value}]", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2550,6 +2619,7 @@ def test_semver_package_condition(self): selected_columns=["id"], referrer="discover", query=f"{SEMVER_PACKAGE_ALIAS}:test", + params={}, snuba_params=self.params, ) assert {r["id"] for r in result["data"]} == { @@ -2560,6 +2630,7 @@ def test_semver_package_condition(self): selected_columns=["id"], query=f"{SEMVER_PACKAGE_ALIAS}:test2", referrer="discover", + params={}, snuba_params=self.params, ) assert {r["id"] for r in result["data"]} == { @@ -2586,6 +2657,7 @@ def test_semver_build_condition(self): result = discover.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:123", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2596,6 +2668,7 @@ def test_semver_build_condition(self): result = discover.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:124", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2605,6 +2678,7 @@ def test_semver_build_condition(self): result = discover.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:>=123", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2614,6 +2688,7 @@ def test_latest_release_condition(self): result = discover.query( selected_columns=["id", "message"], query="release:latest", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2627,6 +2702,7 @@ def test_environment_condition(self): result = discover.query( selected_columns=["id", "message"], query=f"environment:{self.create_environment(self.project).name}", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2635,6 +2711,7 @@ def test_environment_condition(self): result = discover.query( selected_columns=["id", "message"], query=f"environment:{self.environment.name}", + params={}, snuba_params=self.params, referrer="discover", ) @@ -2659,6 +2736,7 @@ def test_conditional_filter(self): result = discover.query( selected_columns=["project", "message"], query=f"project:{self.project.slug} OR project:{project2.slug}", + params={}, snuba_params=SnubaParams( projects=[self.project, project2], start=self.two_min_ago, @@ -2697,6 +2775,7 @@ def test_nested_conditional_filter(self): query="(release:{} OR release:{}) AND project:{}".format( "a" * 32, "b" * 32, self.project.slug ), + params={}, snuba_params=SnubaParams( projects=[self.project, project2], start=self.two_min_ago, @@ -2723,6 +2802,7 @@ def test_conditions_with_special_columns(self): result = discover.query( selected_columns=["title", "message"], query="event.type:transaction (title:{} OR message:{})".format("a" * 32, "b" * 32), + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2742,6 +2822,7 @@ def test_conditions_with_special_columns(self): query="event.type:transaction (title:{} AND sub_customer.is-Enterprise-42:{})".format( "a" * 32, "a" * 32 ), + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2773,6 +2854,7 @@ def test_conditions_with_aggregates(self): query="event.type:transaction (trek:{} OR trek:{}) AND count():>2".format( "a" * 32, "b" * 32 ), + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2805,6 +2887,7 @@ def test_conditions_with_nested_aggregates(self): query="(event.type:transaction AND (trek:{} AND (transaction:*{}* AND count():>2)))".format( "b" * 32, "b" * 32 ), + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2827,6 +2910,7 @@ def test_conditions_with_nested_aggregates(self): "b" * 32, "b" * 32 ), referrer="discover", + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2852,6 +2936,7 @@ def test_conditions_with_timestamps(self): iso_format(self.now - timedelta(seconds=5)), iso_format(self.now - timedelta(seconds=3)), ), + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2874,6 +2959,7 @@ def test_timestamp_rollup_filter(self): result = discover.query( selected_columns=["project.id", "user", "release"], query="timestamp.to_hour:" + iso_format(event_hour), + params={}, snuba_params=self.params, referrer="discover", ) @@ -2898,6 +2984,7 @@ def test_count_with_or(self): results = discover.query( selected_columns=["transaction", "count()"], query="event.type:transaction AND (count():<1 OR count():>0)", + params={}, snuba_params=self.params, orderby=["transaction"], use_aggregate_conditions=True, @@ -2921,6 +3008,7 @@ def test_array_join(self): results = discover.query( selected_columns=["array_join(measurements_key)"], query="", + params={}, snuba_params=self.params, functions_acl=["array_join"], referrer="discover", @@ -2935,6 +3023,7 @@ def test_access_to_private_functions(self): discover.query( selected_columns=["array_join(tags.key)"], query="", + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2949,6 +3038,7 @@ def test_access_to_private_functions(self): discover.query( selected_columns=[f"histogram({array_column}_value, 1,0,1)"], query=f"histogram({array_column}_value, 1,0,1):>0", + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2965,6 +3055,7 @@ def test_access_to_private_functions(self): discover.query( selected_columns=["count()"], query=f"histogram({array_column}_value, 1,0,1):>0", + params={}, snuba_params=SnubaParams( projects=[self.project], start=self.two_min_ago, @@ -2987,6 +3078,7 @@ def test_sum_array_combinator(self): results = discover.query( selected_columns=["sumArray(measurements_value)"], query="", + params={}, snuba_params=self.params, # make sure to opt in to gain access to the function functions_acl=["sumArray"], @@ -3003,6 +3095,7 @@ def test_any_function(self): results = discover.query( selected_columns=["count()", "any(transaction)", "any(user.id)"], query="event.type:transaction", + params={}, snuba_params=SnubaParams( projects=[self.project], start=before_now(minutes=5), @@ -3031,6 +3124,7 @@ def test_offsets(self): result = discover.query( selected_columns=["message"], query="", + params={}, snuba_params=self.params, orderby=["message"], limit=1, @@ -3051,6 +3145,7 @@ def test_reflective_types(self): "p50(spans.foo)", ], query="event.type:transaction", + params={}, snuba_params=self.params, use_aggregate_conditions=True, referrer="discover", @@ -3076,6 +3171,7 @@ def test_measurements(self): "measurements.does_not_exist", ], query="event.type:transaction", + params={}, snuba_params=self.params, referrer="discover", ) @@ -3103,6 +3199,7 @@ def test_span_op_breakdowns(self): "spans.does_not_exist", ], query="event.type:transaction", + params={}, snuba_params=self.params, referrer="discover", ) @@ -3126,6 +3223,7 @@ def test_project_in_condition_with_or(self): result = discover.query( selected_columns=["project"], query=f"project:{self.project.slug} or event.type:transaction", + params={}, snuba_params=SnubaParams( projects=[self.project, project2], start=self.two_min_ago, @@ -3167,6 +3265,7 @@ def test_simple(self): ], equations=["spans.http / transaction.duration"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3186,6 +3285,7 @@ def test_multiple_equations(self): "1500 + transaction.duration", ], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3205,6 +3305,7 @@ def test_invalid_field(self): # while transaction_status is a uint8, there's no reason we should allow arith on it equations=["spans.http / transaction.status"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3218,6 +3319,7 @@ def test_invalid_function(self): ], equations=["p50(transaction.duration) / last_seen()"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3230,6 +3332,7 @@ def test_unselected_field(self): ], equations=["spans.http / transaction.duration"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3242,6 +3345,7 @@ def test_unselected_function(self): ], equations=["p50(transaction.duration) / p100(transaction.duration)"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3266,6 +3370,7 @@ def test_orderby_equation(self): ], orderby=["equation[0]"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3284,6 +3389,7 @@ def test_orderby_equation(self): ], orderby=["equation[1]"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3302,6 +3408,7 @@ def test_orderby_equation(self): ], orderby=["-equation[0]"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3317,6 +3424,7 @@ def test_orderby_nonexistent_equation(self): ], orderby=["equation[1]"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3332,6 +3440,7 @@ def test_equation_without_field_or_function(self): "5 + 5", ], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3343,6 +3452,7 @@ def test_aggregate_equation(self): ], equations=["p50(transaction.duration) / 2"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3358,6 +3468,7 @@ def test_multiple_aggregate_equation(self): ], equations=["p50(transaction.duration) + 2", "p50(transaction.duration) / count()"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3379,6 +3490,7 @@ def test_multiple_operators(self): "count() + count() / count() * count() - count()", ], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3415,6 +3527,7 @@ def test_nan_equation_results(self): ], orderby=["equation[0]"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3432,6 +3545,7 @@ def test_nan_equation_results(self): ], orderby=["equation[1]"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) @@ -3449,6 +3563,7 @@ def test_nan_equation_results(self): ], orderby=["-equation[0]"], query=self.query, + params={}, snuba_params=self.params, referrer="discover", ) diff --git a/tests/sentry/snuba/test_discover_timeseries_query.py b/tests/sentry/snuba/test_discover_timeseries_query.py index 0f1ed24abd7db4..3a4c45993cf270 100644 --- a/tests/sentry/snuba/test_discover_timeseries_query.py +++ b/tests/sentry/snuba/test_discover_timeseries_query.py @@ -5,7 +5,7 @@ from sentry.exceptions import InvalidSearchQuery from sentry.models.transaction_threshold import ProjectTransactionThreshold, TransactionMetric -from sentry.search.events.types import EventsResponse, SnubaParams +from sentry.search.events.types import EventsResponse from sentry.snuba import discover from sentry.snuba.dataset import Dataset from sentry.testutils.cases import SnubaTestCase, TestCase @@ -62,11 +62,11 @@ def test_invalid_field_in_function(self): selected_columns=["min(transaction)"], query="transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=1800, ) @@ -76,7 +76,7 @@ def test_missing_start_and_end(self): selected_columns=["count()"], query="transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams(projects=[self.project]), + params={"project_id": [self.project.id]}, rollup=1800, ) @@ -86,11 +86,11 @@ def test_no_aggregations(self): selected_columns=["transaction", "title"], query="transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=1800, ) @@ -99,9 +99,11 @@ def test_field_alias(self): selected_columns=["p95()"], query="event.type:transaction transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=2), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -111,9 +113,11 @@ def test_failure_rate_field_alias(self): selected_columns=["failure_rate()"], query="event.type:transaction transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=2), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -123,9 +127,11 @@ def test_aggregate_function(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=2), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -135,9 +141,11 @@ def test_aggregate_function(self): selected_columns=["count_unique(user)"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=2), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -155,11 +163,11 @@ def test_comparison_aggregate_function_invalid(self): selected_columns=["count()", "count_unique(user)"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, comparison_delta=timedelta(days=1), ) @@ -177,9 +185,11 @@ def test_comparison_aggregate_function(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=2), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, comparison_delta=timedelta(days=1), ) @@ -214,11 +224,11 @@ def test_comparison_aggregate_function(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2, minutes=1), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2, minutes=1), + "project_id": [self.project.id], + }, rollup=3600, comparison_delta=timedelta(days=1), ) @@ -232,11 +242,11 @@ def test_comparison_aggregate_function(self): result = discover.timeseries_query( selected_columns=["count_unique(user)"], query="", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2, minutes=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2, minutes=2), + "project_id": [self.project.id], + }, rollup=3600, referrer="test_discover_query", comparison_delta=timedelta(days=1), @@ -275,12 +285,12 @@ def test_count_miserable(self): selected_columns=["count_miserable(user)"], referrer="test_discover_query", query="", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - organization=self.organization, - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id, project2.id], + "organization_id": self.organization.id, + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -316,12 +326,12 @@ def test_count_miserable_with_arithmetic(self): selected_columns=["equation|count_miserable(user) - 100"], referrer="test_discover_query", query="", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project, project2], - organization=self.organization, - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id, project2.id], + "organization_id": self.organization.id, + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -334,9 +344,11 @@ def test_equation_function(self): selected_columns=["equation|count() / 100"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=2), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -345,9 +357,11 @@ def test_equation_function(self): result = discover.timeseries_query( selected_columns=["equation|count_unique(user) / 100"], query="", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=2), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, referrer="test_discover_query", ) @@ -363,9 +377,11 @@ def test_zerofilling(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, end=self.day_ago + timedelta(hours=3), projects=[self.project] - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=3), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 4, "Should have empty results" @@ -389,11 +405,11 @@ def test_conditional_filter(self): result = discover.timeseries_query( selected_columns=["count()"], query=f"project:{self.project.slug} OR project:{project2.slug}", - snuba_params=SnubaParams( - start=before_now(minutes=5), - end=before_now(seconds=1), - projects=[self.project, project2, project3], - ), + params={ + "start": before_now(minutes=5), + "end": before_now(seconds=1), + "project_id": [self.project.id, project2.id, project3.id], + }, rollup=3600, referrer="test_discover_query", ) @@ -428,11 +444,11 @@ def test_nested_conditional_filter(self): query="(release:{} OR release:{}) AND project:{}".format( "a" * 32, "b" * 32, self.project.slug ), - snuba_params=SnubaParams( - start=before_now(minutes=5), - end=before_now(seconds=1), - projects=[self.project, project2], - ), + params={ + "start": before_now(minutes=5), + "end": before_now(seconds=1), + "project_id": [self.project.id, project2.id], + }, rollup=3600, referrer="test_discover_query", ) @@ -464,7 +480,11 @@ def test_project_filter_adjusts_filter(self, mock_query): end = before_now(seconds=1) discover.top_events_timeseries( selected_columns=["project", "count()"], - snuba_params=SnubaParams(start=start, end=end, projects=[self.project, project2]), + params={ + "start": start, + "end": end, + "project_id": [self.project.id, project2.id], + }, rollup=3600, top_events=top_events, timeseries_columns=["count()"], @@ -524,7 +544,11 @@ def test_timestamp_fields(self, mock_query): end = before_now(minutes=1) discover.top_events_timeseries( selected_columns=["timestamp", "timestamp.to_day", "timestamp.to_hour", "count()"], - snuba_params=SnubaParams(start=start, end=end, projects=[self.project]), + params={ + "start": start, + "end": end, + "project_id": [self.project.id], + }, rollup=3600, top_events=top_events, timeseries_columns=["count()"], @@ -584,7 +608,7 @@ def test_equation_fields_are_auto_added(self, mock_query): discover.top_events_timeseries( selected_columns=["count()"], equations=["equation|count_unique(user) * 2"], - snuba_params=SnubaParams(start=start, end=end, projects=[self.project]), + params={"start": start, "end": end, "project_id": [self.project.id]}, rollup=3600, timeseries_columns=[], user_query="", @@ -596,7 +620,7 @@ def test_equation_fields_are_auto_added(self, mock_query): mock_query.assert_called_with( ["count()"], query="", - snuba_params=SnubaParams(start=start, end=end, projects=[self.project]), + params={"start": start, "end": end, "project_id": [self.project.id]}, equations=["equation|count_unique(user) * 2"], orderby=["equation[0]"], referrer=None, diff --git a/tests/sentry/snuba/test_errors.py b/tests/sentry/snuba/test_errors.py index 113d076fbf6175..3fa9945c8794e9 100644 --- a/tests/sentry/snuba/test_errors.py +++ b/tests/sentry/snuba/test_errors.py @@ -13,7 +13,7 @@ SEMVER_BUILD_ALIAS, SEMVER_PACKAGE_ALIAS, ) -from sentry.search.events.types import SnubaParams +from sentry.search.events.types import ParamsType from sentry.snuba import errors from sentry.testutils.cases import SnubaTestCase, TestCase from sentry.testutils.helpers.datetime import before_now, iso_format @@ -55,18 +55,18 @@ def setUp(self): data["tags"] = [["key1", "value1"]] self.store_event(data=data, project_id=self.project.id) - self.snuba_params = SnubaParams( - organization=self.organization, - projects=[self.project], - start=before_now(days=1), - end=self.now, - ) + self.params = { + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(days=1), + "end": self.now, + } def test_errors_query(self): result = errors.query( selected_columns=["transaction"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_errors_query", ) data = result["data"] @@ -75,7 +75,7 @@ def test_errors_query(self): def test_project_mapping(self): other_project = self.create_project(organization=self.organization) - self.snuba_params.projects = [other_project] + self.params["project_id"] = [other_project.id] self.store_event( data={"message": "hello", "timestamp": iso_format(self.one_min_ago)}, project_id=other_project.id, @@ -84,7 +84,7 @@ def test_project_mapping(self): result = errors.query( selected_columns=["project", "message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["project"], referrer="errors", ) @@ -106,7 +106,7 @@ def test_issue_short_id_mapping(self): selected_columns=[column], query=query, referrer="errors", - snuba_params=self.snuba_params, + params=self.params, ) data = result["data"] assert len(data) == 1 @@ -126,7 +126,7 @@ def test_issue_filters(self): result = errors.query( selected_columns=["issue", "issue.id"], query=query, - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) data = result["data"] @@ -160,7 +160,7 @@ def test_tags_orderby(self): result = errors.query( selected_columns=[column], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=[orderby], referrer="test_discover_query", ) @@ -208,7 +208,7 @@ def test_tags_filter(self): result = errors.query( selected_columns=[column], query=query, - snuba_params=self.snuba_params, + params=self.params, orderby=[column], referrer="test_discover_query", ) @@ -241,7 +241,7 @@ def test_tags_colliding_with_fields(self): result = errors.query( selected_columns=[column], query=query, - snuba_params=self.snuba_params, + params=self.params, orderby=[column], referrer="test_discover_query", ) @@ -273,7 +273,7 @@ def test_reverse_sorting_issue(self): result = errors.query( selected_columns=[column], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=[f"{direction}{column}"], referrer="errors", ) @@ -288,7 +288,7 @@ def test_timestamp_rounding_fields(self): result = errors.query( selected_columns=["timestamp.to_hour", "timestamp.to_day"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -303,7 +303,7 @@ def test_timestamp_rounding_filters(self): one_day_ago = before_now(days=1) two_day_ago = before_now(days=2) three_day_ago = before_now(days=3) - self.snuba_params.start = three_day_ago + self.params["start"] = three_day_ago self.store_event( data={ @@ -320,7 +320,7 @@ def test_timestamp_rounding_filters(self): result = errors.query( selected_columns=["timestamp.to_hour", "timestamp.to_day"], query=f"timestamp.to_hour:<{iso_format(one_day_ago)} timestamp.to_day:<{iso_format(one_day_ago)}", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -374,7 +374,7 @@ def test_user_display(self): result = errors.query( selected_columns=["user.display"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -403,7 +403,7 @@ def test_user_display_filter(self): result = errors.query( selected_columns=["user.display"], query="has:user.display user.display:bruce@example.com", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -432,7 +432,7 @@ def test_message_orderby(self): result = errors.query( selected_columns=["message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=[orderby], referrer="test_discover_query", ) @@ -471,7 +471,7 @@ def test_message_filter(self): result = errors.query( selected_columns=["message"], query=query, - snuba_params=self.snuba_params, + params=self.params, orderby=["message"], referrer="test_discover_query", ) @@ -511,11 +511,11 @@ def test_to_other_function(self): selected_columns=cols, query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, referrer="test_discover_query", ) @@ -565,11 +565,11 @@ def test_count_if_function(self): result = errors.query( selected_columns=cols, query=query, - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, referrer="test_discover_query", ) @@ -611,11 +611,11 @@ def test_count_if_function_with_unicode(self): result = errors.query( selected_columns=cols, query=query, - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, referrer="test_discover_query", ) @@ -650,11 +650,11 @@ def test_last_seen(self): query=query, referrer="errors", orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, ) data = result["data"] @@ -680,11 +680,11 @@ def test_latest_event(self): query="", orderby=["transaction"], referrer="errors", - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=False, ) data = result["data"] @@ -726,11 +726,11 @@ def test_eps(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="errors", ) @@ -779,11 +779,11 @@ def test_epm(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="errors", ) @@ -826,12 +826,12 @@ def test_error_handled_alias(self): result = errors.query( selected_columns=["error.handled"], query=query, - snuba_params=SnubaParams( - organization=self.organization, - projects=[self.project], - start=before_now(minutes=12), - end=before_now(minutes=8), - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(minutes=12), + "end": before_now(minutes=8), + }, referrer="errors", ) @@ -869,12 +869,12 @@ def test_error_unhandled_alias(self): result = errors.query( selected_columns=["error.unhandled"], query=query, - snuba_params=SnubaParams( - organization=self.organization, - projects=[self.project], - start=before_now(minutes=12), - end=before_now(minutes=8), - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(minutes=12), + "end": before_now(minutes=8), + }, referrer="errors", ) data = result["data"] @@ -906,12 +906,12 @@ def test_array_fields(self): result = errors.query( selected_columns=["stack.filename"], query=query, - snuba_params=SnubaParams( - organization=self.organization, - projects=[self.project], - start=before_now(minutes=12), - end=before_now(minutes=8), - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(minutes=12), + "end": before_now(minutes=8), + }, referrer="errors", ) @@ -926,12 +926,12 @@ def test_array_fields(self): selected_columns=["stack.filename"], query="stack.filename:[raven.js]", referrer="errors", - snuba_params=SnubaParams( - organization=self.organization, - projects=[self.project], - start=before_now(minutes=12), - end=before_now(minutes=8), - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(minutes=12), + "end": before_now(minutes=8), + }, ) data = result["data"] @@ -966,12 +966,12 @@ def test_orderby_field_alias(self): selected_columns=["transaction", "error.unhandled"], query="", orderby=orderby, - snuba_params=SnubaParams( - organization=self.organization, - projects=[self.project], - start=before_now(minutes=12), - end=before_now(minutes=8), - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(minutes=12), + "end": before_now(minutes=8), + }, referrer="errors", ) @@ -1010,11 +1010,11 @@ def test_orderby_aggregate_function(self): selected_columns=["transaction", "count()"], query="", orderby=orderby, - snuba_params=SnubaParams( - projects=[project], - start=before_now(minutes=10), - end=before_now(minutes=2), - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, referrer="errors", ) data = result["data"] @@ -1024,7 +1024,7 @@ def test_field_aliasing_in_selected_columns(self): result = errors.query( selected_columns=["project.id", "user", "release", "timestamp.to_hour"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) data = result["data"] @@ -1048,7 +1048,7 @@ def test_field_alias_with_component(self): result = errors.query( selected_columns=["project.id", "user", "user.email"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) data = result["data"] @@ -1068,7 +1068,7 @@ def test_field_aliasing_in_aggregate_functions_and_groupby(self): result = errors.query( selected_columns=["project.id", "count_unique(user.email)"], query="", - snuba_params=self.snuba_params, + params=self.params, auto_fields=True, referrer="errors", ) @@ -1081,7 +1081,7 @@ def test_field_aliasing_in_conditions(self): result = errors.query( selected_columns=["project.id", "user.email"], query="user.email:bruce@example.com", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", auto_fields=True, ) @@ -1095,7 +1095,7 @@ def test_auto_fields_simple_fields(self): selected_columns=["user.email", "release"], referrer="errors", query="", - snuba_params=self.snuba_params, + params=self.params, auto_fields=True, ) data = result["data"] @@ -1118,7 +1118,7 @@ def test_auto_fields_aggregates(self): selected_columns=["count_unique(user.email)"], referrer="errors", query="", - snuba_params=self.snuba_params, + params=self.params, auto_fields=True, ) data = result["data"] @@ -1129,7 +1129,7 @@ def test_release_condition(self): result = errors.query( selected_columns=["id", "message"], query=f"release:{self.create_release(self.project).version}", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert len(result["data"]) == 0 @@ -1137,7 +1137,7 @@ def test_release_condition(self): result = errors.query( selected_columns=["id", "message"], query=f"release:{self.release.version}", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert len(result["data"]) == 1 @@ -1179,7 +1179,7 @@ def test_semver_condition(self): result = errors.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:>1.2.3", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1191,7 +1191,7 @@ def test_semver_condition(self): result = errors.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:>=1.2.3", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1205,14 +1205,14 @@ def test_semver_condition(self): result = errors.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:<1.2.4", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == {release_1_e_1, release_1_e_2} result = errors.query( selected_columns=["id"], query=f"!{SEMVER_ALIAS}:1.2.3", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1270,12 +1270,13 @@ def test_release_stage_condition(self): project_id=self.project.id, ).event_id - self.snuba_params.environments = [self.environment] + self.params["environment"] = [self.environment.name] + self.params["environment_objects"] = [self.environment] result = errors.query( selected_columns=["id"], query=f"{RELEASE_STAGE_ALIAS}:{ReleaseStages.ADOPTED.value}", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1286,7 +1287,7 @@ def test_release_stage_condition(self): result = errors.query( selected_columns=["id"], query=f"!{RELEASE_STAGE_ALIAS}:{ReleaseStages.LOW_ADOPTION.value}", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1298,7 +1299,7 @@ def test_release_stage_condition(self): result = errors.query( selected_columns=["id"], query=f"{RELEASE_STAGE_ALIAS}:[{ReleaseStages.ADOPTED.value}, {ReleaseStages.REPLACED.value}]", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1329,7 +1330,7 @@ def test_semver_package_condition(self): selected_columns=["id"], referrer="errors", query=f"{SEMVER_PACKAGE_ALIAS}:test", - snuba_params=self.snuba_params, + params=self.params, ) assert {r["id"] for r in result["data"]} == { release_1_e_1, @@ -1339,7 +1340,7 @@ def test_semver_package_condition(self): selected_columns=["id"], query=f"{SEMVER_PACKAGE_ALIAS}:test2", referrer="errors", - snuba_params=self.snuba_params, + params=self.params, ) assert {r["id"] for r in result["data"]} == { release_2_e_1, @@ -1365,7 +1366,7 @@ def test_semver_build_condition(self): result = errors.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:123", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1375,7 +1376,7 @@ def test_semver_build_condition(self): result = errors.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:124", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == { @@ -1384,7 +1385,7 @@ def test_semver_build_condition(self): result = errors.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:>=123", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert {r["id"] for r in result["data"]} == {release_1_e_1, release_1_e_2, release_2_e_1} @@ -1393,7 +1394,7 @@ def test_latest_release_condition(self): result = errors.query( selected_columns=["id", "message"], query="release:latest", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert len(result["data"]) == 1 @@ -1406,7 +1407,7 @@ def test_environment_condition(self): result = errors.query( selected_columns=["id", "message"], query=f"environment:{self.create_environment(self.project).name}", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert len(result["data"]) == 0 @@ -1414,7 +1415,7 @@ def test_environment_condition(self): result = errors.query( selected_columns=["id", "message"], query=f"environment:{self.environment.name}", - snuba_params=self.snuba_params, + params=self.params, referrer="errors", ) assert len(result["data"]) == 1 @@ -1438,11 +1439,11 @@ def test_conditional_filter(self): result = errors.query( selected_columns=["project", "message"], query=f"project:{self.project.slug} OR project:{project2.slug}", - snuba_params=SnubaParams( - projects=[self.project, project2], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id, project2.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["message"], referrer="errors", ) @@ -1476,11 +1477,11 @@ def test_nested_conditional_filter(self): query="(release:{} OR release:{}) AND project:{}".format( "a" * 32, "b" * 32, self.project.slug ), - snuba_params=SnubaParams( - projects=[self.project, project2], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id, project2.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["release"], referrer="discover", ) @@ -1502,11 +1503,11 @@ def test_conditions_with_special_columns(self): result = errors.query( selected_columns=["transaction", "message"], query="event.type:error (transaction:{}* OR message:{}*)".format("a" * 32, "b" * 32), - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["transaction"], referrer="discover", ) @@ -1521,11 +1522,11 @@ def test_conditions_with_special_columns(self): query="event.type:error (transaction:{} AND sub_customer.is-Enterprise-42:{})".format( "a" * 32, "a" * 32 ), - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["transaction"], referrer="discover", ) @@ -1552,11 +1553,11 @@ def test_conditions_with_nested_aggregates(self): query="(event.type:error AND (trek:{} AND (transaction:*{}* AND count():>2)))".format( "b" * 32, "b" * 32 ), - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["trek"], use_aggregate_conditions=True, referrer="discover", @@ -1574,11 +1575,11 @@ def test_conditions_with_nested_aggregates(self): "b" * 32, "b" * 32 ), referrer="discover", - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["trek"], use_aggregate_conditions=True, ) @@ -1599,11 +1600,11 @@ def test_conditions_with_timestamps(self): iso_format(self.now - timedelta(seconds=5)), iso_format(self.now - timedelta(seconds=3)), ), - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["transaction"], use_aggregate_conditions=True, referrer="discover", @@ -1621,7 +1622,7 @@ def test_timestamp_rollup_filter(self): result = errors.query( selected_columns=["project.id", "user", "release"], query="timestamp.to_hour:" + iso_format(event_hour), - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) data = result["data"] @@ -1645,7 +1646,7 @@ def test_count_with_or(self): results = errors.query( selected_columns=["transaction", "count()"], query="event.type:error AND (count():<1 OR count():>0)", - snuba_params=self.snuba_params, + params=self.params, orderby=["transaction"], use_aggregate_conditions=True, referrer="discover", @@ -1662,11 +1663,11 @@ def test_access_to_private_functions(self): errors.query( selected_columns=["array_join(tags.key)"], query="", - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, referrer="discover", ) @@ -1676,11 +1677,11 @@ def test_access_to_private_functions(self): errors.query( selected_columns=[f"histogram({array_column}_value, 1,0,1)"], query=f"histogram({array_column}_value, 1,0,1):>0", - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, use_aggregate_conditions=True, referrer="discover", ) @@ -1692,11 +1693,11 @@ def test_access_to_private_functions(self): errors.query( selected_columns=["count()"], query=f"histogram({array_column}_value, 1,0,1):>0", - snuba_params=SnubaParams( - projects=[self.project], - start=self.two_min_ago, - end=self.now, - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, referrer="discover", auto_aggregations=True, use_aggregate_conditions=True, @@ -1710,11 +1711,11 @@ def test_any_function(self): results = errors.query( selected_columns=["count()", "any(transaction)", "any(user.id)"], query="transaction:{}".format("a" * 32), - snuba_params=SnubaParams( - projects=[self.project], - start=before_now(minutes=5), - end=before_now(seconds=1), - ), + params={ + "start": before_now(minutes=5), + "end": before_now(seconds=1), + "project_id": [self.project.id], + }, referrer="discover", use_aggregate_conditions=True, ) @@ -1737,7 +1738,7 @@ def test_offsets(self): result = errors.query( selected_columns=["message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["message"], limit=1, offset=1, @@ -1759,11 +1760,11 @@ def setUp(self): event_data = load_data("javascript") event_data["timestamp"] = iso_format(self.day_ago + timedelta(minutes=30, seconds=3)) self.store_event(data=event_data, project_id=self.project.id) - self.snuba_params = SnubaParams( - projects=[self.project], - start=self.day_ago, - end=self.now, - ) + self.params: ParamsType = { + "project_id": [self.project.id], + "start": self.day_ago, + "end": self.now, + } self.query = "" def test_simple(self): @@ -1773,7 +1774,7 @@ def test_simple(self): ], equations=["count() + 100"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 1 diff --git a/tests/sentry/snuba/test_metrics_enhanced_performance.py b/tests/sentry/snuba/test_metrics_enhanced_performance.py index 5f8e1b7e8ad9b2..6f382054dde8be 100644 --- a/tests/sentry/snuba/test_metrics_enhanced_performance.py +++ b/tests/sentry/snuba/test_metrics_enhanced_performance.py @@ -5,7 +5,7 @@ import pytest from django.utils import timezone -from sentry.search.events.types import SnubaParams +from sentry.search.events.types import ParamsType from sentry.snuba import metrics_enhanced_performance from sentry.testutils.cases import MetricsEnhancedPerformanceTestCase, SnubaTestCase from sentry.testutils.helpers.datetime import before_now, freeze_time @@ -22,12 +22,12 @@ class MetricsEnhancedPerformanceTest(MetricsEnhancedPerformanceTestCase, SnubaTestCase): def setUp(self): super().setUp() - self.snuba_params = SnubaParams( - organization=self.organization.id, - projects=[self.project], - start=before_now(days=1), - end=self.now, - ) + self.params: ParamsType = { + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(days=1), + "end": self.now, + } @cached_property def now(self): @@ -60,7 +60,7 @@ def test_metrics_incompatible_query_redirects_to_transactions_when_flagged( # Equations are not compatible with metrics in MEP, forces a fallback equations=["measurements.datacenter_memory / 3"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_query", auto_fields=True, fallback_to_transactions=True, @@ -95,7 +95,7 @@ def test_metrics_incompatible_query_redirects_to_discover_when_not_flagged( # Equations are not compatible with metrics in MEP, forces a fallback equations=["measurements.datacenter_memory / 3"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_query", auto_fields=True, fallback_to_transactions=False, diff --git a/tests/sentry/snuba/test_metrics_performance.py b/tests/sentry/snuba/test_metrics_performance.py index a401c045e91ba0..af5199820a3cc2 100644 --- a/tests/sentry/snuba/test_metrics_performance.py +++ b/tests/sentry/snuba/test_metrics_performance.py @@ -4,7 +4,7 @@ import pytest from sentry.exceptions import IncompatibleMetricsQuery -from sentry.search.events.types import SnubaParams +from sentry.search.events.types import ParamsType from sentry.sentry_metrics import indexer from sentry.sentry_metrics.use_case_id_registry import UseCaseID from sentry.snuba.metrics_performance import timeseries_query @@ -26,13 +26,13 @@ def setUp(self): hour=10, minute=0, second=0, microsecond=0 ) self.default_interval = 3600 - self.projects = [self.project] - self.snuba_params = SnubaParams( - organization=self.organization, - projects=self.projects, - start=self.start, - end=self.end, - ) + self.projects = [self.project.id] + self.params: ParamsType = { + "organization_id": self.organization.id, + "project_id": self.projects, + "start": self.start, + "end": self.end, + } indexer.record( use_case_id=UseCaseID.TRANSACTIONS, org_id=self.organization.id, string="transaction" @@ -55,7 +55,7 @@ def test_timeseries_query(self): results = timeseries_query( selected_columns=["avg(transaction.duration)"], query="", - snuba_params=self.snuba_params, + params=self.params, rollup=self.default_interval, referrer="test_query", ) @@ -94,7 +94,7 @@ def test_timeseries_query_with_comparison(self): results = timeseries_query( selected_columns=["avg(transaction.duration)"], query="", - snuba_params=self.snuba_params, + params=self.params, rollup=self.default_interval, comparison_delta=datetime.timedelta(weeks=1), referrer="test_query", @@ -166,7 +166,7 @@ def test_timeseries_query_with_comparison_and_multiple_aggregates(self): timeseries_query( selected_columns=["avg(transaction.duration)", "sum(transaction.duration)"], query="", - snuba_params=self.snuba_params, + params=self.params, rollup=self.default_interval, comparison_delta=datetime.timedelta(weeks=1), referrer="test_query", diff --git a/tests/sentry/snuba/test_transactions.py b/tests/sentry/snuba/test_transactions.py index 833533bafadcb2..e692803367f9a9 100644 --- a/tests/sentry/snuba/test_transactions.py +++ b/tests/sentry/snuba/test_transactions.py @@ -21,7 +21,7 @@ SEMVER_BUILD_ALIAS, SEMVER_PACKAGE_ALIAS, ) -from sentry.search.events.types import SnubaParams +from sentry.search.events.types import ParamsType from sentry.snuba import discover, transactions from sentry.testutils.cases import SnubaTestCase, TestCase from sentry.testutils.helpers.datetime import before_now, iso_format @@ -54,18 +54,18 @@ def setUp(self): data["tags"] = [["key1", "value1"]] self.event = self.store_event(data=data, project_id=self.project.id) - self.snuba_params = SnubaParams( - organization=self.organization, - projects=[self.project], - start=before_now(days=1), - end=self.now, - ) + self.params: ParamsType = { + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(days=1), + "end": self.now, + } def test_transaction_query(self): result = transactions.query( selected_columns=["transaction"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_transactions_query", ) data = result["data"] @@ -76,11 +76,11 @@ def test_error_event_type_query(self): results = transactions.query( selected_columns=["count()", "any(transaction)", "any(user.id)"], query="event.type:error", - snuba_params=SnubaParams( - start=before_now(minutes=5), - end=before_now(seconds=1), - projects=[self.project], - ), + params={ + "start": before_now(minutes=5), + "end": before_now(seconds=1), + "project_id": [self.project.id], + }, referrer="discover", use_aggregate_conditions=True, ) @@ -92,11 +92,11 @@ def test_any_function(self): results = transactions.query( selected_columns=["count()", "any(transaction)", "any(user.id)"], query="event.type:transaction", - snuba_params=SnubaParams( - start=before_now(minutes=5), - end=before_now(seconds=1), - projects=[self.project], - ), + params={ + "start": before_now(minutes=5), + "end": before_now(seconds=1), + "project_id": [self.project.id], + }, referrer="discover", use_aggregate_conditions=True, ) @@ -112,7 +112,7 @@ def test_auto_fields_aggregates(self): selected_columns=["count_unique(user.email)"], referrer="discover", query="", - snuba_params=self.snuba_params, + params=self.params, auto_fields=True, ) data = result["data"] @@ -124,7 +124,7 @@ def test_auto_fields_simple_fields(self): selected_columns=["user.email", "release"], referrer="discover", query="", - snuba_params=self.snuba_params, + params=self.params, auto_fields=True, ) data = result["data"] @@ -157,11 +157,11 @@ def test_conditional_filter(self): result = transactions.query( selected_columns=["project", "transaction"], query=f"project:{self.project.slug} OR project:{project2.slug}", - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project, project2], - ), + params={ + "project_id": [self.project.id, project2.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["transaction"], referrer="discover", ) @@ -195,11 +195,11 @@ def test_nested_conditional_filter(self): query="(release:{} OR release:{}) AND project:{}".format( "a" * 32, "b" * 32, self.project.slug ), - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project, project2], - ), + params={ + "project_id": [self.project.id, project2.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["release"], referrer="discover", ) @@ -213,7 +213,7 @@ def test_environment_condition(self): result = transactions.query( selected_columns=["id", "message"], query=f"environment:{self.create_environment(self.project).name}", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(result["data"]) == 0 @@ -221,7 +221,7 @@ def test_environment_condition(self): result = transactions.query( selected_columns=["id", "message"], query=f"environment:{self.environment.name}", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(result["data"]) == 1 @@ -233,7 +233,7 @@ def test_field_alias_with_component(self): result = transactions.query( selected_columns=["project.id", "user", "user.email"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) data = result["data"] @@ -253,7 +253,7 @@ def test_field_aliasing_in_aggregate_functions_and_groupby(self): result = transactions.query( selected_columns=["project.id", "count_unique(user.email)"], query="", - snuba_params=self.snuba_params, + params=self.params, auto_fields=True, referrer="discover", ) @@ -266,7 +266,7 @@ def test_field_aliasing_in_conditions(self): result = transactions.query( selected_columns=["project.id", "user.email"], query="user.email:bruce@example.com", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", auto_fields=True, ) @@ -279,7 +279,7 @@ def test_field_aliasing_in_selected_columns(self): result = transactions.query( selected_columns=["project.id", "user", "release", "timestamp.to_hour"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) data = result["data"] @@ -303,7 +303,7 @@ def test_latest_release_condition(self): result = transactions.query( selected_columns=["id", "message"], query="release:latest", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(result["data"]) == 1 @@ -338,7 +338,7 @@ def test_message_filter(self): result = transactions.query( selected_columns=["message"], query=query, - snuba_params=self.snuba_params, + params=self.params, orderby=["message"], referrer="test_discover_query", ) @@ -351,7 +351,7 @@ def test_release_condition(self): result = transactions.query( selected_columns=["id", "message"], query=f"release:{self.create_release(self.project).version}", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(result["data"]) == 0 @@ -359,7 +359,7 @@ def test_release_condition(self): result = transactions.query( selected_columns=["id", "message"], query=f"release:{self.release.version}", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(result["data"]) == 1 @@ -400,7 +400,7 @@ def test_semver_condition(self): result = transactions.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:>1.2.3", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -412,7 +412,7 @@ def test_semver_condition(self): result = transactions.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:>=1.2.3", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -426,14 +426,14 @@ def test_semver_condition(self): result = transactions.query( selected_columns=["id"], query=f"{SEMVER_ALIAS}:<1.2.4", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == {release_1_e_1, release_1_e_2} result = transactions.query( selected_columns=["id"], query=f"!{SEMVER_ALIAS}:1.2.3", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -478,12 +478,13 @@ def test_release_stage_condition(self): data["environment"] = self.environment.name replaced_release_e_2 = self.store_event(data, project_id=self.project.id).event_id - self.snuba_params.environments = [self.environment] + self.params["environment"] = [self.environment.name] + self.params["environment_objects"] = [self.environment] result = transactions.query( selected_columns=["id"], query=f"{RELEASE_STAGE_ALIAS}:{ReleaseStages.ADOPTED.value}", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -494,7 +495,7 @@ def test_release_stage_condition(self): result = transactions.query( selected_columns=["id"], query=f"!{RELEASE_STAGE_ALIAS}:{ReleaseStages.LOW_ADOPTION.value}", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -506,7 +507,7 @@ def test_release_stage_condition(self): result = transactions.query( selected_columns=["id"], query=f"{RELEASE_STAGE_ALIAS}:[{ReleaseStages.ADOPTED.value}, {ReleaseStages.REPLACED.value}]", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -539,7 +540,7 @@ def test_semver_package_condition(self): selected_columns=["id"], referrer="discover", query=f"{SEMVER_PACKAGE_ALIAS}:test", - snuba_params=self.snuba_params, + params=self.params, ) assert {r["id"] for r in result["data"]} == { release_1_e_1, @@ -549,7 +550,7 @@ def test_semver_package_condition(self): selected_columns=["id"], query=f"{SEMVER_PACKAGE_ALIAS}:test2", referrer="discover", - snuba_params=self.snuba_params, + params=self.params, ) assert {r["id"] for r in result["data"]} == { release_2_e_1, @@ -577,7 +578,7 @@ def test_semver_build_condition(self): result = transactions.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:123", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -587,7 +588,7 @@ def test_semver_build_condition(self): result = transactions.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:124", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == { @@ -596,7 +597,7 @@ def test_semver_build_condition(self): result = transactions.query( selected_columns=["id"], query=f"{SEMVER_BUILD_ALIAS}:>=123", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert {r["id"] for r in result["data"]} == {release_1_e_1, release_1_e_2, release_2_e_1} @@ -626,7 +627,7 @@ def test_message_orderby(self): result = transactions.query( selected_columns=["message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=[orderby], referrer="test_discover_query", ) @@ -636,16 +637,16 @@ def test_message_orderby(self): assert [item["message"] for item in data] == expected def test_missing_project(self): - projects = [] + project_ids = [] other_project = None for project_name in ["a" * 32, "z" * 32, "m" * 32]: other_project = self.create_project(organization=self.organization, slug=project_name) - projects.append(other_project) + project_ids.append(other_project.id) data = load_data("transaction", timestamp=before_now(seconds=3)) data["transaction"] = "ohh no" self.event = self.store_event(data, project_id=other_project.id) - self.snuba_params.projects = projects + self.params["project_id"] = project_ids # delete the last project so its missing if other_project is not None: @@ -654,7 +655,7 @@ def test_missing_project(self): result = transactions.query( selected_columns=["message", "project"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["project"], referrer="test_discover_query", ) @@ -674,7 +675,7 @@ def test_offsets(self): result = transactions.query( selected_columns=["message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["message"], limit=1, offset=2, @@ -712,12 +713,12 @@ def test_orderby_field_alias(self): selected_columns=["transaction", "transaction.status"], query="", orderby=[orderby], - snuba_params=SnubaParams( - start=before_now(minutes=12), - end=before_now(minutes=8), - projects=[self.project], - organization=self.organization, - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(minutes=12), + "end": before_now(minutes=8), + }, referrer="discover", ) @@ -743,7 +744,7 @@ def test_transaction_status(self): result = transactions.query( selected_columns=["transaction.status"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) data = result["data"] @@ -764,12 +765,12 @@ def test_project_in_condition_with_or(self): result = transactions.query( selected_columns=["project"], query=f"project:{self.project.slug} or event.type:transaction", - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project, project2], - organization=self.organization, - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id, project2.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["project"], referrer="discover", ) @@ -779,7 +780,7 @@ def test_project_in_condition_with_or(self): def test_project_mapping(self): other_project = self.create_project(organization=self.organization) - self.snuba_params.projects = [other_project] + self.params["project_id"] = [other_project.id] data = load_data("transaction", timestamp=before_now(minutes=1)) data["transaction"] = "hello" @@ -788,7 +789,7 @@ def test_project_mapping(self): result = transactions.query( selected_columns=["project", "message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["project"], referrer="discover", ) @@ -798,19 +799,19 @@ def test_project_mapping(self): assert data[0]["project"] == other_project.slug def test_sorting_and_reverse_sorting_project_name(self): - projects = [] + project_ids = [] for project_name in ["a" * 32, "z" * 32, "m" * 32]: other_project = self.create_project(organization=self.organization, slug=project_name) - projects.append(other_project) + project_ids.append(other_project.id) data = load_data("transaction", timestamp=before_now(minutes=1)) self.store_event(data, project_id=other_project.id) - self.snuba_params.projects = projects + self.params["project_id"] = project_ids result = transactions.query( selected_columns=["project", "message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["-project"], referrer="test_discover_query", ) @@ -821,7 +822,7 @@ def test_sorting_and_reverse_sorting_project_name(self): result = transactions.query( selected_columns=["project", "message"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["project"], referrer="test_discover_query", ) @@ -845,7 +846,7 @@ def test_tags_colliding_with_fields(self): result = transactions.query( selected_columns=[column], query=query, - snuba_params=self.snuba_params, + params=self.params, orderby=[column], referrer="test_discover_query", ) @@ -869,7 +870,7 @@ def test_tags_orderby(self): result = transactions.query( selected_columns=[column], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=[orderby], referrer="test_discover_query", ) @@ -908,7 +909,7 @@ def test_tags_filter(self): result = transactions.query( selected_columns=[column], query=query, - snuba_params=self.snuba_params, + params=self.params, orderby=[column], referrer="test_discover_query", ) @@ -962,13 +963,13 @@ def test_team_key_transactions(self): result = transactions.query( selected_columns=["transaction", "team_key_transaction"], query=query, - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[self.project], - organization=self.organization, - teams=[team1, team2], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [self.project.id], + "organization_id": self.organization.id, + "team_id": [team1.id, team2.id], + }, referrer="test_discover_query", ) @@ -983,7 +984,7 @@ def test_timestamp_rounding_fields(self): result = transactions.query( selected_columns=["timestamp.to_hour", "timestamp.to_day"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -998,7 +999,7 @@ def test_timestamp_rounding_filters(self): one_day_ago = before_now(days=1) two_day_ago = before_now(days=2) three_day_ago = before_now(days=3) - self.snuba_params.start = three_day_ago + self.params["start"] = three_day_ago data = load_data("transaction", timestamp=two_day_ago) self.store_event(data, project_id=self.project.id) @@ -1006,7 +1007,7 @@ def test_timestamp_rounding_filters(self): result = transactions.query( selected_columns=["timestamp.to_hour", "timestamp.to_day"], query=f"timestamp.to_hour:<{iso_format(one_day_ago)} timestamp.to_day:<{iso_format(one_day_ago)}", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -1039,7 +1040,7 @@ def test_user_display(self): result = transactions.query( selected_columns=["user.display"], query="", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -1061,7 +1062,7 @@ def test_user_display_filter(self): result = transactions.query( selected_columns=["user.display"], query="has:user.display user.display:bruce@example.com", - snuba_params=self.snuba_params, + params=self.params, referrer="test_discover_query", ) data = result["data"] @@ -1069,19 +1070,19 @@ def test_user_display_filter(self): assert [item["user.display"] for item in data] == ["bruce@example.com"] def test_using_project_and_project_name(self): - projects = [] + project_ids = [] for project_name in ["a" * 32, "z" * 32, "m" * 32]: other_project = self.create_project(organization=self.organization, slug=project_name) - projects.append(other_project) + project_ids.append(other_project.id) data = load_data("transaction", timestamp=self.event_time) self.store_event(data=data, project_id=other_project.id) - self.snuba_params.projects = projects + self.params["project_id"] = project_ids result = transactions.query( selected_columns=["project.name", "message", "project"], query="", - snuba_params=self.snuba_params, + params=self.params, orderby=["project.name"], referrer="test_discover_query", ) @@ -1153,12 +1154,12 @@ def test_snql_wip_project_threshold_config(self): result = transactions.query( selected_columns=["project", "transaction", "project_threshold_config"], query="", - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[self.project, project2], - organization=self.organization, - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [self.project.id, project2.id], + "organization_id": self.organization.id, + }, referrer="test_discover_query", ) @@ -1184,12 +1185,12 @@ def test_snql_wip_project_threshold_config(self): result = transactions.query( selected_columns=["project", "transaction", "project_threshold_config"], query="", - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project2], - organization=self.organization, - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project2.id], + "organization_id": self.organization.id, + }, referrer="test_discover_query", ) @@ -1236,11 +1237,11 @@ def test_to_other_function(self): selected_columns=cols, query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, referrer="test_discover_query", ) @@ -1290,11 +1291,11 @@ def test_count_if_function(self): result = transactions.query( selected_columns=cols, query=query, - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, referrer="test_discover_query", ) @@ -1336,11 +1337,11 @@ def test_count_if_function_with_unicode(self): result = transactions.query( selected_columns=cols, query=query, - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, referrer="test_discover_query", ) @@ -1382,11 +1383,11 @@ def test_failure_count_function(self): selected_columns=["transaction", "failure_count()"], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -1457,12 +1458,12 @@ def test_apdex_function(self): query=query, orderby=["transaction"], referrer="discover", - snuba_params=SnubaParams( - start=before_now(minutes=30), - end=before_now(minutes=2), - projects=[project, project2], - organization=self.organization, - ), + params={ + "start": before_now(minutes=30), + "end": before_now(minutes=2), + "project_id": [project.id, project2.id], + "organization_id": self.organization.id, + }, use_aggregate_conditions=True, ) data = result["data"] @@ -1547,12 +1548,12 @@ def test_count_miserable_function(self): query=query, orderby=["transaction"], referrer="discover", - snuba_params=SnubaParams( - start=before_now(minutes=30), - end=before_now(minutes=2), - projects=[project, project2], - organization=self.organization, - ), + params={ + "start": before_now(minutes=30), + "end": before_now(minutes=2), + "project_id": [project.id, project2.id], + "organization_id": self.organization.id, + }, use_aggregate_conditions=True, ) @@ -1640,12 +1641,12 @@ def test_user_misery_function(self): referrer="discover", query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=30), - end=before_now(minutes=2), - projects=[project, project2], - organization=self.organization, - ), + params={ + "start": before_now(minutes=30), + "end": before_now(minutes=2), + "project_id": [project.id, project2.id], + "organization_id": self.organization.id, + }, use_aggregate_conditions=True, ) @@ -1677,11 +1678,11 @@ def test_count(self): selected_columns=["transaction", "count()"], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, referrer="discover", use_aggregate_conditions=use_aggregate_conditions, ) @@ -1734,11 +1735,11 @@ def test_compare_numeric_aggregate_function(self): selected_columns=selected, query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=True, ) alias, expected_value = expected_results[i] @@ -1773,11 +1774,11 @@ def test_last_seen(self): query=query, referrer="discover", orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, ) data = result["data"] @@ -1803,11 +1804,11 @@ def test_latest_event(self): query="", orderby=["transaction"], referrer="discover", - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=False, ) data = result["data"] @@ -1848,11 +1849,11 @@ def test_failure_rate(self): selected_columns=["transaction", "failure_rate()"], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -1897,11 +1898,11 @@ def test_percentile(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=20), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, ) data = result["data"] @@ -1932,11 +1933,11 @@ def test_p50(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=20), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=20), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, ) data = result["data"] @@ -1965,11 +1966,11 @@ def test_p75(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=20), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=20), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -1999,11 +2000,11 @@ def test_p95(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=20), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=20), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -2033,11 +2034,11 @@ def test_p99(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=20), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=20), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -2067,11 +2068,11 @@ def test_p100(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=20), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=20), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -2110,11 +2111,11 @@ def test_p100_with_measurement(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=20), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=20), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -2137,11 +2138,11 @@ def test_count_unique(self): result = transactions.query( selected_columns=["count_unique(user.display)", "count_unique(foo)"], query="", - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, use_aggregate_conditions=True, referrer="discover", ) @@ -2169,11 +2170,11 @@ def test_min_max(self): "max(transaction.duration)", ], query="", - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, use_aggregate_conditions=True, referrer="discover", ) @@ -2214,11 +2215,11 @@ def test_stats_functions(self): result = transactions.query( selected_columns=[column], query="", - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, use_aggregate_conditions=True, referrer="discover", ) @@ -2245,11 +2246,11 @@ def test_count_at_least(self): "count_at_least(transaction.duration,120000)", ], query="", - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[self.project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [self.project.id], + }, use_aggregate_conditions=True, referrer="discover", ) @@ -2293,11 +2294,11 @@ def test_eps(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -2346,11 +2347,11 @@ def test_epm(self): ], query=query, orderby=["transaction"], - snuba_params=SnubaParams( - start=before_now(minutes=4), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=4), + "end": before_now(minutes=2), + "project_id": [project.id], + }, use_aggregate_conditions=use_aggregate_conditions, referrer="discover", ) @@ -2381,7 +2382,7 @@ def run_query(query, expected_statuses, message): result = transactions.query( selected_columns=["transaction.status"], query=query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) data = result["data"] @@ -2446,11 +2447,11 @@ def test_orderby_aggregate_function(self): selected_columns=["transaction", "failure_count()"], query="", orderby=[orderby], - snuba_params=SnubaParams( - start=before_now(minutes=10), - end=before_now(minutes=2), - projects=[project], - ), + params={ + "start": before_now(minutes=10), + "end": before_now(minutes=2), + "project_id": [project.id], + }, referrer="discover", ) data = result["data"] @@ -2483,12 +2484,12 @@ def test_spans_op_array_field(self): result = discover.query( selected_columns=["spans_op"], query=query, - snuba_params=SnubaParams( - start=before_now(minutes=12), - end=before_now(minutes=8), - projects=[self.project], - organization=self.organization, - ), + params={ + "organization_id": self.organization.id, + "project_id": [self.project.id], + "start": before_now(minutes=12), + "end": before_now(minutes=8), + }, referrer="discover", ) data = result["data"] @@ -2502,7 +2503,7 @@ def test_reflective_types(self): "p50(spans.foo)", ], query="event.type:transaction", - snuba_params=self.snuba_params, + params=self.params, use_aggregate_conditions=True, referrer="discover", ) @@ -2527,7 +2528,7 @@ def test_measurements(self): "measurements.does_not_exist", ], query="event.type:transaction !transaction:{}".format("a" * 32), - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -2552,11 +2553,11 @@ def test_conditions_with_special_columns(self): result = transactions.query( selected_columns=["title", "message"], query="event.type:transaction (title:{} OR message:{})".format("b" * 32, "c" * 32), - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["title"], referrer="discover", ) @@ -2571,11 +2572,11 @@ def test_conditions_with_special_columns(self): query="event.type:transaction (title:{} AND sub_customer.is-Enterprise-42:{})".format( "b" * 32, "b" * 32 ), - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["title"], referrer="discover", ) @@ -2602,11 +2603,11 @@ def test_conditions_with_aggregates(self): query="event.type:transaction (trek:{} OR trek:{}) AND count():>2".format( "a" * 32, "b" * 32 ), - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["trek"], use_aggregate_conditions=True, referrer="discover", @@ -2634,11 +2635,11 @@ def test_conditions_with_nested_aggregates(self): query="(event.type:transaction AND (trek:{} AND (transaction:*{}* AND count():>2)))".format( "b" * 32, "b" * 32 ), - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["trek"], use_aggregate_conditions=True, referrer="discover", @@ -2656,11 +2657,11 @@ def test_conditions_with_nested_aggregates(self): "b" * 32, "b" * 32 ), referrer="discover", - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["trek"], use_aggregate_conditions=True, ) @@ -2681,11 +2682,11 @@ def test_conditions_with_timestamps(self): iso_format(self.now - timedelta(seconds=5)), iso_format(self.now - timedelta(seconds=3)), ), - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, orderby=["transaction"], use_aggregate_conditions=True, referrer="discover", @@ -2705,7 +2706,7 @@ def test_timestamp_rollup_filter(self): result = transactions.query( selected_columns=["project.id", "user", "release"], query="timestamp.to_hour:" + iso_format(event_hour), - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) data = result["data"] @@ -2729,7 +2730,7 @@ def test_count_with_or(self): results = transactions.query( selected_columns=["transaction", "count()"], query="event.type:transaction AND (count():<1 OR count():>0)", - snuba_params=self.snuba_params, + params=self.params, orderby=["transaction"], use_aggregate_conditions=True, referrer="discover", @@ -2753,7 +2754,7 @@ def test_array_join(self): results = transactions.query( selected_columns=["array_join(measurements_key)"], query="transaction:foo", - snuba_params=self.snuba_params, + params=self.params, functions_acl=["array_join"], referrer="discover", ) @@ -2767,11 +2768,11 @@ def test_access_to_private_functions(self): transactions.query( selected_columns=["array_join(tags.key)"], query="", - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, referrer="discover", ) @@ -2781,11 +2782,11 @@ def test_access_to_private_functions(self): transactions.query( selected_columns=[f"histogram({array_column}_value, 1,0,1)"], query=f"histogram({array_column}_value, 1,0,1):>0", - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, use_aggregate_conditions=True, referrer="discover", ) @@ -2797,11 +2798,11 @@ def test_access_to_private_functions(self): transactions.query( selected_columns=["count()"], query=f"histogram({array_column}_value, 1,0,1):>0", - snuba_params=SnubaParams( - start=self.two_min_ago, - end=self.now, - projects=[self.project], - ), + params={ + "project_id": [self.project.id], + "start": self.two_min_ago, + "end": self.now, + }, referrer="discover", auto_aggregations=True, use_aggregate_conditions=True, @@ -2819,7 +2820,7 @@ def test_sum_array_combinator(self): results = transactions.query( selected_columns=["sumArray(measurements_value)"], query="!transaction:{}".format("a" * 32), - snuba_params=self.snuba_params, + params=self.params, # make sure to opt in to gain access to the function functions_acl=["sumArray"], referrer="discover", @@ -2841,7 +2842,7 @@ def test_span_op_breakdowns(self): "spans.does_not_exist", ], query="event.type:transaction !transaction:{}".format("a" * 32), - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -2868,11 +2869,11 @@ def setUp(self): event_data["start_timestamp"] = iso_format(self.day_ago + timedelta(minutes=30)) event_data["timestamp"] = iso_format(self.day_ago + timedelta(minutes=30, seconds=3)) self.store_event(data=event_data, project_id=self.project.id) - self.snuba_params = SnubaParams( - projects=[self.project], - start=self.day_ago, - end=self.now, - ) + self.params: ParamsType = { + "project_id": [self.project.id], + "start": self.day_ago, + "end": self.now, + } self.query = "event.type:transaction" def test_simple(self): @@ -2883,7 +2884,7 @@ def test_simple(self): ], equations=["spans.http / transaction.duration"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 1 @@ -2902,7 +2903,7 @@ def test_multiple_equations(self): "1500 + transaction.duration", ], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 1 @@ -2921,7 +2922,7 @@ def test_invalid_field(self): # while transaction_status is a uint8, there's no reason we should allow arith on it equations=["spans.http / transaction.status"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -2934,7 +2935,7 @@ def test_invalid_function(self): ], equations=["p50(transaction.duration) / last_seen()"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -2946,7 +2947,7 @@ def test_unselected_field(self): ], equations=["spans.http / transaction.duration"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -2958,7 +2959,7 @@ def test_unselected_function(self): ], equations=["p50(transaction.duration) / p100(transaction.duration)"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -2982,7 +2983,7 @@ def test_orderby_equation(self): ], orderby=["equation[0]"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 3 @@ -3000,7 +3001,7 @@ def test_orderby_equation(self): ], orderby=["equation[1]"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 3 @@ -3018,7 +3019,7 @@ def test_orderby_equation(self): ], orderby=["-equation[0]"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 3 @@ -3033,7 +3034,7 @@ def test_orderby_nonexistent_equation(self): ], orderby=["equation[1]"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -3048,7 +3049,7 @@ def test_equation_without_field_or_function(self): "5 + 5", ], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) @@ -3059,7 +3060,7 @@ def test_aggregate_equation(self): ], equations=["p50(transaction.duration) / 2"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 1 @@ -3074,7 +3075,7 @@ def test_multiple_aggregate_equation(self): ], equations=["p50(transaction.duration) + 2", "p50(transaction.duration) / count()"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 1 @@ -3095,7 +3096,7 @@ def test_multiple_operators(self): "count() + count() / count() * count() - count()", ], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 1 @@ -3131,7 +3132,7 @@ def test_nan_equation_results(self): ], orderby=["equation[0]"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 3 @@ -3148,7 +3149,7 @@ def test_nan_equation_results(self): ], orderby=["equation[1]"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 3 @@ -3165,7 +3166,7 @@ def test_nan_equation_results(self): ], orderby=["-equation[0]"], query=self.query, - snuba_params=self.snuba_params, + params=self.params, referrer="discover", ) assert len(results["data"]) == 3 diff --git a/tests/sentry/snuba/test_transactions_timeseries_query.py b/tests/sentry/snuba/test_transactions_timeseries_query.py index a58ca3eac68f4b..97d93069f3c20a 100644 --- a/tests/sentry/snuba/test_transactions_timeseries_query.py +++ b/tests/sentry/snuba/test_transactions_timeseries_query.py @@ -5,7 +5,7 @@ from sentry.exceptions import InvalidSearchQuery from sentry.models.transaction_threshold import ProjectTransactionThreshold, TransactionMetric -from sentry.search.events.types import EventsResponse, SnubaParams +from sentry.search.events.types import EventsResponse from sentry.snuba import transactions from sentry.snuba.dataset import Dataset from sentry.testutils.cases import SnubaTestCase, TestCase @@ -52,11 +52,11 @@ def test_invalid_field_in_function(self): selected_columns=["min(transaction)"], query="transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=1800, ) @@ -66,7 +66,7 @@ def test_missing_start_and_end(self): selected_columns=["count()"], query="transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams(start=self.day_ago), + params={"start": self.day_ago}, rollup=1800, ) @@ -76,11 +76,11 @@ def test_no_aggregations(self): selected_columns=["transaction", "title"], query="transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=1800, ) @@ -89,11 +89,11 @@ def test_field_alias(self): selected_columns=["p95()"], query="event.type:transaction transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -103,11 +103,11 @@ def test_failure_rate_field_alias(self): selected_columns=["failure_rate()"], query="event.type:transaction transaction:api.issue.delete", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -117,11 +117,11 @@ def test_aggregate_function(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -131,11 +131,11 @@ def test_aggregate_function(self): selected_columns=["count_unique(user)"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -153,11 +153,11 @@ def test_comparison_aggregate_function_invalid(self): selected_columns=["count()", "count_unique(user)"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, comparison_delta=timedelta(days=1), ) @@ -171,11 +171,11 @@ def test_comparison_aggregate_function(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, comparison_delta=timedelta(days=1), ) @@ -205,11 +205,11 @@ def test_comparison_aggregate_function(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2, minutes=1), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2, minutes=1), + "project_id": [self.project.id], + }, rollup=3600, comparison_delta=timedelta(days=1), ) @@ -223,11 +223,11 @@ def test_comparison_aggregate_function(self): result = transactions.timeseries_query( selected_columns=["count_unique(user)"], query="", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2, minutes=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2, minutes=2), + "project_id": [self.project.id], + }, rollup=3600, referrer="test_discover_query", comparison_delta=timedelta(days=1), @@ -267,12 +267,12 @@ def test_count_miserable(self): selected_columns=["count_miserable(user)"], referrer="test_discover_query", query="transaction:api/foo/", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project, project2], - organization=self.organization, - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id, project2.id], + "organization_id": self.organization.id, + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -309,12 +309,12 @@ def test_count_miserable_with_arithmetic(self): selected_columns=["equation|count_miserable(user) - 100"], referrer="test_discover_query", query="transaction:api/foo/", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project, project2], - organization=self.organization, - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id, project2.id], + "organization_id": self.organization.id, + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -327,11 +327,11 @@ def test_equation_function(self): selected_columns=["equation|count() / 100"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 3 @@ -340,11 +340,11 @@ def test_equation_function(self): result = transactions.timeseries_query( selected_columns=["equation|count_unique(user) / 100"], query="", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=2), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=2), + "project_id": [self.project.id], + }, rollup=3600, referrer="test_discover_query", ) @@ -360,11 +360,11 @@ def test_zerofilling(self): selected_columns=["count()"], query="", referrer="test_discover_query", - snuba_params=SnubaParams( - start=self.day_ago, - end=self.day_ago + timedelta(hours=3), - projects=[self.project], - ), + params={ + "start": self.day_ago, + "end": self.day_ago + timedelta(hours=3), + "project_id": [self.project.id], + }, rollup=3600, ) assert len(result.data["data"]) == 4, "Should have empty results" @@ -385,11 +385,11 @@ def test_conditional_filter(self): result = transactions.timeseries_query( selected_columns=["count()"], query=f"project:{self.project.slug} OR project:{project2.slug}", - snuba_params=SnubaParams( - start=before_now(minutes=5), - end=before_now(seconds=1), - projects=[self.project, project2, project3], - ), + params={ + "start": before_now(minutes=5), + "end": before_now(seconds=1), + "project_id": [self.project.id, project2.id, project3.id], + }, rollup=3600, referrer="test_discover_query", ) @@ -424,11 +424,11 @@ def test_nested_conditional_filter(self): query="(release:{} OR release:{}) AND project:{}".format( "a" * 32, "b" * 32, self.project.slug ), - snuba_params=SnubaParams( - start=before_now(minutes=5), - end=before_now(seconds=1), - projects=[self.project, project2], - ), + params={ + "start": before_now(minutes=5), + "end": before_now(seconds=1), + "project_id": [self.project.id, project2.id], + }, rollup=3600, referrer="test_discover_query", ) @@ -460,11 +460,11 @@ def test_project_filter_adjusts_filter(self, mock_query): end = before_now(seconds=1) transactions.top_events_timeseries( selected_columns=["project", "count()"], - snuba_params=SnubaParams( - start=start, - end=end, - projects=[self.project, project2], - ), + params={ + "start": start, + "end": end, + "project_id": [self.project.id, project2.id], + }, rollup=3600, top_events=top_events, timeseries_columns=["count()"], @@ -524,11 +524,11 @@ def test_timestamp_fields(self, mock_query): end = before_now(minutes=1) transactions.top_events_timeseries( selected_columns=["timestamp", "timestamp.to_day", "timestamp.to_hour", "count()"], - snuba_params=SnubaParams( - start=start, - end=end, - projects=[self.project], - ), + params={ + "start": start, + "end": end, + "project_id": [self.project.id], + }, rollup=3600, top_events=top_events, timeseries_columns=["count()"], @@ -588,11 +588,7 @@ def test_equation_fields_are_auto_added(self, mock_query): transactions.top_events_timeseries( selected_columns=["count()"], equations=["equation|count_unique(user) * 2"], - snuba_params=SnubaParams( - start=start, - end=end, - projects=[self.project], - ), + params={"start": start, "end": end, "project_id": [self.project.id]}, rollup=3600, timeseries_columns=[], user_query="", @@ -604,11 +600,7 @@ def test_equation_fields_are_auto_added(self, mock_query): mock_query.assert_called_with( ["count()"], query="", - snuba_params=SnubaParams( - start=start, - end=end, - projects=[self.project], - ), + params={"start": start, "end": end, "project_id": [self.project.id]}, equations=["equation|count_unique(user) * 2"], orderby=["equation[0]"], referrer=None,