Skip to content

feat: improve tenant diagnostics - CPU #2633

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

Merged
merged 11 commits into from
Jul 31, 2025
Merged

feat: improve tenant diagnostics - CPU #2633

merged 11 commits into from
Jul 31, 2025

Conversation

Raubzeug
Copy link
Contributor

@Raubzeug Raubzeug commented Jul 29, 2025

Stand

CI Results

Test Status: ⚠️ FLAKY

📊 Full Report

Total Passed Failed Flaky Skipped
354 350 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: 85.35 MB | Main: 85.35 MB
Diff: +3.95 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.

@Raubzeug Raubzeug linked an issue Jul 29, 2025 that may be closed by this pull request
Copy link
Member

@artemmufazalov artemmufazalov left a comment

Choose a reason for hiding this comment

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

Sorting in table is not descending

Screenshot 2025-07-29 at 17 11 52

const columns = React.useMemo(() => {
return getTenantOverviewTopQueriesColumns();
}, []);

const {currentData, isFetching, error} = topQueriesApi.useGetTopQueriesQuery(
{database: tenantName, timeFrame: 'hour', limit: TENANT_OVERVIEW_TABLES_LIMIT},
Copy link
Member

Choose a reason for hiding this comment

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

sortOrder is needed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, stand redeployed

@Raubzeug Raubzeug requested a review from artemmufazalov July 30, 2025 06:49
artemmufazalov
artemmufazalov previously approved these changes Jul 30, 2025
@astandrik
Copy link
Collaborator

bugbot run

Copy link
Contributor

@Copilot 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 improves the tenant diagnostics CPU section by simplifying the UI structure and enhancing the user experience. The main changes include replacing a complex tabbed interface with a unified dashboard layout and improving scroll position management for better navigation.

Key changes:

  • Replaced CPU tabs (nodes/shards/queries) with a unified vertical layout using StatsWrapper components
  • Extracted reusable QueriesTableWithDrawer component for better code reuse
  • Added scroll position persistence for the diagnostics overview tab

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/hooks/useScrollPosition.ts New hook for managing scroll position persistence using sessionStorage
src/containers/Tenant/Diagnostics/TenantOverview/TenantCpu/TenantCpu.tsx Complete refactor from tabbed to unified layout with StatsWrapper components
src/containers/Tenant/Diagnostics/TopQueries/QueriesTableWithDrawer.tsx New reusable component combining table and drawer functionality
src/containers/Tenant/Diagnostics/TenantOverview/StatsWrapper/StatsWrapper.tsx New wrapper component for consistent section layouts
src/components/SeeAllButton/SeeAllButton.tsx New reusable button component for navigation to detailed views
src/containers/Tenant/Diagnostics/TopQueries/columns/columns.tsx Refactored to use parameterized query text columns
src/containers/Tenant/Diagnostics/Diagnostics.tsx Added scroll position hook integration

import {debounce} from 'lodash';
import {useHistory} from 'react-router-dom';

const DEBAUNCE_DELAY = 100;
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The constant name 'DEBAUNCE_DELAY' contains a typo. It should be 'DEBOUNCE_DELAY'.

Suggested change
const DEBAUNCE_DELAY = 100;
const DEBOUNCE_DELAY = 100;

Copilot uses AI. Check for mistakes.

const queryHashColumn: Column<KeyValueRow> = {
name: QUERIES_COLUMNS_IDS.QueryHash,
header: QUERIES_COLUMNS_TITLES.QueryHash,
render: ({row}) => generateHash(String(row.QueryText)),
render: ({row}) => <div className={b('query-hash')}>{generateHash(String(row.QueryText))}</div>,
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Adding a wrapper div with CSS class for the query hash changes the column behavior. Consider if this styling change is necessary or if it should be handled differently to maintain consistency with other hash displays.

Suggested change
render: ({row}) => <div className={b('query-hash')}>{generateHash(String(row.QueryText))}</div>,
render: ({row}) => generateHash(String(row.QueryText)),

Copilot uses AI. Check for mistakes.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no bugs!


}
export function getRunningQueriesColumns() {
const columns = [
queryHashColumn,
userSIDColumn,
queryStartColumn,
queryTextColumn,
getQueryTextColumn(),
Copy link
Collaborator

@astandrik astandrik Jul 30, 2025

Choose a reason for hiding this comment

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

maybe create getRunningQueryTextColumn and getTopQueryTextColumn

I dont see that we use functions for columns - and current solution looks inconsistent

Copy link
Collaborator

Choose a reason for hiding this comment

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

@claude what do you think of it?

Copy link

@claude claude bot Jul 31, 2025

Choose a reason for hiding this comment

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

Claude finished @astandrik's task —— View job


@astandrik, I've analyzed the column patterns across the codebase, and I agree with your suggestion. Here's my analysis:

Current Codebase Patterns

After reviewing the column definitions across the codebase, I found that the established pattern is to use individual get*Column functions rather than parameterized functions. Examples:

  1. nodesColumns (src/components/nodesColumns/columns.tsx:37-94):

    • getNodeIdColumn()
    • getHostColumn()
    • getNetworkHostColumn() (different variant, not parameterized)
    • getDataCenterColumn()
  2. Operations (src/containers/Operations/columns.tsx:21-29):

    • Uses a single getColumns() function that builds all columns internally based on the kind parameter
    • Doesn't use parameterized individual column functions
  3. TopicData (src/containers/Tenant/Diagnostics/TopicData/columns/columns.tsx):

    • Exports individual column constants: offsetColumn, timestampCreateColumn, etc.
    • No parameterized column functions
  4. SchemaViewer (src/containers/Tenant/Schema/SchemaViewer/columns.tsx):

    • Also uses individual column constants: idColumn, nameColumn, etc.

Recommendation

The current PR approach of having separate functions would be more consistent:

  • getRunningQueryTextColumn()
  • getTopQueryTextColumn()

This follows the established pattern in the codebase where different column variants get their own functions rather than using parameters. The getNetworkHostColumn() vs getHostColumn() example from nodesColumns is a good precedent for this approach.

The parameterized approach would be a departure from the existing patterns and might make the codebase less consistent overall.

Todo:

  • Read the current columns.tsx implementation
  • Search for other column patterns in the codebase
  • Provide feedback on the consistency question

@Raubzeug
Copy link
Contributor Author

Stand redeployed

@Raubzeug Raubzeug enabled auto-merge July 31, 2025 10:50
@Raubzeug Raubzeug requested a review from astandrik July 31, 2025 12:17
Copy link

claude bot commented Jul 31, 2025

Claude finished @Raubzeug's task —— View job


Code Review Summary

I've completed my review of this PR that refactors the tenant diagnostics CPU section. Here are my findings:

✅ Strengths

  1. Good architectural refactoring: The move from tabbed interface to unified vertical layout with StatsWrapper components improves code reusability and UX consistency.

  2. Proper component extraction: The new QueriesTableWithDrawer component effectively consolidates table and drawer functionality, reducing code duplication.

  3. Correct API patterns: All API calls properly use window.api through RTK Query's injectEndpoints pattern (src/store/reducers/executeTopQueries/executeTopQueries.ts:127).

  4. Good i18n implementation: New components properly use i18n for user-facing text (e.g., SeeAllButton component).

  5. Performance considerations: Components use React optimization hooks appropriately (useCallback, useMemo).

🔍 Issues to Address

  1. Typo in constant name (src/utils/hooks/useScrollPosition.ts:6):

    const DEBAUNCE_DELAY = 100; // Should be DEBOUNCE_DELAY
  2. Hardcoded strings in column renderers (src/containers/Tenant/Diagnostics/TopQueries/columns/columns.tsx:84,123):

    {row.UserSID || '–'}  // Should use i18n for the dash
    {row.ApplicationName || '–'}  // Should use i18n for the dash
  3. Console warnings not internationalized (src/utils/hooks/useScrollPosition.ts:27,39,59):

    • Console warnings are developer-facing and don't need i18n, but consider if these should be in production code at all.
  4. Column function inconsistency: As noted by @astandrik, the parameterized column functions could be split into getRunningQueryTextColumn and getTopQueryTextColumn for better consistency with the codebase patterns.

  5. Scroll position hook complexity: The useScrollPosition hook is quite complex for its limited use case (back/forward navigation only). Consider if anchors would be a simpler solution as suggested by @astandrik.

📋 Recommendations

  1. Fix the typo in DEBAUNCE_DELAYDEBOUNCE_DELAY.
  2. Consider extracting the empty value dash ('–') to a constant or i18n entry.
  3. Evaluate if the scroll position hook complexity is justified for the use case.
  4. Consider splitting the column functions as suggested for consistency.

✅ All Critical Requirements Met

  • ✅ TypeScript type safety with proper interfaces
  • ✅ React best practices and Gravity UI components
  • ✅ Redux Toolkit patterns with RTK Query
  • ✅ BEM naming convention with cn() utility
  • ✅ API calls through window.api
  • ✅ No state mutations in RTK Query
  • ✅ Proper loading states and error handling

The PR significantly improves the code structure and user experience. The issues found are minor and don't block the functionality.

@astandrik
Copy link
Collaborator

@claude actually some you addressed are already fixed

@Raubzeug Raubzeug added this pull request to the merge queue Jul 31, 2025
Copy link

claude bot commented Jul 31, 2025

Claude finished @astandrik's task —— View job


Thanks for the clarification @astandrik! I've checked the current state of the code and you're right - some issues have been fixed.

✅ Issues Already Fixed

  1. DEBOUNCE_DELAY typo - Fixed! The constant is now correctly spelled in src/utils/hooks/useScrollPosition.ts:6

  2. CPU Cores column alignment - Fixed! Changed to DataTable.LEFT in src/components/ShardsTable/columns.tsx

🔍 Remaining Issues

  1. Hardcoded '–' strings (src/containers/Tenant/Diagnostics/TopQueries/columns/columns.tsx:84,123):

    {row.UserSID || '–'}
    {row.ApplicationName || '–'}

    These could use the existing EMPTY_DATA_PLACEHOLDER constant or be added to i18n. However, this is a minor issue that doesn't block functionality.

  2. Console warnings (src/utils/hooks/useScrollPosition.ts:27,39,59):

    • These are developer-facing console warnings and don't need i18n
    • Consider if these warnings should be in production code at all

📊 Overall Assessment

The PR successfully improves the tenant diagnostics CPU section with:

  • Better architectural patterns (StatsWrapper, QueriesTableWithDrawer)
  • Proper i18n for new components
  • Cleaner code structure without the complex tabbed interface
  • Good adherence to the codebase conventions

The remaining issues are minor and don't affect the functionality. Great work on the refactoring!

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jul 31, 2025
@Raubzeug Raubzeug added this pull request to the merge queue Jul 31, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jul 31, 2025
@astandrik astandrik added this pull request to the merge queue Jul 31, 2025
Merged via the queue into main with commit 84e75ea Jul 31, 2025
13 checks passed
@astandrik astandrik deleted the cpu-redesign branch July 31, 2025 16:45
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.

Improve CPU section in Tenant - Diagnostics - Info
3 participants