From 3f9304db27baad02cc97e3a3fceb8cb7b5dd1d58 Mon Sep 17 00:00:00 2001 From: Rahul Saini Date: Wed, 15 Mar 2023 14:48:46 -0700 Subject: [PATCH 1/5] tenant_ids for replays queries --- src/sentry/eventstore/snuba/backend.py | 2 ++ .../replays/endpoints/organization_replay_count.py | 1 + .../replays/endpoints/organization_replay_index.py | 1 + src/sentry/replays/endpoints/project_replay_details.py | 1 + src/sentry/replays/query.py | 10 ++++++++++ src/sentry/tagstore/snuba/backend.py | 1 + 6 files changed, 16 insertions(+) diff --git a/src/sentry/eventstore/snuba/backend.py b/src/sentry/eventstore/snuba/backend.py index 5034e5adde7130..0c2e8d5a93ea98 100644 --- a/src/sentry/eventstore/snuba/backend.py +++ b/src/sentry/eventstore/snuba/backend.py @@ -233,6 +233,7 @@ def get_event_by_id(self, project_id, event_id, group_id=None): filter_keys={"project_id": [project_id], "event_id": [event_id]}, limit=1, referrer="eventstore.get_event_by_id_nodestore", + tenant_ids={"organization_id": event.project.organization_id}, **raw_query_kwargs, ) except snuba.QueryOutsideRetentionError: @@ -338,6 +339,7 @@ def __get_event_id_from_filter( referrer="eventstore.get_next_or_prev_event_id", orderby=orderby, dataset=dataset, + tenant_ids=tenant_ids, ) except (snuba.QueryOutsideRetentionError, snuba.QueryOutsideGroupActivityError): # This can happen when the date conditions for paging diff --git a/src/sentry/replays/endpoints/organization_replay_count.py b/src/sentry/replays/endpoints/organization_replay_count.py index 4622bd501c0d5a..c66e9133ada358 100644 --- a/src/sentry/replays/endpoints/organization_replay_count.py +++ b/src/sentry/replays/endpoints/organization_replay_count.py @@ -65,6 +65,7 @@ def get(self, request: Request, organization: Organization) -> Response: start=snuba_params.start, end=snuba_params.end, replay_ids=list(replay_ids_mapping.keys()), + tenant_ids={"organization_id": organization.id}, ) if request.GET.get("returnIds"): diff --git a/src/sentry/replays/endpoints/organization_replay_index.py b/src/sentry/replays/endpoints/organization_replay_index.py index 4df6b41faa0be2..efc0a09cdfb629 100644 --- a/src/sentry/replays/endpoints/organization_replay_index.py +++ b/src/sentry/replays/endpoints/organization_replay_index.py @@ -61,6 +61,7 @@ def data_fn(offset, limit): limit=limit, offset=offset, search_filters=search_filters, + tenant_ids={"organization_id": organization.id}, ) return self.paginate( diff --git a/src/sentry/replays/endpoints/project_replay_details.py b/src/sentry/replays/endpoints/project_replay_details.py index ceb5f3619d4630..ddea55e28c15f8 100644 --- a/src/sentry/replays/endpoints/project_replay_details.py +++ b/src/sentry/replays/endpoints/project_replay_details.py @@ -45,6 +45,7 @@ def get(self, request: Request, project: Project, replay_id: str) -> Response: replay_id=replay_id, start=filter_params["start"], end=filter_params["end"], + tenant_ids={"organization_id": project.organization_id}, ) response = process_raw_response( diff --git a/src/sentry/replays/query.py b/src/sentry/replays/query.py index efa0849309af90..3af7113c43b3ff 100644 --- a/src/sentry/replays/query.py +++ b/src/sentry/replays/query.py @@ -52,6 +52,7 @@ def query_replays_collection( limit: Optional[str], offset: Optional[str], search_filters: List[SearchFilter], + tenant_ids: dict[str, Any], ) -> dict: """Query aggregated replay collection.""" conditions = [] @@ -75,6 +76,7 @@ def query_replays_collection( sorting=sort_ordering, pagination=paginators, search_filters=search_filters, + tenant_ids=tenant_ids, ) return response["data"] @@ -84,6 +86,7 @@ def query_replay_instance( replay_id: str, start: datetime, end: datetime, + tenant_ids: dict[str, Any], ): """Query aggregated replay instance.""" response = query_replays_dataset( @@ -98,6 +101,7 @@ def query_replay_instance( sorting=[], pagination=None, search_filters=[], + tenant_ids=tenant_ids, ) return response["data"] @@ -112,6 +116,7 @@ def query_replays_dataset( sorting: List[OrderBy], pagination: Optional[Paginators], search_filters: List[SearchFilter], + tenant_ids: dict[str, Any], ): query_options = {} @@ -157,6 +162,7 @@ def query_replays_dataset( groupby=[Column("project_id"), Column("replay_id")], granularity=Granularity(3600), **query_options, + tenant_ids=tenant_ids, ), ) return raw_snql_query(snuba_request, "replays.query.query_replays_dataset") @@ -167,6 +173,7 @@ def query_replays_count( start: datetime, end: datetime, replay_ids: List[str], + tenant_ids: dict[str, Any], ): snuba_request = Request( @@ -198,6 +205,7 @@ def query_replays_count( groupby=[Column("replay_id")], granularity=Granularity(3600), ), + tenant_ids=tenant_ids, ) return raw_snql_query( snuba_request, referrer="replays.query.query_replays_count", use_cache=True @@ -210,6 +218,7 @@ def query_replays_dataset_tagkey_values( end: datetime, environment: str | None, tag_key: str, + tenant_ids: dict[str, Any] | None, ): """Query replay tagkey values. Like our other tag functionality, aggregates do not work here.""" @@ -256,6 +265,7 @@ def query_replays_dataset_tagkey_values( groupby=[grouped_column], granularity=Granularity(3600), limit=Limit(1000), + tenant_ids=tenant_ids, ), ) return raw_snql_query( diff --git a/src/sentry/tagstore/snuba/backend.py b/src/sentry/tagstore/snuba/backend.py index 1ce0f461786524..b076de0c4ca6ad 100644 --- a/src/sentry/tagstore/snuba/backend.py +++ b/src/sentry/tagstore/snuba/backend.py @@ -1404,6 +1404,7 @@ def get_tag_value_paginator_for_projects( end=end, environment=filters.get("environment"), tag_key=key, + tenant_ids=tenant_ids, ) results = { d["tag_value"]: { From 481ccc42c8004feb4de4f56ae13d99f837469eb3 Mon Sep 17 00:00:00 2001 From: Rahul Saini Date: Wed, 15 Mar 2023 16:59:43 -0700 Subject: [PATCH 2/5] fix tenant_ids --- src/sentry/replays/query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/replays/query.py b/src/sentry/replays/query.py index 3af7113c43b3ff..0e256e8d657458 100644 --- a/src/sentry/replays/query.py +++ b/src/sentry/replays/query.py @@ -162,8 +162,8 @@ def query_replays_dataset( groupby=[Column("project_id"), Column("replay_id")], granularity=Granularity(3600), **query_options, - tenant_ids=tenant_ids, ), + tenant_ids=tenant_ids, ) return raw_snql_query(snuba_request, "replays.query.query_replays_dataset") From 72ac71fed326bf8e309c9f18c672f6b588e4e931 Mon Sep 17 00:00:00 2001 From: Rahul Saini Date: Thu, 16 Mar 2023 09:53:19 -0700 Subject: [PATCH 3/5] fix tenant_ids --- src/sentry/replays/query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/replays/query.py b/src/sentry/replays/query.py index 0e256e8d657458..88a6f3c61f8ae0 100644 --- a/src/sentry/replays/query.py +++ b/src/sentry/replays/query.py @@ -265,8 +265,8 @@ def query_replays_dataset_tagkey_values( groupby=[grouped_column], granularity=Granularity(3600), limit=Limit(1000), - tenant_ids=tenant_ids, ), + tenant_ids=tenant_ids, ) return raw_snql_query( snuba_request, referrer="replays.query.query_replays_dataset_tagkey_values", use_cache=True From c3fbc663add04ca46d408ed4f9f7b4588719c4a0 Mon Sep 17 00:00:00 2001 From: Rahul Saini Date: Thu, 16 Mar 2023 11:38:51 -0700 Subject: [PATCH 4/5] optional tenant_ids in query_replays_dataset for delete script --- src/sentry/replays/query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/replays/query.py b/src/sentry/replays/query.py index 88a6f3c61f8ae0..b97cc7c98d2dd6 100644 --- a/src/sentry/replays/query.py +++ b/src/sentry/replays/query.py @@ -116,7 +116,7 @@ def query_replays_dataset( sorting: List[OrderBy], pagination: Optional[Paginators], search_filters: List[SearchFilter], - tenant_ids: dict[str, Any], + tenant_ids: dict[str, Any] | None = None, ): query_options = {} From 51d05cd6699058c66718bc98929e748a2994a856 Mon Sep 17 00:00:00 2001 From: Rahul Saini Date: Thu, 16 Mar 2023 11:56:15 -0700 Subject: [PATCH 5/5] optional tenant_ids in query_replays_collection for delete script --- src/sentry/replays/query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/replays/query.py b/src/sentry/replays/query.py index b97cc7c98d2dd6..81df5fba878e9e 100644 --- a/src/sentry/replays/query.py +++ b/src/sentry/replays/query.py @@ -52,7 +52,7 @@ def query_replays_collection( limit: Optional[str], offset: Optional[str], search_filters: List[SearchFilter], - tenant_ids: dict[str, Any], + tenant_ids: dict[str, Any] | None = None, ) -> dict: """Query aggregated replay collection.""" conditions = []