-
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.
feat: show chart sql dialog, add new-parts-created chart
- Loading branch information
Showing
17 changed files
with
269 additions
and
65 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,32 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
import { RelatedCharts } from '@/components/related-charts' | ||
|
||
interface PageProps { | ||
params: { | ||
chart: string | ||
} | ||
} | ||
|
||
export const dynamic = 'force-dynamic' | ||
export const revalidate = 30 | ||
|
||
export default async function Page({ params: { chart } }: PageProps) { | ||
const title = chart.replace(/-/g, ' ') | ||
let Chart | ||
let props = {} | ||
|
||
try { | ||
Chart = (await import(`@/components/charts/${chart}`)).default | ||
} catch (e) { | ||
return notFound() | ||
} | ||
|
||
return ( | ||
<Chart | ||
className="w-full p-0 shadow-none" | ||
chartClassName="h-96" | ||
{...props} | ||
/> | ||
) | ||
} |
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
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
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
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,68 @@ | ||
import { fetchData } from '@/lib/clickhouse' | ||
import { ChartCard } from '@/components/chart-card' | ||
import type { ChartProps } from '@/components/charts/chart-props' | ||
import { BarChart } from '@/components/tremor' | ||
|
||
export async function ChartNewPartCreated({ | ||
title = 'New Parts Created over last 24 hours (part counts / 15 minutes)', | ||
interval = 'toStartOfFifteenMinutes', | ||
lastHours = 24, | ||
className, | ||
chartClassName, | ||
...props | ||
}: ChartProps) { | ||
const sql = ` | ||
SELECT | ||
count() AS new_parts, | ||
${interval}(event_time) AS event_time, | ||
table, | ||
sum(rows) AS total_written_rows, | ||
formatReadableQuantity(total_written_rows) AS readable_total_written_rows, | ||
sum(size_in_bytes) AS total_bytes_on_disk, | ||
formatReadableSize(total_bytes_on_disk) AS readable_total_bytes_on_disk | ||
FROM clusterAllReplicas(default, system.part_log) | ||
WHERE (event_type = 'NewPart') AND (event_time > (now() - toIntervalHour(${lastHours}))) | ||
GROUP BY | ||
event_time, | ||
table | ||
ORDER BY | ||
event_time ASC, | ||
table DESC | ||
` | ||
|
||
const raw = await fetchData(sql) | ||
|
||
const data = raw.reduce((acc, cur) => { | ||
const { event_time, table, new_parts } = cur | ||
if (acc[event_time] === undefined) { | ||
acc[event_time] = {} | ||
} | ||
acc[event_time][table] = new_parts | ||
return acc | ||
}, {}) as Record<string, Record<string, number>> | ||
|
||
const barData = Object.entries(data).map(([event_time, obj]) => { | ||
return { event_time, ...obj } | ||
}) | ||
|
||
// All users | ||
const tables = Object.values(data).reduce((acc, cur) => { | ||
return Array.from(new Set([...acc, ...Object.keys(cur)])) | ||
}, [] as string[]) | ||
|
||
return ( | ||
<ChartCard title={title} className={className} sql={sql}> | ||
<BarChart | ||
className={chartClassName} | ||
data={barData} | ||
index="event_time" | ||
categories={tables} | ||
readable="quantity" | ||
stack | ||
{...props} | ||
/> | ||
</ChartCard> | ||
) | ||
} | ||
|
||
export default ChartNewPartCreated |
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
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
Oops, something went wrong.