Skip to content

Commit

Permalink
fix(admin): make profile events optional for trace queries (#6779)
Browse files Browse the repository at this point in the history
Sometimes the system.query_log table doesn't exist in the environment.
Right now that breaks the entire tool. Gathering profile events can also
be quite slow and for long queries it can time out. Allow it to be
optional in the UI
  • Loading branch information
volokluev authored Jan 16, 2025
1 parent f187ccf commit 987fc61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
22 changes: 18 additions & 4 deletions snuba/admin/static/tracing/query_display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,24 @@ function QueryDisplay(props: {
options={storages}
/>
</div>
<ExecuteButton
onClick={executeQuery}
disabled={!query.storage || !query.sql}
/>
<div style={{ display: "flex", alignItems: "center", gap: "1rem" }}>
<Switch
checked={query.gather_profile_events ?? true}
onChange={(evt: React.ChangeEvent<HTMLInputElement>) =>
setQuery((prevQuery) => ({
...prevQuery,
gather_profile_events: evt.currentTarget.checked,
}))
}
onLabel="PROFILE"
offLabel="NO PROFILE"
size="md"
/>
<ExecuteButton
onClick={executeQuery}
disabled={!query.storage || !query.sql}
/>
</div>
</div>
<div>
<h2>Query results</h2>
Expand Down
5 changes: 3 additions & 2 deletions snuba/admin/static/tracing/types.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type TracingRequest = {
storage: string;
export type TracingRequest = {
sql: string;
storage: string;
gather_profile_events?: boolean;
};

type TracingResult = {
Expand Down
9 changes: 8 additions & 1 deletion snuba/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,14 @@ def clickhouse_trace_query() -> Response:

query_trace = run_query_and_get_trace(storage, raw_sql)

gather_profile_events(query_trace, storage)
if req.get("gather_profile_events", True):
try:
gather_profile_events(query_trace, storage)
except Exception:
logger.warning(
"Error gathering profile events, returning trace anyway",
exc_info=True,
)
return make_response(jsonify(asdict(query_trace)), 200)
except InvalidCustomQuery as err:
return make_response(
Expand Down

0 comments on commit 987fc61

Please sign in to comment.