-
Notifications
You must be signed in to change notification settings - Fork 5
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: add http-connections and interserver-connections charts #242
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,44 @@ | ||||||||||||||
import { ChartSkeleton } from '@/components/skeleton' | ||||||||||||||
import { notFound } from 'next/navigation' | ||||||||||||||
import { Suspense } from 'react' | ||||||||||||||
|
||||||||||||||
interface PageProps { | ||||||||||||||
params: { | ||||||||||||||
charts: string | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
export const dynamic = 'force-dynamic' | ||||||||||||||
export const revalidate = 30 | ||||||||||||||
|
||||||||||||||
export default async function Page({ params: { charts } }: PageProps) { | ||||||||||||||
let chartComponents = [] | ||||||||||||||
let props = {} | ||||||||||||||
|
||||||||||||||
for (const chart of decodeURIComponent(charts).split(',')) { | ||||||||||||||
console.log(`Rendering chart: ${chart}`) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Remove or replace console.log statements. Consider removing or replacing
Suggested change
|
||||||||||||||
try { | ||||||||||||||
chartComponents.push( | ||||||||||||||
(await import(`@/components/charts/${chart}`)).default | ||||||||||||||
) | ||||||||||||||
} catch (e) { | ||||||||||||||
console.error(`Error rendering chart: ${chart}`, e) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Improve error handling for chart rendering. Consider providing more user-friendly feedback or fallback UI in case of errors when rendering charts, rather than just logging the error.
Suggested change
|
||||||||||||||
notFound() | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return ( | ||||||||||||||
<div> | ||||||||||||||
{chartComponents.map((Chart, i) => ( | ||||||||||||||
<Suspense key={i} fallback={<ChartSkeleton />}> | ||||||||||||||
<Chart | ||||||||||||||
key={i} | ||||||||||||||
className="mb-4 w-full p-0 shadow-none" | ||||||||||||||
chartClassName="h-64" | ||||||||||||||
{...props} | ||||||||||||||
/> | ||||||||||||||
</Suspense> | ||||||||||||||
))} | ||||||||||||||
</div> | ||||||||||||||
) | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ChartCard } from '@/components/chart-card' | ||
import { fetchData } from '@/lib/clickhouse' | ||
import { cn } from '@/lib/utils' | ||
import { BarChart } from '../tremor/bar' | ||
import { type ChartProps } from './chart-props' | ||
|
||
export async function ChartConnectionsHttp({ | ||
title = 'HTTP Connections Last 7 days (Total Requests / Hour)', | ||
interval = 'toStartOfHour', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Consider validating the To prevent potential SQL injection or unexpected behavior, consider validating the |
||
lastHours = 24 * 7, | ||
className, | ||
chartClassName, | ||
}: ChartProps) { | ||
const query = ` | ||
SELECT | ||
${interval}(event_time) AS event_time, | ||
SUM(CurrentMetric_HTTPConnection) AS CurrentMetric_HTTPConnection, | ||
formatReadableQuantity(CurrentMetric_HTTPConnection) AS readable_CurrentMetric_HTTPConnection | ||
FROM system.metric_log | ||
WHERE event_time >= now() - INTERVAL ${lastHours} HOUR | ||
GROUP BY event_time | ||
ORDER BY event_time | ||
` | ||
|
||
const data = await fetchData< | ||
{ | ||
event_time: string | ||
CurrentMetric_HTTPConnection: number | ||
readable_CurrentMetric_HTTPConnection: string | ||
}[] | ||
>({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Handle potential errors from Consider adding error handling for the |
||
query, | ||
format: 'JSONEachRow', | ||
}) | ||
|
||
return ( | ||
<ChartCard title={title} sql={query} className={className}> | ||
<BarChart | ||
data={data} | ||
index="event_time" | ||
categories={['CurrentMetric_HTTPConnection']} | ||
readableColumn="readable_CurrentMetric_HTTPConnection" | ||
className={cn('h-52', chartClassName)} | ||
stack | ||
/> | ||
</ChartCard> | ||
) | ||
} | ||
|
||
export default ChartConnectionsHttp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ChartCard } from '@/components/chart-card' | ||
import { fetchData } from '@/lib/clickhouse' | ||
import { cn } from '@/lib/utils' | ||
import { BarChart } from '../tremor/bar' | ||
import { type ChartProps } from './chart-props' | ||
|
||
export async function ChartConnectionsInterserver({ | ||
title = 'Interserver Connections Last 7 days (Total Requests / Hour)', | ||
interval = 'toStartOfHour', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Consider validating the To prevent potential SQL injection or unexpected behavior, consider validating the |
||
lastHours = 24 * 7, | ||
className, | ||
chartClassName, | ||
}: ChartProps) { | ||
const query = ` | ||
SELECT | ||
${interval}(event_time) AS event_time, | ||
SUM(CurrentMetric_InterserverConnection) AS CurrentMetric_InterserverConnection, | ||
formatReadableQuantity(CurrentMetric_InterserverConnection) AS readable_CurrentMetric_InterserverConnection | ||
FROM system.metric_log | ||
WHERE event_time >= now() - INTERVAL ${lastHours} HOUR | ||
GROUP BY event_time | ||
ORDER BY event_time | ||
` | ||
|
||
const data = await fetchData< | ||
{ | ||
event_time: string | ||
CurrentMetric_InterserverConnection: number | ||
readable_CurrentMetric_InterserverConnection: string | ||
}[] | ||
>({ | ||
Comment on lines
+25
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Handle potential errors from Consider adding error handling for the |
||
query, | ||
format: 'JSONEachRow', | ||
}) | ||
|
||
return ( | ||
<ChartCard title={title} sql={query} className={className}> | ||
<BarChart | ||
data={data} | ||
index="event_time" | ||
categories={['CurrentMetric_InterserverConnection']} | ||
readableColumn="readable_CurrentMetric_InterserverConnection" | ||
className={cn('h-52', chartClassName)} | ||
stack | ||
/> | ||
</ChartCard> | ||
) | ||
} | ||
|
||
export default ChartConnectionsInterserver |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,6 +27,7 @@ import { | |||||||||||||||||||||||||||
HardDriveIcon, | ||||||||||||||||||||||||||||
RollerCoasterIcon, | ||||||||||||||||||||||||||||
UngroupIcon, | ||||||||||||||||||||||||||||
UnplugIcon, | ||||||||||||||||||||||||||||
} from 'lucide-react' | ||||||||||||||||||||||||||||
import { type MenuItem } from './components/menu/types' | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -247,6 +248,12 @@ export const menuItemsConfig: MenuItem[] = [ | |||||||||||||||||||||||||||
'Exposes data from the Keeper cluster defined in the config', | ||||||||||||||||||||||||||||
icon: RollerCoasterIcon, | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||
title: 'Connections', | ||||||||||||||||||||||||||||
href: '/charts/connections-http,connections-interserver', | ||||||||||||||||||||||||||||
description: 'Number of connections over time', | ||||||||||||||||||||||||||||
icon: UnplugIcon, | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
Comment on lines
+251
to
+256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider adding a unique identifier for each menu item. Adding a unique identifier (e.g.,
Suggested change
|
||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
] |
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: Clarify the purpose of disabling revalidation.
It would be helpful to add a comment explaining why revalidation is disabled for this route. This can provide context for future maintainers.