Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ export function useAdditionalTenantsProps({

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

const useMetaProxy = clusterInfo.settings?.use_meta_proxy;

const additionalTenantsProps: AdditionalTenantsProps = {};
additionalTenantsProps.prepareTenantBackend = (nodeId) => {
// If no backend is provided, it will be automatically generated by API instance
if (useMetaProxy) {
return undefined;
}

// Balancer value is used to create path, so it's necessary
if (!balancer) {
return undefined;
Expand Down
19 changes: 16 additions & 3 deletions src/services/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import AxiosWrapper from '@gravity-ui/axios-wrapper';
import type {AxiosWrapperOptions} from '@gravity-ui/axios-wrapper';
import axiosRetry from 'axios-retry';

import {backend as BACKEND} from '../../store';
import {backend as BACKEND, clusterName} from '../../store';
import {DEV_ENABLE_TRACING_FOR_ALL_REQUESTS} from '../../utils/constants';
import {prepareBackendWithMetaProxy} from '../../utils/parseBalancer';
import {isRedirectToAuth} from '../../utils/response';
import {settingsManager} from '../settings';

Expand All @@ -14,11 +15,19 @@ export type AxiosOptions = {
timeout?: number;
};

export interface BaseAPIParams {
singleClusterMode?: boolean;
}

export class BaseYdbAPI extends AxiosWrapper {
DEFAULT_RETRIES_COUNT = 0;

constructor(options?: AxiosWrapperOptions) {
super(options);
singleClusterMode?: boolean;

constructor(axiosOptions?: AxiosWrapperOptions, {singleClusterMode}: BaseAPIParams = {}) {
super(axiosOptions);

this.singleClusterMode = singleClusterMode;

axiosRetry(this._axios, {
retries: this.DEFAULT_RETRIES_COUNT,
Expand Down Expand Up @@ -74,6 +83,10 @@ export class BaseYdbAPI extends AxiosWrapper {
}

getPath(path: string) {
if (clusterName && !this.singleClusterMode && !BACKEND) {
return prepareBackendWithMetaProxy({clusterName}) + path;
}

return `${BACKEND ?? ''}${path}`;
}

Expand Down
28 changes: 16 additions & 12 deletions src/services/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {AxiosWrapperOptions} from '@gravity-ui/axios-wrapper';
import type {AxiosRequestConfig} from 'axios';

import {codeAssistBackend} from '../../store';
Expand Down Expand Up @@ -30,33 +31,36 @@ export class YdbEmbeddedAPI {
constructor({
webVersion = false,
withCredentials = false,
singleClusterMode,
csrfTokenGetter = () => undefined,
defaults = {},
}: {
webVersion?: boolean;
withCredentials?: boolean;
singleClusterMode?: boolean;
csrfTokenGetter?: () => string | undefined;
defaults?: AxiosRequestConfig;
} = {}) {
const config: AxiosRequestConfig = {withCredentials, ...defaults};
const axiosParams: AxiosWrapperOptions = {config: {withCredentials, ...defaults}};
const baseApiParams = {singleClusterMode};

this.auth = new AuthAPI({config});
this.auth = new AuthAPI(axiosParams, baseApiParams);
if (webVersion) {
this.meta = new MetaAPI({config});
this.meta = new MetaAPI(axiosParams, baseApiParams);
}

if (webVersion || codeAssistBackend) {
this.codeAssist = new CodeAssistAPI({config});
this.codeAssist = new CodeAssistAPI(axiosParams, baseApiParams);
}

this.operation = new OperationAPI({config});
this.pdisk = new PDiskAPI({config});
this.scheme = new SchemeAPI({config});
this.storage = new StorageAPI({config});
this.streaming = new StreamingAPI({config});
this.tablets = new TabletsAPI({config});
this.vdisk = new VDiskAPI({config});
this.viewer = new ViewerAPI({config});
this.operation = new OperationAPI(axiosParams, baseApiParams);
this.pdisk = new PDiskAPI(axiosParams, baseApiParams);
this.scheme = new SchemeAPI(axiosParams, baseApiParams);
this.storage = new StorageAPI(axiosParams, baseApiParams);
this.streaming = new StreamingAPI(axiosParams, baseApiParams);
this.tablets = new TabletsAPI(axiosParams, baseApiParams);
this.vdisk = new VDiskAPI(axiosParams, baseApiParams);
this.viewer = new ViewerAPI(axiosParams, baseApiParams);

const token = csrfTokenGetter();
if (token) {
Expand Down
6 changes: 5 additions & 1 deletion src/store/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const isSingleClusterMode = `${metaBackend}` === 'undefined';
export function configureStore({
aRootReducer = rootReducer,
singleClusterMode = isSingleClusterMode,
api = new YdbEmbeddedAPI({webVersion, withCredentials: !customBackend}),
api = new YdbEmbeddedAPI({
webVersion,
singleClusterMode: isSingleClusterMode,
withCredentials: !customBackend,
}),
getBackend = (params: ReturnType<typeof getUrlData>) => params.backend,
} = {}) {
const params = getUrlData({singleClusterMode, customBackend});
Expand Down
21 changes: 14 additions & 7 deletions src/store/reducers/clusters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ export const prepareClustersData = (data: MetaClusters): PreparedCluster[] => {
const versionsData = getVersionsData(allMinorVersions);

// Apply color map to every cluster in the list
return clusters.map((cluster) => ({
...cluster,
preparedVersions: prepareClusterVersions(cluster.versions, versionsData),
preparedBackend: cluster.balancer
? prepareBackendFromBalancer(cluster.balancer)
: undefined,
}));
return clusters.map((cluster) => {
// If no backend is provided, it will be automatically generated by API instance
const useMetaProxy = cluster.settings?.use_meta_proxy;
const preparedBackend =
cluster.balancer && !useMetaProxy
? prepareBackendFromBalancer(cluster.balancer)
: undefined;

return {
...cluster,
preparedVersions: prepareClusterVersions(cluster.versions, versionsData),
preparedBackend,
};
});
};
8 changes: 8 additions & 0 deletions src/utils/parseBalancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ export function prepareBackendFromBalancer(rawBalancer: string) {

return preparedBalancer;
}

export function prepareBackendWithMetaProxy({clusterName}: {clusterName?: string}) {
if (!clusterName) {
return undefined;
}

return prepareBackendFromBalancer(`/proxy/cluster/${clusterName}`);
}
Loading