Skip to content

Commit ed0fdd5

Browse files
feat: add QUERY_TECHNICAL_MARK to all UI queries
1 parent 9ac8cfc commit ed0fdd5

File tree

6 files changed

+41
-31
lines changed

6 files changed

+41
-31
lines changed

src/store/reducers/cluster/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import type {TClusterInfoV2, TStorageStats} from '../../../types/api/cluster';
22
import type {ExecuteQueryResponse, KeyValueRow} from '../../../types/api/query';
3+
import {QUERY_TECHNICAL_MARK} from '../../../utils/constants';
34
import {parseQueryAPIResponse} from '../../../utils/query';
45

56
import type {ClusterGroupsStats} from './types';
67

78
export const createSelectClusterGroupsQuery = (clusterRoot: string) => {
8-
return `
9+
return `${QUERY_TECHNICAL_MARK}
910
SELECT
1011
PDiskFilter,
1112
ErasureSpecies,
1213
CurrentAvailableSize,
1314
CurrentAllocatedSize,
1415
CurrentGroupsCreated,
1516
AvailableGroupsToCreate
16-
FROM \`${clusterRoot}/.sys/ds_storage_stats\`
17-
ORDER BY CurrentGroupsCreated DESC;
17+
FROM \`${clusterRoot}/.sys/ds_storage_stats\`
18+
ORDER BY CurrentGroupsCreated DESC;
1819
`;
1920
};
2021

src/store/reducers/executeTopQueries/executeTopQueries.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {SortOrder} from '@gravity-ui/react-data-table';
33
import {createSlice} from '@reduxjs/toolkit';
44
import type {PayloadAction} from '@reduxjs/toolkit';
55

6+
import {QUERY_TECHNICAL_MARK} from '../../../utils/constants';
67
import {prepareOrderByFromTableSort} from '../../../utils/hooks/useTableSort';
78
import {isQueryErrorResponse, parseQueryAPIResponse} from '../../../utils/query';
89
import {api} from '../api';
@@ -12,8 +13,6 @@ import {getFiltersConditions} from './utils';
1213

1314
const initialState: TopQueriesFilters = {};
1415

