Skip to content

Commit 03608f1

Browse files
authored
feat: add data sorting to TopQueries table (#1028)
1 parent e1c8f83 commit 03608f1

File tree

5 files changed

+46
-48
lines changed

5 files changed

+46
-48
lines changed

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
window.systemSettings = {};
2424
window.userSettings = {};
2525
window.web_version = !'%REACT_APP_BACKEND%';
26-
window.custom_backend = '%NODE_ENV%' === 'development' && '%REACT_APP_BACKEND%' ;
26+
window.custom_backend = '%NODE_ENV%' === 'development' && '%REACT_APP_BACKEND%';
2727
window.meta_backend = '%REACT_APP_META_BACKEND%'
2828
</script>
2929
</head>

src/containers/Tenant/Diagnostics/TopQueries/getTopQueriesColumns.tsx

+5-15
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import {
88
import type {KeyValueRow} from '../../../../types/api/query';
99
import {cn} from '../../../../utils/cn';
1010
import {formatDateTime, formatNumber} from '../../../../utils/dataFormatters/dataFormatters';
11+
import {TOP_QUERIES_COLUMNS_IDS} from '../../../../utils/diagnostics';
1112
import {generateHash} from '../../../../utils/generateHash';
12-
import {parseUsToMs} from '../../../../utils/timeParsers';
13+
import {formatToMs, parseUsToMs} from '../../../../utils/timeParsers';
1314
import {MAX_QUERY_HEIGHT} from '../../utils/constants';
1415

1516
import './TopQueries.scss';
@@ -18,21 +19,10 @@ const b = cn('kv-top-queries');
1819

1920
export const TOP_QUERIES_COLUMNS_WIDTH_LS_KEY = 'topQueriesColumnsWidth';
2021

21-
const TOP_QUERIES_COLUMNS_IDS = {
22-
CPUTimeUs: 'CPUTimeUs',
23-
QueryText: 'QueryText',
24-
EndTime: 'EndTime',
25-
ReadRows: 'ReadRows',
26-
ReadBytes: 'ReadBytes',
27-
UserSID: 'UserSID',
28-
OneLineQueryText: 'OneLineQueryText',
29-
QueryHash: 'QueryHash',
30-
Duration: 'Duration',
31-
};
32-
3322
const cpuTimeUsColumn: Column<KeyValueRow> = {
3423
name: TOP_QUERIES_COLUMNS_IDS.CPUTimeUs,
3524
sortAccessor: (row) => Number(row.CPUTimeUs),
25+
render: ({row}) => formatToMs(parseUsToMs(row.CPUTimeUs ?? undefined)),
3626
width: 120,
3727
align: DataTable.RIGHT,
3828
sortable: false,
@@ -97,8 +87,8 @@ const queryHashColumn: Column<KeyValueRow> = {
9787

9888
const durationColumn: Column<KeyValueRow> = {
9989
name: TOP_QUERIES_COLUMNS_IDS.Duration,
100-
header: 'Duration, ms',
101-
render: ({row}) => formatNumber(parseUsToMs(row.Duration ?? undefined)),
90+
header: 'Duration',
91+
render: ({row}) => formatToMs(parseUsToMs(row.Duration ?? undefined)),
10292
sortAccessor: (row) => Number(row.Duration),
10393
align: DataTable.RIGHT,
10494
width: 150,

src/containers/Tenant/Diagnostics/TopShards/TopShards.tsx

+4-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {EPathType} from '../../../../types/api/schema';
1717
import {cn} from '../../../../utils/cn';
1818
import {DEFAULT_TABLE_SETTINGS, HOUR_IN_SECONDS} from '../../../../utils/constants';
1919
import {formatDateTime} from '../../../../utils/dataFormatters/dataFormatters';
20-
import {isSortableTopShardsProperty} from '../../../../utils/diagnostics';
20+
import {TOP_SHARD_COLUMNS_IDS, isSortableTopShardsProperty} from '../../../../utils/diagnostics';
2121
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../../../utils/hooks';
2222
import {parseQueryErrorToString} from '../../../../utils/query';
2323
import {isColumnEntityType} from '../../utils/schema';
@@ -38,17 +38,6 @@ const TABLE_SETTINGS: Settings = {
3838
defaultOrder: DataTable.DESCENDING,
3939
};
4040

41-
const tableColumnsNames = {
42-
TabletId: 'TabletId',
43-
CPUCores: 'CPUCores',
44-
DataSize: 'DataSize',
45-
Path: 'Path',
46-
NodeId: 'NodeId',
47-
PeakTime: 'PeakTime',
48-
InFlightTxCount: 'InFlightTxCount',
49-
IntervalEnd: 'IntervalEnd',
50-
};
51-
5241
function prepareDateTimeValue(value: CellValue) {
5342
if (!value) {
5443
return '–';
@@ -115,7 +104,7 @@ export const TopShards = ({tenantName, path, type}: TopShardsProps) => {
115104
return defaultValue;
116105
});
117106

118-
const [sortOrder, setSortOrder] = React.useState(tableColumnsNames.CPUCores);
107+
const [sortOrder, setSortOrder] = React.useState(TOP_SHARD_COLUMNS_IDS.CPUCores);
119108
const {
120109
data: result,
121110
isFetching,
@@ -171,14 +160,14 @@ export const TopShards = ({tenantName, path, type}: TopShardsProps) => {
171160
if (filters.mode === EShardsWorkloadMode.History) {
172161
// after NodeId
173162
columns.splice(5, 0, {
174-
name: tableColumnsNames.PeakTime,
163+
name: TOP_SHARD_COLUMNS_IDS.PeakTime,
175164
render: ({row}) => {
176165
return prepareDateTimeValue(row.PeakTime);
177166
},
178167
sortable: false,
179168
});
180169
columns.push({
181-
name: tableColumnsNames.IntervalEnd,
170+
name: TOP_SHARD_COLUMNS_IDS.IntervalEnd,
182171
render: ({row}) => {
183172
return prepareDateTimeValue(row.IntervalEnd);
184173
},

src/store/reducers/executeTopQueries/executeTopQueries.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SELECT
3737
Duration
3838
FROM \`${path}/.sys/top_queries_by_cpu_time_one_hour\`
3939
WHERE ${filterConditions || 'true'}
40+
ORDER BY CPUTimeUs DESC
4041
`;
4142
};
4243

src/utils/diagnostics.ts

+35-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1-
import type {ValueOf} from '../types/common';
2-
3-
const TOP_SHARDS_SORT_VALUES = {
4-
CPUCores: 'CPUCores',
5-
DataSize: 'DataSize',
6-
InFlightTxCount: 'InFlightTxCount',
7-
} as const;
8-
9-
const TOP_QUERIES_SORT_VALUES = {
10-
CPUTimeUs: 'CPUTimeUs',
1+
export const TOP_QUERIES_COLUMNS_IDS = {
2+
CPUTimeUs: 'CPUTime',
3+
QueryText: 'QueryText',
114
EndTime: 'EndTime',
125
ReadRows: 'ReadRows',
136
ReadBytes: 'ReadBytes',
147
UserSID: 'UserSID',
8+
OneLineQueryText: 'OneLineQueryText',
9+
QueryHash: 'QueryHash',
1510
Duration: 'Duration',
16-
} as const;
11+
};
12+
13+
export const TOP_SHARD_COLUMNS_IDS = {
14+
TabletId: 'TabletId',
15+
CPUCores: 'CPUCores',
16+
DataSize: 'DataSize',
17+
Path: 'Path',
18+
NodeId: 'NodeId',
19+
PeakTime: 'PeakTime',
20+
InFlightTxCount: 'InFlightTxCount',
21+
IntervalEnd: 'IntervalEnd',
22+
};
23+
24+
const TOP_SHARDS_SORT_VALUES = [
25+
TOP_SHARD_COLUMNS_IDS.CPUCores,
26+
TOP_SHARD_COLUMNS_IDS.DataSize,
27+
TOP_SHARD_COLUMNS_IDS.InFlightTxCount,
28+
];
1729

18-
type TopShardsSortValue = ValueOf<typeof TOP_SHARDS_SORT_VALUES>;
19-
type TopQueriesSortValue = ValueOf<typeof TOP_QUERIES_SORT_VALUES>;
30+
const TOP_QUERIES_SORT_VALUES = [
31+
TOP_QUERIES_COLUMNS_IDS.CPUTimeUs,
32+
TOP_QUERIES_COLUMNS_IDS.EndTime,
33+
TOP_QUERIES_COLUMNS_IDS.ReadRows,
34+
TOP_QUERIES_COLUMNS_IDS.ReadBytes,
35+
TOP_QUERIES_COLUMNS_IDS.UserSID,
36+
TOP_QUERIES_COLUMNS_IDS.Duration,
37+
];
2038

21-
export const isSortableTopShardsProperty = (value: string): value is TopShardsSortValue =>
22-
Object.values(TOP_SHARDS_SORT_VALUES).includes(value as TopShardsSortValue);
39+
export const isSortableTopShardsProperty = (value: string) =>
40+
Object.values(TOP_SHARDS_SORT_VALUES).includes(value);
2341

24-
export const isSortableTopQueriesProperty = (value: string): value is TopQueriesSortValue =>
25-
Object.values(TOP_QUERIES_SORT_VALUES).includes(value as TopQueriesSortValue);
42+
export const isSortableTopQueriesProperty = (value: string) =>
43+
Object.values(TOP_QUERIES_SORT_VALUES).includes(value);

0 commit comments

Comments
 (0)