Skip to content

Commit

Permalink
feat(CapMan): Replays queries now have tenant_ids (#45885)
Browse files Browse the repository at this point in the history
### Overview
- Added org ID per Snuba request for Replays queries
- More context #44788
  • Loading branch information
rahul-kumar-saini authored Mar 16, 2023
1 parent a9991cc commit f5ab3c9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sentry/eventstore/snuba/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/sentry/replays/endpoints/organization_replay_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
1 change: 1 addition & 0 deletions src/sentry/replays/endpoints/organization_replay_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/sentry/replays/endpoints/project_replay_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions src/sentry/replays/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def query_replays_collection(
limit: Optional[str],
offset: Optional[str],
search_filters: List[SearchFilter],
tenant_ids: dict[str, Any] | None = None,
) -> dict:
"""Query aggregated replay collection."""
conditions = []
Expand All @@ -75,6 +76,7 @@ def query_replays_collection(
sorting=sort_ordering,
pagination=paginators,
search_filters=search_filters,
tenant_ids=tenant_ids,
)
return response["data"]

Expand All @@ -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(
Expand All @@ -98,6 +101,7 @@ def query_replay_instance(
sorting=[],
pagination=None,
search_filters=[],
tenant_ids=tenant_ids,
)
return response["data"]

Expand All @@ -112,6 +116,7 @@ def query_replays_dataset(
sorting: List[OrderBy],
pagination: Optional[Paginators],
search_filters: List[SearchFilter],
tenant_ids: dict[str, Any] | None = None,
):
query_options = {}

Expand Down Expand Up @@ -158,6 +163,7 @@ def query_replays_dataset(
granularity=Granularity(3600),
**query_options,
),
tenant_ids=tenant_ids,
)
return raw_snql_query(snuba_request, "replays.query.query_replays_dataset")

Expand All @@ -167,6 +173,7 @@ def query_replays_count(
start: datetime,
end: datetime,
replay_ids: List[str],
tenant_ids: dict[str, Any],
):

snuba_request = Request(
Expand Down Expand Up @@ -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
Expand All @@ -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."""

Expand Down Expand Up @@ -257,6 +266,7 @@ def query_replays_dataset_tagkey_values(
granularity=Granularity(3600),
limit=Limit(1000),
),
tenant_ids=tenant_ids,
)
return raw_snql_query(
snuba_request, referrer="replays.query.query_replays_dataset_tagkey_values", use_cache=True
Expand Down
1 change: 1 addition & 0 deletions src/sentry/tagstore/snuba/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]: {
Expand Down

0 comments on commit f5ab3c9

Please sign in to comment.