-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(explorer/replay): support short id details query for replay metadata rpc #103269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f28cd1c
337e0b8
faeb88c
c4e8138
041ecde
0309873
ecfc466
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| Entity, | ||
| Function, | ||
| Granularity, | ||
| Limit, | ||
| Op, | ||
| Or, | ||
| OrderBy, | ||
|
|
@@ -440,6 +441,62 @@ def make_full_aggregation_query( | |
| ) | ||
|
|
||
|
|
||
| def make_full_aggregation_query_with_short_id( | ||
| fields: list[str], | ||
| replay_id_prefix: str, | ||
| project_ids: list[int], | ||
| period_start: datetime, | ||
| period_end: datetime, | ||
| request_user_id: int | None, | ||
| limit: int, | ||
| ) -> Query: | ||
| """Return a query to fetch a replay with a short ID - an 8-character replay ID prefix. | ||
| This query does not make use of the replay_id index and can potentially scan all rows in the time range and project list. | ||
|
|
||
| Arguments: | ||
| fields -- if non-empty, used to query a subset of fields. Corresponds to the keys in QUERY_ALIAS_COLUMN_MAP. | ||
| """ | ||
|
|
||
| if len(replay_id_prefix) != 8 or not replay_id_prefix.isalnum(): | ||
| raise ValueError("Invalid short ID. Must be 8 hexadecimal characters.") | ||
aliu39 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from sentry.replays.query import select_from_fields | ||
aliu39 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| select = select_from_fields(fields, user_id=request_user_id) | ||
|
|
||
| return Query( | ||
|
||
| match=Entity("replays"), | ||
| select=select, | ||
| where=[ | ||
| Condition(Column("project_id"), Op.IN, project_ids), | ||
| # Range queries on UUID column don't work as expected due to comparison on the binary representation, and Clickhouse endianness. | ||
| # It's slower as we're no longer using the replay_id index, but the only way to do this is through a string prefix filter. | ||
| Condition( | ||
| Function( | ||
| "startsWith", | ||
| parameters=[ | ||
| Function("toString", parameters=[Column("replay_id")]), | ||
| replay_id_prefix, | ||
| ], | ||
| ), | ||
| Op.EQ, | ||
| 1, | ||
| ), | ||
| # We can scan an extended time range to account for replays which span either end of | ||
| # the range. | ||
| Condition(Column("timestamp"), Op.GTE, period_start - timedelta(hours=1)), | ||
| Condition(Column("timestamp"), Op.LT, period_end + timedelta(hours=1)), | ||
| ], | ||
| # NOTE: Refer to this note: "make_scalar_search_conditions_query". | ||
| # | ||
| # This condition ensures that every replay shown to the user is valid. | ||
| having=[Condition(Function("min", parameters=[Column("segment_id")]), Op.EQ, 0)], | ||
| groupby=[Column("replay_id")], | ||
| granularity=Granularity(3600), | ||
| limit=Limit(limit), | ||
| ) | ||
|
|
||
|
|
||
| def execute_query(query: Query, tenant_id: dict[str, int], referrer: str) -> Mapping[str, Any]: | ||
| try: | ||
| return raw_snql_query( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.