-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtenantOverviewTopShards.ts
More file actions
52 lines (46 loc) · 1.69 KB
/
tenantOverviewTopShards.ts
File metadata and controls
52 lines (46 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {QUERY_TECHNICAL_MARK, TENANT_OVERVIEW_TABLES_LIMIT} from '../../../../utils/constants';
import {isQueryErrorResponse, parseQueryAPIResponse} from '../../../../utils/query';
import {api} from '../../api';
function createShardQuery(path: string, database: string) {
const pathSelect = database
? `CAST(SUBSTRING(CAST(Path AS String), ${database.length}) AS Utf8) AS Path`
: 'Path';
return `${QUERY_TECHNICAL_MARK}
SELECT
${pathSelect},
TabletId,
CPUCores,
FROM \`${database}/.sys/partition_stats\`
WHERE
Path='${path}'
OR Path LIKE '${path}/%'
ORDER BY CPUCores DESC
LIMIT ${TENANT_OVERVIEW_TABLES_LIMIT}`;
}
const queryAction = 'execute-scan';
export const topShardsApi = api.injectEndpoints({
endpoints: (builder) => ({
getTopShards: builder.query({
queryFn: async ({database, path = ''}: {database: string; path?: string}, {signal}) => {
try {
const response = await window.api.viewer.sendQuery(
{
query: createShardQuery(path, database),
database,
action: queryAction,
},
{signal, withRetries: true},
);
if (isQueryErrorResponse(response)) {
return {error: response};
}
return {data: parseQueryAPIResponse(response)};
} catch (error) {
return {error: error || new Error('Unauthorized')};
}
},
providesTags: ['All'],
}),
}),
overrideExisting: 'throw',
});