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 /query-cache #288

Merged
merged 4 commits into from
Jul 10, 2024
Merged

feat: add /query-cache #288

merged 4 commits into from
Jul 10, 2024

Conversation

duyet
Copy link
Owner

@duyet duyet commented Jul 10, 2024

Close #287

Summary by Sourcery

This pull request introduces a new 'Query Cache' feature, adding it to the menu, implementing a chart component to display query cache metrics, and creating a query configuration to fetch and display query cache data.

  • New Features:
    • Added a new 'Query Cache' section to the menu with a corresponding icon and description.
    • Introduced a new chart component 'ChartQueryCache' to display query cache metrics.
    • Implemented a new query configuration 'queryCacheConfig' to fetch and display query cache data.

Copy link

vercel bot commented Jul 10, 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 Jul 10, 2024 0:34am

Copy link
Contributor

sourcery-ai bot commented Jul 10, 2024

Reviewer's Guide by Sourcery

This pull request implements the 'Query Cache' feature by adding a new menu item, creating a new chart component to display query cache metrics, and defining a new query configuration to fetch and display query cache details from the 'system.query_cache' table.

File-Level Changes

Files Changes
components/charts/query-cache.tsx
app/[query]/queries/query-cache.ts
Introduced new components and configurations to support the display of query cache metrics and details.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@duyet duyet enabled auto-merge July 10, 2024 12:30
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 found some issues that need to be addressed.

Blocking issues:

  • Check for division by zero. (link)
Here's what I looked at during the review
  • 🔴 General issues: 1 blocking issue, 5 other issues
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: 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 +151 to +156
{
title: 'Query Cache',
href: '/query-cache',
description: 'Query cache usage',
icon: DatabaseZapIcon,
},
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 the new menu item.

Adding a unique identifier (e.g., id: 'query-cache') to each menu item can help with tracking and managing menu items programmatically.

Suggested change
{
title: 'Query Cache',
href: '/query-cache',
description: 'Query cache usage',
icon: DatabaseZapIcon,
},
{
id: 'query-cache',
title: 'Query Cache',
href: '/query-cache',
description: 'Query cache usage',
icon: DatabaseZapIcon,
},

Copy link
Owner Author

Choose a reason for hiding this comment

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

This one can respect the type when suggesting adding an id

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for pointing that out, @duyet. You're correct that the suggestion should respect the existing type definitions. If the MenuItem type does not currently include an id field, we should update the type definition accordingly. Here's an example of how you might adjust the type and the menu item:

  1. Update the MenuItem type to include an id field:

    interface MenuItem {
      id: string;
      title: string;
      href: string;
      description: string;
      icon: React.ComponentType;
    }
  2. Add the id field to the new menu item:

    {
      id: 'query-cache',
      title: 'Query Cache',
      href: '/query-cache',
      description: 'Query cache usage',
      icon: DatabaseZapIcon,
    }

Would you like me to update the type definition in the PR, or do you prefer to handle it?

Comment on lines +18 to +25
const { data } = await fetchData<
{
total_result_size: number
total_staled_result_size: number
readable_total_result_size: string
readable_total_staled_result_size: string
}[]
>({ query })
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Handle potential errors from fetchData.

Consider adding error handling for the fetchData call to manage potential network or query issues gracefully.

>({ query })
const first = data?.[0]

if (!data || !first) return null
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Provide user feedback when data is not available.

Instead of returning null, consider rendering a message or a placeholder component to inform the user that no data is available.

Suggested change
if (!data || !first) return null
if (!data || !first) {
return <div>No data available</div>
}

components/charts/query-cache.tsx Outdated Show resolved Hide resolved
query,
result_size,
formatReadableSize(result_size) AS readable_result_size,
round(100 * result_size / max(result_size) OVER ()) AS pct_result_size,
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): Check for division by zero.

Ensure that max(result_size) is never zero to avoid potential division by zero errors.

expires_in: ColumnFormat.Duration,
},

relatedCharts: [['query-cache', {}]],
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Clarify the purpose of the empty object in relatedCharts.

If the empty object is intended for future use, consider adding a placeholder comment or a TODO to clarify its purpose.

>({ query })
const first = data?.[0]

if (!data || !first) return null
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!data || !first) return null
if (!data || !first) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Signed-off-by: Duyet Le <5009534+duyet@users.noreply.github.com>
@duyet duyet disabled auto-merge July 10, 2024 14:53
@duyet duyet merged commit 730ad57 into main Jul 10, 2024
12 checks passed
@duyet duyet deleted the chore/ui branch July 10, 2024 15:08
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.

Cache table
1 participant