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: add http-connections and interserver-connections charts #242

Merged
merged 3 commits into from
May 18, 2024
Merged

Conversation

duyet
Copy link
Owner

@duyet duyet commented May 18, 2024

Resolved #103

Copy link

vercel bot commented May 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clickhouse-monitoring ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 18, 2024 6:09pm

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @duyet - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 6 issues found
  • 🟡 Security: 2 issues found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +251 to +256
{
title: 'Connections',
href: '/charts/connections-http,connections-interserver',
description: 'Number of connections over time',
icon: UnplugIcon,
},
Copy link
Contributor

Choose a reason for hiding this comment

The 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., id) to each menu item can help with tracking and managing menu items more effectively, especially if the list grows or needs to be manipulated programmatically.

Suggested change
{
title: 'Connections',
href: '/charts/connections-http,connections-interserver',
description: 'Number of connections over time',
icon: UnplugIcon,
},
{
id: 'connections',
title: 'Connections',
href: '/charts/connections-http,connections-interserver',
description: 'Number of connections over time',
icon: UnplugIcon,
},

@@ -2,6 +2,8 @@ import { NextResponse } from 'next/server'

import { fetchData } from '@/lib/clickhouse'

export const revalidate = false
Copy link
Contributor

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.

Suggested change
export const revalidate = false
export const revalidate = false // Revalidation is disabled to ensure the data remains static and doesn't trigger unnecessary fetches


export async function ChartConnectionsHttp({
title = 'HTTP Connections Last 7 days (Total Requests / Hour)',
interval = 'toStartOfHour',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue (security): Consider validating the interval parameter.

To prevent potential SQL injection or unexpected behavior, consider validating the interval parameter to ensure it only contains allowed values.

Comment on lines 25 to 31
const data = await fetchData<
{
event_time: string
CurrentMetric_HTTPConnection: number
readable_CurrentMetric_HTTPConnection: string
}[]
>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Handle potential errors from fetchData.

Consider adding error handling for the fetchData call to manage potential failures gracefully.


export async function ChartConnectionsInterserver({
title = 'Interserver Connections Last 7 days (Total Requests / Hour)',
interval = 'toStartOfHour',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue (security): Consider validating the interval parameter.

To prevent potential SQL injection or unexpected behavior, consider validating the interval parameter to ensure it only contains allowed values.

Comment on lines +25 to +31
const data = await fetchData<
{
event_time: string
CurrentMetric_InterserverConnection: number
readable_CurrentMetric_InterserverConnection: string
}[]
>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Handle potential errors from fetchData.

Consider adding error handling for the fetchData call to manage potential failures gracefully.

let props = {}

for (const chart of decodeURIComponent(charts).split(',')) {
console.log(`Rendering chart: ${chart}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Remove or replace console.log statements.

Consider removing or replacing console.log statements with a proper logging mechanism to avoid cluttering the console in production.

Suggested change
console.log(`Rendering chart: ${chart}`)
import { log } from 'some-logging-library';
...
log.info(`Rendering chart: ${chart}`);

(await import(`@/components/charts/${chart}`)).default
)
} catch (e) {
console.error(`Error rendering chart: ${chart}`, e)
Copy link
Contributor

Choose a reason for hiding this comment

The 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
console.error(`Error rendering chart: ${chart}`, e)
console.error(`Error rendering chart: ${chart}`, e)
alert('An error occurred while rendering the chart. Please try again later.')

@duyet duyet merged commit 98d02a7 into main May 18, 2024
10 checks passed
@duyet duyet deleted the chore/ui branch May 18, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Number of connections
1 participant