Skip to content

Commit

Permalink
feat(Job): add 'Job trace' meta-table item [YTFRONT-4182]
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-efremoff committed Jun 25, 2024
1 parent 9baedc4 commit 00c0691
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 13 deletions.
17 changes: 9 additions & 8 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ 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 |
| 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'] }` |

### Configuration

Expand Down
5 changes: 5 additions & 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,11 @@ export interface ClusterUiConfig {
enable_maintenance_api_nodes?: boolean;
enable_maintenance_api_proxies?: boolean;
chyt_controller_base_url?: string;
job_trace_url_template?: {
title: string;
url_template: string;
enforce_for_trees?: Array<string>;
};
}

export type CypressNode<AttributesT extends Record<string, unknown>, ValueT> = {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/ui/pages/job/JobActions/JobActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function ActionBlock(action: Action) {
);
}

export default function JobActions() {
export default function JobActions({className}: {className?: string}) {
const job = useSelector(getJob);
const {loaded} = useSelector((state: RootState) => state.job.general);
const cluster = useSelector(getCluster);
Expand Down Expand Up @@ -256,7 +256,7 @@ export default function JobActions() {

return (
<ErrorBoundary>
<div className={block()}>
<div className={block(null, className)}>
{_.map(actions, (action: Action) => (
<ActionBlock {...action} />
))}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/ui/pages/job/JobGeneral/JobGeneral.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
margin-right: 12px;
}

.job-actions {
&__actions {
margin-left: auto;
}

Expand Down
54 changes: 52 additions & 2 deletions packages/ui/src/ui/pages/job/JobGeneral/JobGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import {DEFAULT_TAB, Tab} from '../../../constants/job';
import {RootState} from '../../../store/reducers';
import {Page} from '../../../constants/index';
import {makeTabProps} from '../../../utils';
import {formatByParams} from '../../../utils/format';
import hammer from '../../../common/hammer';
import {RouteInfo} from '../Job';

import ChartLink from '../../../components/ChartLink/ChartLink';
import Link from '../../../components/Link/Link';
import {getJob} from '../../../store/selectors/job/detail';
import ClipboardButton from '../../../components/ClipboardButton/ClipboardButton';
import {getCluster} from '../../../store/selectors/global';
import {getCluster, getClusterUiConfig} from '../../../store/selectors/global';
import UIFactory from '../../../UIFactory';
import {StaleJobIcon} from '../../../pages/operations/OperationDetail/tabs/Jobs/StaleJobIcon';

Expand All @@ -44,6 +45,14 @@ export default function JobGeneral() {
const job = useSelector(getJob);
const {loaded} = useSelector((state: RootState) => state.job.general);

const {url: traceUrl, title: traceTitle} = useJobProfilingUrl({
operationId: job?.operationId,
jobId: job?.id,
has_trace: job?.archive_features?.has_trace,
pool_tree: job?.pool_tree,
cluster,
});

if (!loaded) {
return null;
}
Expand Down Expand Up @@ -83,7 +92,7 @@ export default function JobGeneral() {

<Statuslabel label={state} renderPlaque />

<JobActions />
<JobActions className={block('actions')} />
</div>

{isSpeculativeJob && (
Expand Down Expand Up @@ -246,6 +255,15 @@ export default function JobGeneral() {
),
},
]),
{
key: 'Job trace',
value: (
<Link target="_blank" url={traceUrl}>
{traceTitle}
</Link>
),
visible: Boolean(traceUrl),
},
],
]}
/>
Expand Down Expand Up @@ -276,3 +294,35 @@ export default function JobGeneral() {
</ErrorBoundary>
);
}

function useJobProfilingUrl({
operationId,
jobId,
pool_tree,
has_trace,
cluster,
}: {
operationId?: string;
jobId?: string;
cluster: string;
has_trace?: boolean;
pool_tree?: string;
}) {
const {job_trace_url_template: {url_template, title = 'Open trace', enforce_for_trees} = {}} =
useSelector(getClusterUiConfig);
return React.useMemo(() => {
const allowTrace = has_trace || 0 <= enforce_for_trees?.indexOf(pool_tree!)!;

if (!allowTrace || !cluster || !operationId || !jobId || !url_template) {
return {};
}
return {
url: formatByParams(url_template, {
operationId,
jobId,
cluster,
}),
title,
};
}, [cluster, operationId, jobId, url_template, title, enforce_for_trees, pool_tree, has_trace]);
}
1 change: 1 addition & 0 deletions packages/ui/src/ui/types/job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface RawJob {
monitoring_descriptor?: string;
pool_tree?: string;
is_stale?: boolean;
archive_features?: {has_trace?: boolean};
}

export type JobState =
Expand Down

0 comments on commit 00c0691

Please sign in to comment.