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

feat(Queries): default ACO [#436] #754

Merged
merged 1 commit into from
Oct 18, 2024
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
21 changes: 11 additions & 10 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ 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 |
| 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'] }` |
| 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'] }` |
| query_tracker_default_aco | **null**, `{stage1: string; stage2: string; }` | Sets the default ACO in Query Tracker requests for each stage |

### Configuration

Expand Down
11 changes: 8 additions & 3 deletions packages/ui/src/shared/constants/settings-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ interface AccountsSettings {
'global::accounts::dashboardVisibilityMode': 'string';
}

type ClusterName = string;
export type Stage = string;

interface QueryTrackerSettings {
'global::queryTracker::queriesListSidebarVisibilityMode': boolean;
Expand All @@ -81,7 +81,11 @@ interface ChytSettings {
}

type QueryTrackerLastSelectedACOsSettings = {
[key in `local::${ClusterName}::queryTracker::lastSelectedACOs`]: string[];
[key in `qt-stage::${Stage}::queryTracker::lastSelectedACOs`]: string[];
};

type QueryTrackerUserDefaultACOSettings = {
[key in `qt-stage::${Stage}::queryTracker::defaultACO`]: string;
};

interface OtherSettings {
Expand Down Expand Up @@ -113,7 +117,8 @@ type DescribedSettings = GlobalSettings &
AccountsSettings &
QueryTrackerSettings &
ChytSettings &
QueryTrackerLastSelectedACOsSettings;
QueryTrackerLastSelectedACOsSettings &
QueryTrackerUserDefaultACOSettings;

export type Settings = DescribedSettings & OtherSettings;

Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/shared/yt-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {YTError} from '../@types/types';
import type {Settings} from './constants/settings-types';
import type {Settings, Stage} from './constants/settings-types';
import type {UISettings} from './ui-settings';

export interface YTConfig {
Expand All @@ -24,6 +24,7 @@ export interface ClusterUiConfig {
enable_maintenance_api_proxies?: boolean;
chyt_controller_base_url?: string;
livy_controller_base_url?: string;
query_tracker_default_aco?: Record<Stage, string>;
job_trace_url_template?: {
title: string;
url_template: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
&_one-line {
display: flex;
}

&_select {
margin-left: 0;
margin-bottom: 0;
}
}

&-annotation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, {useEffect, useState} from 'react';
import block from 'bem-cn-lite';
import {SelectSingle} from '../../components/Select/Select';

import './SettingsMenu.scss';

const b = block('elements-page');

type SettingsMenuSelectOption =
| {options: Array<{value: string; text: string}>}
| {getOptionsOnMount: () => Promise<Array<{value: string; text: string}>>};
type SettingsMenuSelectProps = {
placeholder?: string;
label?: string;
getSetting: () => string;
setSetting: (value?: string) => void;
} & SettingsMenuSelectOption;

export const SettingsMenuSelect = (props: SettingsMenuSelectProps) => {
const value = props.getSetting();
const [items, setItems] = useState('options' in props ? props.options : []);

useEffect(() => {
if ('getOptionsOnMount' in props) {
props?.getOptionsOnMount().then((options) => {
setItems(options);
});
}
}, []);

return (
<div className={b('settings-item', {select: true})} title={props.label}>
<SelectSingle
value={value}
items={items}
onChange={(value) => props.setSetting(value)}
placeholder={props.placeholder}
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ import Link from '../../components/Link/Link';
import Button from '../../components/Button/Button';
import {AddTokenForm, VcsList} from '../../pages/query-tracker/Vcs/SettingsMenu';
import {selectIsVcsVisible, selectVcsConfig} from '../../pages/query-tracker/module/vcs/selectors';
import {SettingsMenuSelect} from '../SettingsMenu/SettingsMenuSelect';
import {getDefaultQueryACO} from '../../pages/query-tracker/module/query_aco/selectors';
import {getQueryACO, setUserDefaultACO} from '../../pages/query-tracker/module/query_aco/actions';
import {Item} from '../../components/Select/Select';
import {useThunkDispatch} from '../../store/thunkDispatch';

export interface SettingsPage {
title: string;
Expand Down Expand Up @@ -80,13 +85,15 @@ function wrapEscapeText(text: string) {
}

function useSettings(cluster: string, isAdmin: boolean): Array<SettingsPage> {
const dispatch = useThunkDispatch();
const clusterNS = useSelector(getCurrentClusterNS);

const httpProxyVersion: string = useSelector(getHttpProxyVersion);
const schedulerVersion: string = useSelector(getGlobalSchedulerVersion);
const masterVersion: string = useSelector(getGlobalMasterVersion);
const vcsConfig = useSelector(selectVcsConfig);
const isVcsVisible = useSelector(selectIsVcsVisible);
const defaultUserACO = useSelector(getDefaultQueryACO);

return compact_([
makePage('General', generalIcon, [
Expand Down Expand Up @@ -511,6 +518,32 @@ function useSettings(cluster: string, isAdmin: boolean): Array<SettingsPage> {
]),
),

makePage(
'Query ACO',
undefined,
compact_([
makeItem(
'Default ACO',
undefined,
<SettingsMenuSelect
getOptionsOnMount={() =>
dispatch(getQueryACO()).then((data) => {
return data.access_control_objects.reduce(
(acc: Item[], item: string) => {
acc.push({value: item, text: item});
return acc;
},
[] as Item[],
);
})
}
setSetting={(value) => value && dispatch(setUserDefaultACO(value))}
getSetting={() => defaultUserACO}
/>,
),
]),
),

makePage(
'About',
infoIcon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {useDispatch, useSelector} from 'react-redux';
import {QueriesPoolingContext} from '../../hooks/QueriesPooling/context';

import {getCurrentQuery} from '../../module/query/selectors';
import {getDefaultQueryACO} from '../../module/query_aco/selectors';
import {isQueryProgress} from '../../utils/query';
import {QueryItem} from '../../module/api';
import {prepareQueryPlanIds} from '../../module/query/utills';
import {UPDATE_QUERY} from '../../../../pages/query-tracker/module/query-tracker-contants';

export function useCurrentQuery() {
const query = useSelector(getCurrentQuery);
const defaultQueryACO = useSelector(getDefaultQueryACO);
const pollingContext = useContext(QueriesPoolingContext);

const dispatch = useDispatch();
Expand All @@ -19,10 +21,10 @@ export function useCurrentQuery() {
([item]: QueryItem[]) => {
dispatch({
type: UPDATE_QUERY,
data: prepareQueryPlanIds(item),
data: prepareQueryPlanIds(item, defaultQueryACO),
});
},
[dispatch],
[dispatch, defaultQueryACO],
);

useEffect(
Expand Down
16 changes: 9 additions & 7 deletions packages/ui/src/ui/pages/query-tracker/module/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {getClusterConfigByName, getClusterProxy} from '../../../store/selectors/
import {generateQuerySettings, generateQueryText} from '../utils/query_generate';
import {RootState} from '../../../store/reducers';
import {makeDirectDownloadPath} from '../../../utils/navigation';
import {DEFAULT_QUERY_ACO, getQueryTrackerRequestOptions} from './query/selectors';
import {QueriesHistoryCursorDirection, UPDATE_QUERIES_LIST} from './query-tracker-contants';
import {getEffectiveApiStage, getQueryTrackerRequestOptions} from './query/selectors';
import {AnyAction} from 'redux';
import {QueryEngine} from './engines';
import {getLastSelectedACONamespaces, selectIsMultipleAco} from './query_aco/selectors';
Expand Down Expand Up @@ -212,7 +212,7 @@ export type QueriesListRequestParams = {

export async function generateQueryFromTable(
engine: QueryEngine,
{cluster, path}: {cluster: string; path: string},
{cluster, path, defaultQueryACO}: {cluster: string; path: string; defaultQueryACO: string},
): Promise<DraftQuery | undefined> {
const selectedCluster = getClusterConfigByName(cluster);
const node = await ytApiV3.get({
Expand All @@ -239,8 +239,8 @@ export async function generateQueryFromTable(
}),
files: [],
annotations: {},
access_control_object: DEFAULT_QUERY_ACO,
access_control_objects: [DEFAULT_QUERY_ACO],
access_control_object: defaultQueryACO,
access_control_objects: [defaultQueryACO],
settings: generateQuerySettings(engine, cluster),
};
}
Expand Down Expand Up @@ -571,13 +571,15 @@ export function addACOToLastSelected(
): ThunkAction<Promise<any>, RootState, any, AnyAction> {
return async (dispatch, getState) => {
const state = getState();
const cluster = state.global.cluster;
const lastSelectedACONamespaces = getLastSelectedACONamespaces(state);
const stage = getEffectiveApiStage(state);

await dispatch(
setSettingByKey(`local::${cluster}::queryTracker::lastSelectedACOs`, [
setSettingByKey(`qt-stage::${stage}::queryTracker::lastSelectedACOs`, [
...aco,
...lastSelectedACONamespaces.filter((item) => !aco.includes(item)).slice(0, 9),
...lastSelectedACONamespaces
.filter((item: string) => !aco.includes(item))
.slice(0, 9),
]),
);
};
Expand Down
Loading
Loading