Skip to content

Commit 2cecddd

Browse files
authored
feat: support async replications (#856)
1 parent 3bd1e5d commit 2cecddd

File tree

22 files changed

+391
-12
lines changed

22 files changed

+391
-12
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"url": "^0.11.3",
4949
"use-query-params": "^2.2.1",
5050
"web-vitals": "^1.1.2",
51-
"ydb-ui-components": "^4.1.0",
51+
"ydb-ui-components": "^4.2.0",
5252
"zod": "^3.23.8"
5353
},
5454
"scripts": {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Label} from '@gravity-ui/uikit';
2+
3+
import type {TReplicationState} from '../../types/api/schema/replication';
4+
5+
interface AsyncReplicationStateProps {
6+
state?: TReplicationState;
7+
}
8+
9+
export function AsyncReplicationState({state}: AsyncReplicationStateProps) {
10+
if (!state) {
11+
return null;
12+
}
13+
14+
if ('StandBy' in state) {
15+
return <Label theme="info">Standby</Label>;
16+
}
17+
if ('Paused' in state) {
18+
return <Label theme="info">Paused</Label>;
19+
}
20+
if ('Done' in state) {
21+
return <Label theme="success">Done</Label>;
22+
}
23+
if ('Error' in state) {
24+
return <Label theme="danger">Error</Label>;
25+
}
26+
27+
return <Label size="s">Unknown</Label>;
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './AsyncReplicationState';

src/containers/Tenant/Diagnostics/DiagnosticsPages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const partitions = {
7070
title: 'Partitions',
7171
};
7272

73+
export const ASYNC_REPLICATION_PAGES = [overview, describe];
74+
7375
export const DATABASE_PAGES = [
7476
overview,
7577
topQueries,
@@ -117,6 +119,8 @@ const pathTypeToPages: Record<EPathType, Page[] | undefined> = {
117119
[EPathType.EPathTypeExternalTable]: EXTERNAL_TABLE_PAGES,
118120

119121
[EPathType.EPathTypeView]: VIEW_PAGES,
122+
123+
[EPathType.EPathTypeReplication]: ASYNC_REPLICATION_PAGES,
120124
};
121125

122126
export const getPagesByType = (type?: EPathType) => (type && pathTypeToPages[type]) || DIR_PAGES;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {Flex, Text} from '@gravity-ui/uikit';
2+
3+
import {AsyncReplicationState} from '../../../../../components/AsyncReplicationState';
4+
import {InfoViewer} from '../../../../../components/InfoViewer';
5+
import type {TEvDescribeSchemeResult} from '../../../../../types/api/schema';
6+
import {useTypedSelector} from '../../../../../utils/hooks';
7+
import {getEntityName} from '../../../utils';
8+
import {AsyncReplicationPaths} from '../AsyncReplicationPaths';
9+
10+
import {Credentials} from './Credentials';
11+
import i18n from './i18n';
12+
13+
interface AsyncReplicationProps {
14+
data?: TEvDescribeSchemeResult;
15+
}
16+
17+
/** Displays overview for Replication EPathType */
18+
export function AsyncReplicationInfo({data}: AsyncReplicationProps) {
19+
const entityName = getEntityName(data?.PathDescription);
20+
21+
const {error: schemaError} = useTypedSelector((state) => state.schema);
22+
23+
if (schemaError) {
24+
return <div className="error">{schemaError.statusText}</div>;
25+
}
26+
27+
if (!data) {
28+
return (
29+
<div className="error">
30+
{i18n('noData')} {entityName}
31+
</div>
32+
);
33+
}
34+
35+
return (
36+
<Flex direction="column" gap="4">
37+
<InfoViewer
38+
title={entityName}
39+
info={[
40+
{
41+
label: i18n('state.label'),
42+
value: (
43+
<AsyncReplicationState
44+
state={data.PathDescription?.ReplicationDescription?.State}
45+
/>
46+
),
47+
},
48+
{
49+
label: i18n('srcConnection.endpoint.label'),
50+
value: (
51+
<Text variant="code-inline-2">
52+
{
53+
data.PathDescription?.ReplicationDescription?.Config
54+
?.SrcConnectionParams?.Endpoint
55+
}
56+
</Text>
57+
),
58+
},
59+
{
60+
label: i18n('srcConnection.database.label'),
61+
value: (
62+
<Text variant="code-inline-2">
63+
{
64+
data.PathDescription?.ReplicationDescription?.Config
65+
?.SrcConnectionParams?.Database
66+
}
67+
</Text>
68+
),
69+
},
70+
{
71+
label: i18n('credentials.label'),
72+
value: (
73+
<Credentials
74+
connection={
75+
data.PathDescription?.ReplicationDescription?.Config
76+
?.SrcConnectionParams
77+
}
78+
/>
79+
),
80+
},
81+
]}
82+
/>
83+
<AsyncReplicationPaths config={data.PathDescription?.ReplicationDescription?.Config} />
84+
</Flex>
85+
);
86+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {Label} from '@gravity-ui/uikit';
2+
3+
import type {TConnectionParams} from '../../../../../types/api/schema/replication';
4+
5+
interface CredentialsProps {
6+
connection?: TConnectionParams;
7+
}
8+
9+
export function Credentials({connection}: CredentialsProps) {
10+
if (!connection) {
11+
return null;
12+
}
13+
14+
if (connection.StaticCredentials) {
15+
return (
16+
<Label value={connection.StaticCredentials.User} theme="normal">
17+
user
18+
</Label>
19+
);
20+
}
21+
22+
if ('OAuthToken' in connection) {
23+
return 'OAuth';
24+
}
25+
26+
return 'unknown';
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"credentials.label": "Credentials",
3+
"noData": "No data for entity:",
4+
"srcConnection.database.label": "Source Database Path",
5+
"srcConnection.endpoint.label": "Source Cluster Endpoint",
6+
"state.label": "State"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {registerKeysets} from '../../../../../../utils/i18n';
2+
3+
import en from './en.json';
4+
5+
const COMPONENT = 'ydb-diagnostics-async-replication-info';
6+
7+
export default registerKeysets(COMPONENT, {en});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './AsyncReplicationInfo';

0 commit comments

Comments
 (0)