-
Notifications
You must be signed in to change notification settings - Fork 14
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: enhance query detail page with cluster support and improve UI components #431
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { ErrorAlert } from '@/components/error-alert' | ||
import { Button } from '@/components/ui/button' | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuLabel, | ||
DropdownMenuRadioGroup, | ||
DropdownMenuRadioItem, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu' | ||
import { fetchData } from '@/lib/clickhouse' | ||
|
||
import { getHostIdCookie } from '@/lib/scoped-link' | ||
import { CircleCheckIcon, CombineIcon } from 'lucide-react' | ||
import { PageProps } from './types' | ||
|
||
interface RowData { | ||
cluster: string | ||
replica_count: number | ||
} | ||
|
||
const sql = ` | ||
SELECT DISTINCT | ||
cluster, | ||
count(replica_num) AS replica_count | ||
FROM system.clusters | ||
GROUP BY 1 | ||
` | ||
|
||
export async function DropdownCluster({ | ||
params, | ||
searchParams, | ||
className, | ||
}: { | ||
params: Awaited<PageProps['params']> | ||
searchParams: Awaited<PageProps['searchParams']> | ||
className?: string | ||
}) { | ||
const { query_id } = params | ||
const { cluster } = searchParams | ||
const hostId = await getHostIdCookie() | ||
const path = `/${hostId}/query/${query_id}/` | ||
|
||
try { | ||
const { data } = await fetchData<RowData[]>({ | ||
query: sql, | ||
format: 'JSONEachRow', | ||
clickhouse_settings: { | ||
use_query_cache: 0, | ||
}, | ||
hostId, | ||
}) | ||
|
||
if (!data.length) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className={className}> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="outline"> | ||
{!!cluster ? ( | ||
<span className="flex items-center gap-1"> | ||
<CircleCheckIcon className="size-3" /> | ||
{cluster} | ||
</span> | ||
) : ( | ||
<span className="flex items-center gap-1"> | ||
<CombineIcon className="size-3" /> | ||
Query Across Cluster | ||
</span> | ||
)} | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="w-56"> | ||
<DropdownMenuLabel>Query Across Cluster</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuRadioGroup value={cluster}> | ||
{data.map((row) => ( | ||
<DropdownMenuRadioItem key={row.cluster} value={row.cluster}> | ||
<a | ||
href={ | ||
cluster === row.cluster | ||
? path | ||
: `${path}?cluster=${row.cluster}` | ||
} | ||
> | ||
{row.cluster} ({row.replica_count} replicas) | ||
</a> | ||
</DropdownMenuRadioItem> | ||
))} | ||
</DropdownMenuRadioGroup> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</div> | ||
) | ||
} catch (error) { | ||
return ( | ||
<ErrorAlert | ||
title="ClickHouse Query Error" | ||
message={`${error}`} | ||
query={sql} | ||
/> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Badge } from '@/components/ui/badge' | ||
import { fetchData } from '@/lib/clickhouse' | ||
import { getHostIdCookie } from '@/lib/scoped-link' | ||
import { QueryConfig } from '@/types/query-config' | ||
import { type RowData } from './config' | ||
import { PageProps } from './types' | ||
|
||
export async function QueryDetailBadge({ | ||
queryConfig, | ||
params, | ||
}: { | ||
queryConfig: QueryConfig | ||
params: Awaited<PageProps['params']> | ||
searchParams: Awaited<PageProps['searchParams']> | ||
}) { | ||
try { | ||
const queryParams = { | ||
...queryConfig.defaultParams, | ||
...params, | ||
} | ||
const { data } = await fetchData<RowData[]>({ | ||
query: queryConfig.sql, | ||
format: 'JSONEachRow', | ||
query_params: queryParams, | ||
clickhouse_settings: { | ||
use_query_cache: 0, | ||
...queryConfig.clickhouseSettings, | ||
}, | ||
hostId: await getHostIdCookie(), | ||
}) | ||
|
||
if (!data.length) { | ||
return <div className="text-xs text-muted-foreground">No data</div> | ||
} | ||
|
||
const { user } = data[0] | ||
const finalType = data[data.length - 1].type | ||
const query_duration_ms = data | ||
.map((row) => parseInt(row.duration_ms)) | ||
.reduce((a, b) => a + b, 0) | ||
|
||
return ( | ||
<> | ||
<Badge className="ml-2" variant="outline" title="Query Duration (ms)"> | ||
{query_duration_ms} ms | ||
</Badge> | ||
<Badge className="ml-2" variant="outline" title="Query Type"> | ||
{finalType || 'Unknown'} | ||
</Badge> | ||
<Badge className="ml-2" variant="outline" title="User"> | ||
{user || 'Unknown'} | ||
</Badge> | ||
</> | ||
) | ||
} catch (error) { | ||
return null | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): Consider lifting data fetching to parent component to avoid duplicate queries
This component and QueryDetailCard are fetching the same data. Consider fetching once in a parent component and passing the data down to both children to improve performance.