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

fix: fix top queries table row height #565

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"axios": "0.19.2",
"bem-cn-lite": "4.0.0",
"copy-to-clipboard": "^3.3.3",
"crc-32": "^1.2.2",
"history": "4.10.1",
"js-cookie": "2.2.1",
"lodash": "4.17.11",
Expand Down
8 changes: 8 additions & 0 deletions src/components/TruncatedQuery/TruncatedQuery.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@
}
}
}

&__popover-content {
overflow: hidden;

max-width: 600px;

white-space: pre;
}
}
16 changes: 15 additions & 1 deletion src/components/TruncatedQuery/TruncatedQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import cn from 'bem-cn-lite';

import {CellWithPopover} from '../CellWithPopover/CellWithPopover';

import './TruncatedQuery.scss';

const b = cn('kv-truncated-query');

interface TruncatedQueryProps {
value: string | undefined;
value?: string;
maxQueryHeight?: number;
}

Expand All @@ -26,3 +28,15 @@ export const TruncatedQuery = ({value = '', maxQueryHeight = 6}: TruncatedQueryP
}
return <>{value}</>;
};

interface OneLineQueryWithPopoverProps {
value?: string;
}

export const OneLineQueryWithPopover = ({value = ''}: OneLineQueryWithPopoverProps) => {
return (
<CellWithPopover contentClassName={b('popover-content')} content={value}>
{value}
</CellWithPopover>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import qs from 'qs';
import {useDispatch} from 'react-redux';
import {useHistory, useLocation} from 'react-router';
import {useCallback} from 'react';
Expand All @@ -14,6 +13,7 @@ import {
} from '../../../../../store/reducers/tenantOverview/topQueries/tenantOverviewTopQueries';
import {changeUserInput} from '../../../../../store/reducers/executeQuery';
import {useAutofetcher, useTypedSelector} from '../../../../../utils/hooks';
import {parseQuery} from '../../../../../routes';
import {TenantTabsGroups, getTenantPath} from '../../../TenantPages';
import {getTenantOverviewTopQueriesColumns} from '../../TopQueries/getTopQueriesColumns';
import {TenantOverviewTableLayout} from '../TenantOverviewTableLayout';
Expand Down Expand Up @@ -55,9 +55,7 @@ export function TopQueries({path}: TopQueriesProps) {

dispatch(changeUserInput({input}));

const queryParams = qs.parse(location.search, {
ignoreQueryPrefix: true,
});
const queryParams = parseQuery(location);

const queryPath = getTenantPath({
...queryParams,
Expand Down
8 changes: 7 additions & 1 deletion src/containers/Tenant/Diagnostics/TopQueries/TopQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {useAutofetcher, useTypedSelector} from '../../../../utils/hooks';
import {prepareQueryError} from '../../../../utils/query';
import {parseQuery} from '../../../../routes';
import {QUERY_TABLE_SETTINGS} from '../../utils/constants';
import {isSortableTopQueriesProperty} from '../../../../utils/diagnostics';
import {isColumnEntityType} from '../../utils/schema';
import {TenantTabsGroups, getTenantPath} from '../../TenantPages';
import {getTopQueriesColumns} from './getTopQueriesColumns';
Expand Down Expand Up @@ -58,7 +59,7 @@ export const TopQueries = ({path, type}: TopQueriesProps) => {
data: {result: data = undefined} = {},
filters: storeFilters,
} = useTypedSelector((state) => state.executeTopQueries);
const columns = getTopQueriesColumns();
const rawColumns = getTopQueriesColumns();

const preventFetch = useRef(false);

Expand All @@ -71,6 +72,11 @@ export const TopQueries = ({path, type}: TopQueriesProps) => {
dispatch(setTopQueriesFilters(filters));
}, [dispatch, filters]);

const columns = rawColumns.map((column) => ({
...column,
sortable: isSortableTopQueriesProperty(column.name),
}));

const setDefaultFiltersFromResponse = (responseData?: IQueryResult) => {
const intervalEnd = responseData?.result?.[0]?.IntervalEnd;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import DataTable, {type Column} from '@gravity-ui/react-data-table';

import type {KeyValueRow} from '../../../../types/api/query';
import {formatDateTime, formatNumber} from '../../../../utils/dataFormatters/dataFormatters';
import {TruncatedQuery} from '../../../../components/TruncatedQuery/TruncatedQuery';
import {generateHash} from '../../../../utils/generateHash';
import {
TruncatedQuery,
OneLineQueryWithPopover,
} from '../../../../components/TruncatedQuery/TruncatedQuery';
import {MAX_QUERY_HEIGHT} from '../../utils/constants';

import './TopQueries.scss';
Expand All @@ -18,6 +22,8 @@ const TOP_QUERIES_COLUMNS_IDS = {
ReadRows: 'ReadRows',
ReadBytes: 'ReadBytes',
UserSID: 'UserSID',
OneLineQueryText: 'OneLineQueryText',
QueryHash: 'QueryHash',
};

const cpuTimeUsColumn: Column<KeyValueRow> = {
Expand Down Expand Up @@ -66,6 +72,20 @@ const userSIDColumn: Column<KeyValueRow> = {
align: DataTable.LEFT,
};

const oneLineQueryTextColumn: Column<KeyValueRow> = {
name: TOP_QUERIES_COLUMNS_IDS.OneLineQueryText,
header: 'QueryText',
render: ({row}) => <OneLineQueryWithPopover value={row.QueryText?.toString()} />,
sortable: false,
};

const queryHashColumn: Column<KeyValueRow> = {
name: TOP_QUERIES_COLUMNS_IDS.QueryHash,
render: ({row}) => generateHash(String(row.QueryText)),
width: 130,
sortable: false,
};

export const getTopQueriesColumns = (): Column<KeyValueRow>[] => {
return [
cpuTimeUsColumn,
Expand All @@ -78,5 +98,5 @@ export const getTopQueriesColumns = (): Column<KeyValueRow>[] => {
};

export const getTenantOverviewTopQueriesColumns = (): Column<KeyValueRow>[] => {
return [queryTextColumn, cpuTimeUsColumn];
return [queryHashColumn, oneLineQueryTextColumn, cpuTimeUsColumn];
};
16 changes: 14 additions & 2 deletions src/utils/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import {ValueOf} from '../types/common';

export const TOP_SHARDS_SORT_VALUES = {
const TOP_SHARDS_SORT_VALUES = {
CPUCores: 'CPUCores',
DataSize: 'DataSize',
} as const;

export type TopShardsSortValue = ValueOf<typeof TOP_SHARDS_SORT_VALUES>;
const TOP_QUERIES_SORT_VALUES = {
CPUTimeUs: 'CPUTimeUs',
EndTime: 'EndTime',
ReadRows: 'ReadRows',
ReadBytes: 'ReadBytes',
UserSID: 'UserSID',
} as const;

type TopShardsSortValue = ValueOf<typeof TOP_SHARDS_SORT_VALUES>;
type TopQueriesSortValue = ValueOf<typeof TOP_QUERIES_SORT_VALUES>;

export const isSortableTopShardsProperty = (value: string): value is TopShardsSortValue =>
Object.values(TOP_SHARDS_SORT_VALUES).includes(value as TopShardsSortValue);

export const isSortableTopQueriesProperty = (value: string): value is TopQueriesSortValue =>
Object.values(TOP_QUERIES_SORT_VALUES).includes(value as TopQueriesSortValue);
11 changes: 11 additions & 0 deletions src/utils/generateHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import crc32 from 'crc-32';

export const generateHash = (value: string) => {
// 1. crc32.str(value) - generate crc32 hash
// 2. (>>>) - use unsigned right shift operator (>>>) to avoid negative values
// 3. toString(16) - convert hash to hex format
// 4. toUpperCase() - convert hash to uppercase
// 5. padStart(8, '0') - fill hash with leading zeros if hash length < 8
// eslint-disable-next-line no-bitwise
return (crc32.str(value) >>> 0).toString(16).toUpperCase().padStart(8, '0');
};
Loading