Skip to content
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

feat: snuba admin, collapse stack trace in errors in system query tool #6787

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions snuba/admin/static/clickhouse_queries/query_display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Placeholder from "@tiptap/extension-placeholder";
import StarterKit from "@tiptap/starter-kit";
import { getRecentHistory, setRecentHistory } from "SnubaAdmin/query_history";
import { CustomSelect, getParamFromStorage } from "SnubaAdmin/select";
import { Collapse as MantineCollapse, Group, Text } from '@mantine/core';
import { IconChevronDown, IconChevronRight } from '@tabler/icons-react';

import {
ClickhouseNodeData,
Expand All @@ -39,6 +41,9 @@ function QueryDisplay(props: {

const [queryError, setQueryError] = useState<Error | null>(null);

// this is used to collapse the stack trace in error messages
const [collapseOpened, setCollapseOpened] = useState(false);

useEffect(() => {
props.api.getClickhouseNodes().then((res) => {
setNodeData(res);
Expand Down Expand Up @@ -132,8 +137,32 @@ function QueryDisplay(props: {

function getErrorDomElement() {
if (queryError !== null) {
const bodyDOM = queryError.message.split("\n").map((line) => <React.Fragment>{line}< br /></React.Fragment>)
return <Alert title={queryError.name} color="red">{bodyDOM}</Alert>;
let title: string;
let bodyDOM;
if (queryError.name === "Error" && queryError.message.includes("Stack trace:")) {
// this puts the stack trace in a collapsible section
const split = queryError.message.indexOf("Stack trace:")
title = queryError.message.slice(0, split)

const stackTrace = queryError.message.slice(split + "Stack trace:".length)
.split("\n").map((line) => <React.Fragment>{line}< br /></React.Fragment>)
bodyDOM = <div>
<Group spacing="xs" onClick={() => setCollapseOpened((o) => !o)} style={{ cursor: 'pointer' }}>
{collapseOpened ? <IconChevronDown size={16} /> : <IconChevronRight size={16} />}
<Text weight={500}>Stack Trace</Text>
</Group>

<MantineCollapse in={collapseOpened}>
<Text mt="sm">
{stackTrace}
</Text>
</MantineCollapse>
</div>
} else {
title = queryError.name
bodyDOM = queryError.message.split("\n").map((line) => <React.Fragment>{line}< br /></React.Fragment>)
}
return <Alert title={title} color="red">{bodyDOM}</Alert>;
}
return "";
}
Expand Down
Loading