-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #431 from duyet/chore/ui-update
feat: enhance query detail page with cluster support and improve UI components
- Loading branch information
Showing
12 changed files
with
623 additions
and
392 deletions.
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.
f36e38e
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.
Successfully deployed to the following URLs:
clickhouse-monitoring – ./
clickhouse-monitoring.vercel.app
clickhouse-monitor.vercel.app
clickhouse-dashboard.vercel.app
clickhouse-monitoring-duyet-team.vercel.app
clickhouse.duyet.net
clickhouse-monitoring-git-main-duyet-team.vercel.app