Skip to content

Conversation

@Raubzeug
Copy link
Contributor

@Raubzeug Raubzeug commented Dec 15, 2025

Greptile Overview

Greptile Summary

This PR introduces a new hook useDatabasesV2 that adds an additional check for the use_meta_proxy cluster setting before using meta databases handlers, ensuring that database operations only use the meta proxy when it's both available and enabled in cluster settings.

Key changes:

  • Created useDatabasesV2 hook that combines useDatabasesAvailable capability check with use_meta_proxy setting check
  • Fixed MetaAPI.getTenants to never proxy the /meta/cp_databases endpoint to clusters (removed clusterName from path)
  • Updated TenantNameWrapper to consider use_meta_proxy setting when deciding whether to use database IDs vs names
  • Replaced all usages of useDatabasesAvailable with useDatabasesV2 across 6 components for consistency

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-structured and follow a clear pattern of centralizing the database availability check logic. The new hook properly combines two related checks (capability + setting), and the fix to the API path ensures correct backend routing. All changes are consistent and follow existing code patterns.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/utils/hooks/useDatabasesV2.ts 5/5 New hook that wraps useDatabasesAvailable with additional check for use_meta_proxy setting
src/services/api/meta.ts 5/5 Fixed getTenants to never proxy to cluster (removed clusterName from path), maintaining consistency with backend API design
src/components/TenantNameWrapper/TenantNameWrapper.tsx 5/5 Updated to use useDatabaseId based on both uiFactory.useDatabaseId and use_meta_proxy setting, ensuring consistent database ID usage

Sequence Diagram

sequenceDiagram
    participant Component as React Component
    participant useDatabasesV2 as useDatabasesV2 Hook
    participant useClusterBaseInfo as useClusterBaseInfo Hook
    participant useDatabasesAvailable as useDatabasesAvailable Hook
    participant MetaAPI as MetaAPI.getTenants

    Component->>useDatabasesV2: Call hook
    useDatabasesV2->>useClusterBaseInfo: Get cluster settings
    useClusterBaseInfo-->>useDatabasesV2: Return {settings}
    useDatabasesV2->>useDatabasesAvailable: Check if meta databases available
    useDatabasesAvailable-->>useDatabasesV2: Return capability status
    useDatabasesV2->>useDatabasesV2: Check: settings?.use_meta_proxy !== false && isMetaDatabasesAvailable
    useDatabasesV2-->>Component: Return boolean (use databases v2)
    
    Component->>MetaAPI: getTenants({clusterName, database})
    Note over MetaAPI: Path: /meta/cp_databases (no cluster proxy)
    MetaAPI-->>Component: Return tenant data
Loading

CI Results

Test Status: ⚠️ FLAKY

📊 Full Report

Total Passed Failed Flaky Skipped
384 380 0 2 2
Test Changes Summary ⏭️2

⏭️ Skipped Tests (2)

  1. Scroll to row, get shareable link, navigate to URL and verify row is scrolled into view (tenant/diagnostics/tabs/queries.test.ts)
  2. Copy result button copies to clipboard (tenant/queryEditor/queryEditor.test.ts)

Bundle Size: ✅

Current: 62.51 MB | Main: 62.51 MB
Diff: +1.12 KB (0.00%)

✅ Bundle size unchanged.

ℹ️ CI Information
  • Test recordings for failed tests are available in the full report.
  • Bundle size is measured for the entire 'dist' directory.
  • 📊 indicates links to detailed reports.
  • 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.

Copilot AI review requested due to automatic review settings December 15, 2025 10:37
@Raubzeug Raubzeug enabled auto-merge December 15, 2025 10:39
@Raubzeug Raubzeug added this pull request to the merge queue Dec 15, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

8 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new hook useDatabasesV2 that combines checks for both the use_meta_proxy cluster setting and meta databases availability. The hook replaces direct usage of useDatabasesAvailable across multiple components to ensure database handlers are called correctly based on cluster configuration.

Key changes:

  • Introduces useDatabasesV2 hook that checks both use_meta_proxy setting and databases availability
  • Replaces useDatabasesAvailable with useDatabasesV2 across 6 components/files
  • Fixes API path for cp_databases to prevent proxying to cluster

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/utils/hooks/useDatabasesV2.ts New hook that combines use_meta_proxy setting check with databases availability check
src/store/reducers/tenant/tenant.ts Updates import and usage to use new useDatabasesV2 hook instead of useDatabasesAvailable
src/services/api/meta.ts Removes cluster name from cp_databases API path to prevent proxying to cluster
src/containers/Tenants/Tenants.tsx Updates to use useDatabasesV2 hook for determining database handler availability
src/containers/Tenant/Diagnostics/TenantOverview/TenantOverview.tsx Updates to use useDatabasesV2 hook for tenant info queries
src/containers/Header/Header.tsx Updates to use useDatabasesV2 hook in header component
src/components/TenantNameWrapper/TenantNameWrapper.tsx Updates to use useDatabasesV2 logic inline by extracting settings and checking use_meta_proxy
src/components/ConnectToDB/ConnectToDBDialog.tsx Updates to use useDatabasesV2 hook for database connection info
Comments suppressed due to low confidence (1)

src/components/TenantNameWrapper/TenantNameWrapper.tsx:46

  • The hook useClusterBaseInfo is being called twice in this component - once on line 40 to get settings, and again on line 46 to get monitoring. This creates unnecessary duplicate hook calls and could impact performance.

Consider destructuring both values from a single call to useClusterBaseInfo.

    const {settings} = useClusterBaseInfo();

    const backend = getTenantBackend(tenant, additionalTenantsProps);
    const isExternalLink = Boolean(backend);

    const links = getDatabaseLinks(additionalTenantsProps, tenant?.Name, tenant?.Type);
    const {monitoring: clusterMonitoring} = useClusterBaseInfo();

Comment on lines +3 to +8

export function useDatabasesV2() {
const {settings} = useClusterBaseInfo();
const isMetaDatabasesAvailable = useDatabasesAvailable();

return settings?.use_meta_proxy !== false && isMetaDatabasesAvailable;
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The return value of this hook should be memoized using useMemo to prevent unnecessary re-renders. The hook currently returns a newly computed boolean value on every render, even when the dependencies haven't changed. This is particularly important since this hook is used in multiple components that may render frequently (Tenants, Header, TenantOverview, etc.).

The computation involves property access and logical operations that should be memoized according to the project's React performance guidelines.

Suggested change
export function useDatabasesV2() {
const {settings} = useClusterBaseInfo();
const isMetaDatabasesAvailable = useDatabasesAvailable();
return settings?.use_meta_proxy !== false && isMetaDatabasesAvailable;
import {useMemo} from 'react';
export function useDatabasesV2() {
const {settings} = useClusterBaseInfo();
const isMetaDatabasesAvailable = useDatabasesAvailable();
return useMemo(
() => settings?.use_meta_proxy !== false && isMetaDatabasesAvailable,
[settings?.use_meta_proxy, isMetaDatabasesAvailable],
);

Copilot uses AI. Check for mistakes.
Merged via the queue into main with commit 79d11f0 Dec 15, 2025
13 checks passed
@Raubzeug Raubzeug deleted the databases branch December 15, 2025 10:41
Raubzeug added a commit that referenced this pull request Dec 15, 2025
@greptile-apps greptile-apps bot mentioned this pull request Dec 15, 2025
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.

3 participants