Skip to content

Commit 2a2082e

Browse files
feat: allow meta proxy
1 parent 4cfdcf6 commit 2a2082e

File tree

6 files changed

+67
-22
lines changed

6 files changed

+67
-22
lines changed

src/containers/AppWithClusters/utils/useAdditionalTenantsProps.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ export function useAdditionalTenantsProps({
2626

2727
const {balancer, monitoring, logging, name: clusterName} = clusterInfo;
2828

29+
const useMetaProxy = clusterInfo.settings?.use_meta_proxy;
30+
2931
const additionalTenantsProps: AdditionalTenantsProps = {};
3032
additionalTenantsProps.prepareTenantBackend = (nodeId) => {
33+
if (useMetaProxy) {
34+
return undefined;
35+
}
36+
3137
// Balancer value is used to create path, so it's necessary
3238
if (!balancer) {
3339
return undefined;

src/services/api/base.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import axiosRetry from 'axios-retry';
44

55
import {backend as BACKEND} from '../../store';
66
import {DEV_ENABLE_TRACING_FOR_ALL_REQUESTS} from '../../utils/constants';
7+
import {prepareBackendWithMetaProxy} from '../../utils/parseBalancer';
78
import {isRedirectToAuth} from '../../utils/response';
89
import {settingsManager} from '../settings';
910

@@ -14,11 +15,19 @@ export type AxiosOptions = {
1415
timeout?: number;
1516
};
1617

18+
export interface BaseAPIParams {
19+
singleClusterMode?: boolean;
20+
}
21+
1722
export class BaseYdbAPI extends AxiosWrapper {
1823
DEFAULT_RETRIES_COUNT = 0;
1924

20-
constructor(options?: AxiosWrapperOptions) {
21-
super(options);
25+
singleClusterMode?: boolean;
26+
27+
constructor(axiosOptions?: AxiosWrapperOptions, {singleClusterMode}: BaseAPIParams = {}) {
28+
super(axiosOptions);
29+
30+
this.singleClusterMode = singleClusterMode;
2231

2332
axiosRetry(this._axios, {
2433
retries: this.DEFAULT_RETRIES_COUNT,
@@ -74,6 +83,13 @@ export class BaseYdbAPI extends AxiosWrapper {
7483
}
7584

7685
getPath(path: string) {
86+
const urlSearchParams = new URL(window.location.href).searchParams;
87+
const clusterName = urlSearchParams.get('clusterName') ?? undefined;
88+
89+
if (clusterName && !this.singleClusterMode && !BACKEND) {
90+
return prepareBackendWithMetaProxy({clusterName}) + path;
91+
}
92+
7793
return `${BACKEND ?? ''}${path}`;
7894
}
7995

src/services/api/index.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {AxiosWrapperOptions} from '@gravity-ui/axios-wrapper';
12
import type {AxiosRequestConfig} from 'axios';
23

34
import {codeAssistBackend} from '../../store';
@@ -30,33 +31,36 @@ export class YdbEmbeddedAPI {
3031
constructor({
3132
webVersion = false,
3233
withCredentials = false,
34+
singleClusterMode,
3335
csrfTokenGetter = () => undefined,
3436
defaults = {},
3537
}: {
3638
webVersion?: boolean;
3739
withCredentials?: boolean;
40+
singleClusterMode?: boolean;
3841
csrfTokenGetter?: () => string | undefined;
3942
defaults?: AxiosRequestConfig;
4043
} = {}) {
41-
const config: AxiosRequestConfig = {withCredentials, ...defaults};
44+
const axiosParams: AxiosWrapperOptions = {config: {withCredentials, ...defaults}};
45+
const baseApiParams = {singleClusterMode};
4246

43-
this.auth = new AuthAPI({config});
47+
this.auth = new AuthAPI(axiosParams, baseApiParams);
4448
if (webVersion) {
45-
this.meta = new MetaAPI({config});
49+
this.meta = new MetaAPI(axiosParams, baseApiParams);
4650
}
4751

4852
if (webVersion || codeAssistBackend) {
49-
this.codeAssist = new CodeAssistAPI({config});
53+
this.codeAssist = new CodeAssistAPI(axiosParams, baseApiParams);
5054
}
5155

52-
this.operation = new OperationAPI({config});
53-
this.pdisk = new PDiskAPI({config});
54-
this.scheme = new SchemeAPI({config});
55-
this.storage = new StorageAPI({config});
56-
this.streaming = new StreamingAPI({config});
57-
this.tablets = new TabletsAPI({config});
58-
this.vdisk = new VDiskAPI({config});
59-
this.viewer = new ViewerAPI({config});
56+
this.operation = new OperationAPI(axiosParams, baseApiParams);
57+
this.pdisk = new PDiskAPI(axiosParams, baseApiParams);
58+
this.scheme = new SchemeAPI(axiosParams, baseApiParams);
59+
this.storage = new StorageAPI(axiosParams, baseApiParams);
60+
this.streaming = new StreamingAPI(axiosParams, baseApiParams);
61+
this.tablets = new TabletsAPI(axiosParams, baseApiParams);
62+
this.vdisk = new VDiskAPI(axiosParams, baseApiParams);
63+
this.viewer = new ViewerAPI(axiosParams, baseApiParams);
6064

6165
const token = csrfTokenGetter();
6266
if (token) {

src/store/configureStore.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ const isSingleClusterMode = `${metaBackend}` === 'undefined';
5757
export function configureStore({
5858
aRootReducer = rootReducer,
5959
singleClusterMode = isSingleClusterMode,
60-
api = new YdbEmbeddedAPI({webVersion, withCredentials: !customBackend}),
60+
api = new YdbEmbeddedAPI({
61+
webVersion,
62+
singleClusterMode: isSingleClusterMode,
63+
withCredentials: !customBackend,
64+
}),
6165
getBackend = (params: ReturnType<typeof getUrlData>) => params.backend,
6266
} = {}) {
6367
const params = getUrlData({singleClusterMode, customBackend});

src/store/reducers/clusters/utils.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ export const prepareClustersData = (data: MetaClusters): PreparedCluster[] => {
2222
const versionsData = getVersionsData(allMinorVersions);
2323

2424
// Apply color map to every cluster in the list
25-
return clusters.map((cluster) => ({
26-
...cluster,
27-
preparedVersions: prepareClusterVersions(cluster.versions, versionsData),
28-
preparedBackend: cluster.balancer
29-
? prepareBackendFromBalancer(cluster.balancer)
30-
: undefined,
31-
}));
25+
return clusters.map((cluster) => {
26+
const useMetaProxy = cluster.settings?.use_meta_proxy;
27+
28+
const preparedBackend =
29+
cluster.balancer && !useMetaProxy
30+
? prepareBackendFromBalancer(cluster.balancer)
31+
: undefined;
32+
33+
return {
34+
...cluster,
35+
preparedVersions: prepareClusterVersions(cluster.versions, versionsData),
36+
preparedBackend,
37+
};
38+
});
3239
};

src/utils/parseBalancer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ export function prepareBackendFromBalancer(rawBalancer: string) {
7070

7171
return preparedBalancer;
7272
}
73+
74+
export function prepareBackendWithMetaProxy({clusterName}: {clusterName?: string}) {
75+
if (!clusterName) {
76+
return undefined;
77+
}
78+
79+
return prepareBackendFromBalancer(`/proxy/cluster/${clusterName}`);
80+
}

0 commit comments

Comments
 (0)