15-
const QUERY_TECHNICAL_MARK = '/*UI-QUERY-EXCLUDE*/';
16-
1716
const slice = createSlice({
1817
name: 'executeTopQueries',
1918
initialState,
@@ -32,8 +31,8 @@ const getQueryText = (path: string, filters?: TopQueriesFilters, sortOrder?: Sor
3231

3332
const orderBy = prepareOrderByFromTableSort(sortOrder);
3433

35-
return `
36-
SELECT ${QUERY_TECHNICAL_MARK}
34+
return `${QUERY_TECHNICAL_MARK}
35+
SELECT
3736
CPUTime as CPUTimeUs,
3837
QueryText,
3938
IntervalEnd,
@@ -49,6 +48,25 @@ LIMIT 100
4948
`;
5049
};
5150

51+
function getRunningQueriesText(path: string, filters?: TopQueriesFilters, sortOrder?: SortOrder[]) {
52+
const filterConditions = filters?.text
53+
? `Query ILIKE '%${filters.text}%' OR UserSID ILIKE '%${filters.text}%'`
54+
: '';
55+
56+
const orderBy = prepareOrderByFromTableSort(sortOrder);
57+
58+
return `${QUERY_TECHNICAL_MARK}
59+
SELECT
60+
UserSID,
61+
QueryStartAt,
62+
Query as QueryText,
63+
ApplicationName
64+
FROM \`${path}/.sys/query_sessions\`
65+
WHERE ${filterConditions || 'true'} AND Query NOT LIKE '%${QUERY_TECHNICAL_MARK}%'
66+
${orderBy}
67+
LIMIT 100`;
68+
}
69+
5270
interface TopQueriesRequestParams {
5371
database: string;
5472
filters?: TopQueriesFilters;
@@ -102,24 +120,9 @@ export const topQueriesApi = api.injectEndpoints({
102120
getRunningQueries: build.query({
103121
queryFn: async ({database, filters, sortOrder}: TopQueriesRequestParams, {signal}) => {
104122
try {
105-
const filterConditions = filters?.text
106-
? `Query ILIKE '%${filters.text}%' OR UserSID ILIKE '%${filters.text}%'`
107-
: '';
108-
109-
const orderBy = prepareOrderByFromTableSort(sortOrder);
110-
111-
const queryText = `SELECT ${QUERY_TECHNICAL_MARK}
112-
UserSID, QueryStartAt, Query as QueryText, ApplicationName
113-
FROM
114-
\`.sys/query_sessions\`
115-
WHERE
116-
${filterConditions || 'true'} AND Query NOT LIKE '%${QUERY_TECHNICAL_MARK}%'
117-
${orderBy}
118-
LIMIT 100`;
119-
120123
const response = await window.api.viewer.sendQuery(
121124
{
122-
query: queryText,
125+
query: getRunningQueriesText(database, filters, sortOrder),
123126
database,
124127
action: 'execute-scan',
125128
},

src/store/reducers/shardsWorkload/shardsWorkload.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {SortOrder} from '@gravity-ui/react-data-table';
33
import {createSlice} from '@reduxjs/toolkit';
44
import type {PayloadAction} from '@reduxjs/toolkit';
55

6+
import {QUERY_TECHNICAL_MARK} from '../../../utils/constants';
67
import {prepareOrderByFromTableSort} from '../../../utils/hooks/useTableSort';
78
import {isQueryErrorResponse, parseQueryAPIResponse} from '../../../utils/query';
89
import {api} from '../api';
@@ -54,7 +55,8 @@ function createShardQueryHistorical(
5455

5556
const orderBy = prepareOrderByFromTableSort(sortOrder);
5657

57-
return `SELECT
58+
return `${QUERY_TECHNICAL_MARK}
59+
SELECT
5860
${pathSelect},
5961
TabletId,
6062
CPUCores,
@@ -76,7 +78,8 @@ function createShardQueryImmediate(path: string, sortOrder?: SortOrder[], tenant
7678

7779
const orderBy = prepareOrderByFromTableSort(sortOrder);
7880

79-
return `SELECT
81+
return `${QUERY_TECHNICAL_MARK}
82+
SELECT
8083
${pathSelect},
8184
TabletId,
8285
CPUCores,

src/store/reducers/tenantOverview/executeTopTables/executeTopTables.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../utils/constants';
1+
import {QUERY_TECHNICAL_MARK, TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../utils/constants';
22
import {isQueryErrorResponse, parseQueryAPIResponse} from '../../../../utils/query';
33
import {api} from '../../api';
44

55
const getQueryText = (path: string) => {
6-
return `
6+
return `${QUERY_TECHNICAL_MARK}
77
SELECT
88
Path, SUM(DataSize) as Size
99
FROM \`${path}/.sys/partition_stats\`
1010
GROUP BY Path
11-
ORDER BY Size DESC
12-
LIMIT ${TENANT_OVERVIEW_TABLES_LIMIT}
11+
ORDER BY Size DESC
12+
LIMIT ${TENANT_OVERVIEW_TABLES_LIMIT}
1313
`;
1414
};
1515

src/store/reducers/tenantOverview/topShards/tenantOverviewTopShards.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../utils/constants';
1+
import {QUERY_TECHNICAL_MARK, TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../utils/constants';
22
import {isQueryErrorResponse, parseQueryAPIResponse} from '../../../../utils/query';
33
import {api} from '../../api';
44

@@ -7,7 +7,8 @@ function createShardQuery(path: string, tenantName?: string) {
77
? `CAST(SUBSTRING(CAST(Path AS String), ${tenantName.length}) AS Utf8) AS Path`
88
: 'Path';
99

10-
return `SELECT
10+
return `${QUERY_TECHNICAL_MARK}
11+
SELECT
1112
${pathSelect},
1213
TabletId,
1314
CPUCores,

src/utils/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export const TENANT_OVERVIEW_TABLES_LIMIT = 5;
5252

5353
export const EMPTY_DATA_PLACEHOLDER = '—';
5454

55+
export const QUERY_TECHNICAL_MARK = '/*UI-QUERY-EXCLUDE*/';
56+
5557
// ==== Titles ====
5658
export const DEVELOPER_UI_TITLE = 'Developer UI';
5759
export const CLUSTER_DEFAULT_TITLE = 'Cluster';

0 commit comments

Comments
 (0)