Skip to content

Commit

Permalink
feat(Query): spyt clicue selector [YTFRONT-4219]
Browse files Browse the repository at this point in the history
  • Loading branch information
SimbiozizV committed Jul 4, 2024
1 parent 37a5e64 commit 6288c73
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 76 deletions.
19 changes: 10 additions & 9 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ It is supposed that a user is developer on a cluster if he has `write` access to

Available flags (**default values** are highlighted in bold):

| Flag name | Allowed values | Description |
| :----------------------------------- | :----------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| enable_per_bundle_tablet_accounting | **true**, false | Allows editing of resources of tablets through BundleEditorDialog [YTFRONT-2851](https://nda.ya.ru/t/xnLq-3Dm6fPYPo) |
| enable_per_account_tablet_accounting | **false**, true | Allows editing of resources of tablets through AccountEditorDialog [YTFRONT-2851](https://nda.ya.ru/t/xnLq-3Dm6fPYPo) |
| per_bundle_accounting_help_link | **null**, url as string | Help link for resources of tablets to display from AccountEditorDialog about moving the resources to bundles [YTFRONT-2851](https://nda.ya.ru/t/xnLq-3Dm6fPYPo) |
| enable_maintenance_api_nodes | **null**, boolean | Allows to use `add_maintenance`/`remove_maintenance` commands from `Comopnents/Nodes` page [YTFRONT-3792](https://nda.ya.ru/t/RvueJLzN6fWx3h) |
| enable_maintenance_api_proxies | **null**, boolean | Allows to use `add_maintenance`/`remove_maintenance` commands from `Components/HTTP Proxies` and `Components/RPC Proxies` pages [YTFRONT-3792](https://nda.ya.ru/t/RvueJLzN6fWx3h) |
| chyt_controller_base_url | **null**, url as string | Base url for chyt-controller |
| job_trace_url_template | **null**, `{title: string; url_template: string; enforce_for_trees?: Array<string>}` | If defined adds `Job trace` item to meta-table on `Job/Details` page for a job with `archive_features/has_trace == true` and for jobs from a tree in `enforce_for_trees`, example: `{title: 'Open im MyProfiling', url_template: 'https://my.profiling.service/{cluster}/{operationId}/{jobId}', enforce_for_trees: ['tree-with-traces'] }` |
| Flag name | Allowed values | Description |
|:------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| enable_per_bundle_tablet_accounting | **true**, false | Allows editing of resources of tablets through BundleEditorDialog [YTFRONT-2851](https://nda.ya.ru/t/xnLq-3Dm6fPYPo) |
| enable_per_account_tablet_accounting | **false**, true | Allows editing of resources of tablets through AccountEditorDialog [YTFRONT-2851](https://nda.ya.ru/t/xnLq-3Dm6fPYPo) |
| per_bundle_accounting_help_link | **null**, url as string | Help link for resources of tablets to display from AccountEditorDialog about moving the resources to bundles [YTFRONT-2851](https://nda.ya.ru/t/xnLq-3Dm6fPYPo) |
| enable_maintenance_api_nodes | **null**, boolean | Allows to use `add_maintenance`/`remove_maintenance` commands from `Comopnents/Nodes` page [YTFRONT-3792](https://nda.ya.ru/t/RvueJLzN6fWx3h) |
| enable_maintenance_api_proxies | **null**, boolean | Allows to use `add_maintenance`/`remove_maintenance` commands from `Components/HTTP Proxies` and `Components/RPC Proxies` pages [YTFRONT-3792](https://nda.ya.ru/t/RvueJLzN6fWx3h) |
| chyt_controller_base_url | **null**, url as string | Base url for chyt-controller |
| livy_controller_base_url | **null**, url as string | Base url for spyt-controller |
| job_trace_url_template | **null**, `{title: string; url_template: string; enforce_for_trees?: Array<string>}` | If defined adds `Job trace` item to meta-table on `Job/Details` page for a job with `archive_features/has_trace == true` and for jobs from a tree in `enforce_for_trees`, example: `{title: 'Open im MyProfiling', url_template: 'https://my.profiling.service/{cluster}/{operationId}/{jobId}', enforce_for_trees: ['tree-with-traces'] }` |

### Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {UNEXPECTED_PIPE_AXIOS_RESPONSE, pipeAxiosResponse, sendAndLogError} from
import {getUserYTApiSetup} from '../components/requestsSetup';
import {getPreloadedClusterUiConfig} from '../components/cluster-params';

export async function chytProxyApi(req: Request, res: Response) {
export async function strawberryProxyApi(req: Request, res: Response) {
try {
await chytProxyApiImpl(req, res);
await strawberryProxyApiImpl(req, res);
} catch (e: any) {
await sendAndLogError(req.ctx, res, 500, e, {
method: 'nodejs',
Expand All @@ -18,8 +18,18 @@ export async function chytProxyApi(req: Request, res: Response) {
}
}

async function chytProxyApiImpl(req: Request, res: Response) {
const {action, ytAuthCluster: cluster} = req.params;
const getBaseUrlConfigParameter = (engine: string) => {
const CLUSTER_CONFIG_ENGINE_URL_MAP = {
chyt: 'chyt_controller_base_url',
spyt: 'livy_controller_base_url',
} as const;

if (!(engine in CLUSTER_CONFIG_ENGINE_URL_MAP)) return null;
return CLUSTER_CONFIG_ENGINE_URL_MAP[engine as keyof typeof CLUSTER_CONFIG_ENGINE_URL_MAP];
};

async function strawberryProxyApiImpl(req: Request, res: Response) {
const {action, engine, ytAuthCluster: cluster} = req.params;
const ALLOWED_ACTIONS = new Set([
'list',
'create',
Expand All @@ -32,29 +42,31 @@ async function chytProxyApiImpl(req: Request, res: Response) {
'get_speclet',
]);

const baseUrlConfigParameter = getBaseUrlConfigParameter(engine);

if (!baseUrlConfigParameter) {
return sendAndLogError(req.ctx, res, 400, new Error('api engine is not supported'));
}

if (!ALLOWED_ACTIONS.has(action)) {
return sendAndLogError(
req.ctx,
res,
400,
new Error(`CHYT action - '${action}', is not supported`),
new Error(`${engine.toUpperCase()} action - '${action}', is not supported`),
);
}

const isDeveloper = req.query.isDeveloper === 'true';

const {chyt_controller_base_url: baseUrl} = await getPreloadedClusterUiConfig(
cluster,
req.ctx,
isDeveloper,
);
const config = await getPreloadedClusterUiConfig(cluster, req.ctx, isDeveloper);
const baseUrl = config[baseUrlConfigParameter];

if (!baseUrl) {
return sendAndLogError(
req.ctx,
res,
500,
new Error('//sys/@ui_config/chyt_controller_base_url is not defined'),
new Error(`//sys/@ui_config/${baseUrlConfigParameter} is not defined`),
);
}
const {ctx} = req;
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {getClusterPools} from './controllers/scheduling-pools';
import {markdownToHtmlHandler} from './controllers/markdown-to-html';
import {odinProxyApi} from './controllers/odin-proxy-api';
import {getClustersAvailability} from './controllers/availability';
import {chytProxyApi} from './controllers/chyt-api';
import {strawberryProxyApi} from './controllers/strawberry-api';
import {oauthCallback, oauthLogin, oauthLogout} from './controllers/oauth-login';
import {handleLogout} from './controllers/logout';

Expand Down Expand Up @@ -57,7 +57,7 @@ const routes: AppRoutes = {
'GET /api/odin/proxy/:action/:ytAuthCluster?': {handler: odinProxyApi},
'GET /api/odin/clusters/availability': {handler: getClustersAvailability},

'POST /api/chyt/:ytAuthCluster/:action': {handler: chytProxyApi},
'POST /api/strawberry/:engine/:ytAuthCluster/:action': {handler: strawberryProxyApi},

'GET /api/settings/:ytAuthCluster/:username': {handler: settingsGet},
'POST /api/settings/:ytAuthCluster/:username': {handler: settingsCreate},
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/shared/yt-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ClusterUiConfig {
enable_maintenance_api_nodes?: boolean;
enable_maintenance_api_proxies?: boolean;
chyt_controller_base_url?: string;
livy_controller_base_url?: string;
job_trace_url_template?: {
title: string;
url_template: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {FC} from 'react';
import {QueryCliqueItem} from './QueryCliqueItem';
import {QuerySelector} from '../QuerySelector';
import {Select} from '@gravity-ui/uikit';
import {Flex, Select} from '@gravity-ui/uikit';

type Props = {
loading: boolean;
Expand All @@ -21,7 +21,8 @@ export const QueryCliqueSelector: FC<Props> = ({cliqueList, value, loading, onCh
loading={loading}
onChange={onChange}
getOptionHeight={() => 52}
disabled={!cliqueList.length}
disabled={loading && !cliqueList.length}
renderEmptyOptions={() => <Flex justifyContent="center">No access clique</Flex>}
>
{(items) =>
items.map(({alias, yt_operation_id}) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, {ChangeEvent, FC, useCallback} from 'react';
import React, {FC} from 'react';
import {QueryClusterSelector} from './QueryClusterSelector';
import {ClusterConfig} from '../../../../shared/yt-types';
import {QueryEngine} from '../module/engines';
import {QueryCliqueSelector} from './QueryCliqueSelector';
import {TextInput} from '@gravity-ui/uikit';

type Props = {
settings?: Record<string, string>;
engine: QueryEngine;
clusters: ClusterConfig[];
cliqueMap: Record<string, {alias: string; yt_operation_id?: string}[]>;
cliqueMap: Record<string, Record<string, {alias: string; yt_operation_id?: string}[]>>;
cliqueLoading: boolean;
onClusterChange: (clusterId: string) => void;
onCliqueChange: (alias: string) => void;
Expand All @@ -25,15 +24,9 @@ export const QuerySelectorsByEngine: FC<Props> = ({
onCliqueChange,
onPathChange,
}) => {
const handlePathChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
onPathChange(e.currentTarget.value);
},
[onPathChange],
);

const cliqueList =
settings.cluster && settings.cluster in cliqueMap ? cliqueMap[settings.cluster] : [];
const clusterCliqueList =
settings.cluster && settings.cluster in cliqueMap ? cliqueMap[settings.cluster] : {};
const cliqueList = engine in clusterCliqueList ? clusterCliqueList[engine] : [];

if (engine === QueryEngine.CHYT) {
return (
Expand Down Expand Up @@ -61,14 +54,11 @@ export const QuerySelectorsByEngine: FC<Props> = ({
value={settings.cluster}
onChange={onClusterChange}
/>
<TextInput
placeholder="Discovery path"
value={settings.discovery_path}
onChange={handlePathChange}
size="l"
hasClear
defaultValue={settings.discovery_path}
style={{maxWidth: '200px'}}
<QueryCliqueSelector
loading={cliqueLoading}
cliqueList={cliqueList}
value={settings.discovery_group}
onChange={onPathChange}
/>
</>
);
Expand Down
28 changes: 15 additions & 13 deletions packages/ui/src/ui/pages/query-tracker/QueryTrackerTopRow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {FC, useCallback, useState} from 'react';
import React, {FC, useCallback, useEffect, useState} from 'react';
import {useDispatch, useSelector} from 'react-redux';
import {RowWithName} from '../../../containers/AppNavigation/TopRowContent/SectionName';
import {Page} from '../../../../shared/constants/settings';
Expand Down Expand Up @@ -36,18 +36,23 @@ const QueryTrackerTopRow: FC = () => {
const [nameEdit, setNameEdit] = useState(false);
const isDesktop = useIsDesktop();

useEffect(() => {
if ((engine === QueryEngine.CHYT || engine === QueryEngine.SPYT) && settings?.cluster) {
dispatch(loadCliqueByCluster(engine, settings.cluster));
}
}, [engine, settings?.cluster, dispatch]);

const handleChangeEngine = useCallback(
(newEngine: QueryEngine) => {
const newSettings = {...settings};
const isSpyt = newEngine === QueryEngine.SPYT;
const isChyt = newEngine === QueryEngine.CHYT;

if (newEngine === QueryEngine.CHYT && settings && 'cluster' in settings) {
dispatch(loadCliqueByCluster(settings.cluster as string));
}

if (newEngine !== QueryEngine.SPYT && 'discovery_path' in newSettings) {
delete newSettings['discovery_path'];
if (!isSpyt && 'discovery_group' in newSettings) {
delete newSettings['discovery_group'];
delete newSettings['discovery_path']; // old request type. Deprecated
}
if (newEngine !== QueryEngine.CHYT && 'clique' in newSettings) {
if (!isChyt && 'clique' in newSettings) {
delete newSettings['clique'];
}

Expand Down Expand Up @@ -78,16 +83,13 @@ const QueryTrackerTopRow: FC = () => {
const newSettings: Record<string, string> = settings ? {...settings} : {};
if (clusterId) {
newSettings.cluster = clusterId;
if (engine === QueryEngine.CHYT) {
dispatch(loadCliqueByCluster(clusterId));
}
} else {
delete newSettings['cluster'];
}
delete newSettings['clique'];
dispatch(updateQueryDraft({settings: newSettings}));
},
[dispatch, engine, settings],
[dispatch, settings],
);

const handleCliqueChange = useCallback(
Expand All @@ -105,7 +107,7 @@ const QueryTrackerTopRow: FC = () => {

const handlePathChange = useCallback(
(newPath: string) => {
dispatch(updateQueryDraft({settings: {...settings, discovery_path: newPath}}));
dispatch(updateQueryDraft({settings: {...settings, discovery_group: newPath}}));
},
[dispatch, settings],
);
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/ui/pages/query-tracker/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export interface DraftQuery {
settings?: {
cluster?: string;
clique?: string;
discovery_path?: string;
discovery_path?: string; // old request type. Deprecated
discovery_group?: string;
execution_mode?: 'validate' | 'optimize';
} & Record<string, string>;
error?: unknown;
Expand Down
Loading

0 comments on commit 6288c73

Please sign in to comment.