diff --git a/src/containers/AppWithClusters/utils/useAdditionalTenantsProps.tsx b/src/containers/AppWithClusters/utils/useAdditionalTenantsProps.tsx index 0626f17286..b2722296d4 100644 --- a/src/containers/AppWithClusters/utils/useAdditionalTenantsProps.tsx +++ b/src/containers/AppWithClusters/utils/useAdditionalTenantsProps.tsx @@ -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; diff --git a/src/services/api/base.ts b/src/services/api/base.ts index 0d1d85b884..8bb84c0329 100644 --- a/src/services/api/base.ts +++ b/src/services/api/base.ts @@ -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'; @@ -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, @@ -74,6 +83,10 @@ export class BaseYdbAPI extends AxiosWrapper { } getPath(path: string) { + if (clusterName && !this.singleClusterMode && !BACKEND) { + return prepareBackendWithMetaProxy({clusterName}) + path; + } + return `${BACKEND ?? ''}${path}`; } diff --git a/src/services/api/index.ts b/src/services/api/index.ts index 3ba6bfb483..daee91bbd6 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -1,3 +1,4 @@ +import type {AxiosWrapperOptions} from '@gravity-ui/axios-wrapper'; import type {AxiosRequestConfig} from 'axios'; import {codeAssistBackend} from '../../store'; @@ -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) { diff --git a/src/store/configureStore.ts b/src/store/configureStore.ts index 3e8b93b15f..d481984a58 100644 --- a/src/store/configureStore.ts +++ b/src/store/configureStore.ts @@ -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) => params.backend, } = {}) { const params = getUrlData({singleClusterMode, customBackend}); diff --git a/src/store/reducers/clusters/utils.ts b/src/store/reducers/clusters/utils.ts index 5d562a07e9..574f35592f 100644 --- a/src/store/reducers/clusters/utils.ts +++ b/src/store/reducers/clusters/utils.ts @@ -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, + }; + }); }; diff --git a/src/utils/parseBalancer.ts b/src/utils/parseBalancer.ts index 1c64f1e886..c8b9767a34 100644 --- a/src/utils/parseBalancer.ts +++ b/src/utils/parseBalancer.ts @@ -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}`); +}