Skip to content

Commit f8a0db1

Browse files
authored
feat(Databases): use balancer + /node/:id as backend endpoint (#1418)
1 parent 90a3403 commit f8a0db1

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/containers/AppWithClusters/ExtendedCluster/ExtendedCluster.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import type {
55
AdditionalClusterProps,
66
AdditionalTenantsProps,
77
AdditionalVersionsProps,
8+
NodeAddress,
89
} from '../../../types/additionalProps';
910
import type {MetaClusterVersion} from '../../../types/api/meta';
1011
import type {ETenantType} from '../../../types/api/tenant';
1112
import {getVersionColors, getVersionMap} from '../../../utils/clusterVersionColors';
1213
import {cn} from '../../../utils/cn';
1314
import type {GetMonitoringClusterLink, GetMonitoringLink} from '../../../utils/monitoring';
1415
import {getCleanBalancerValue, removeViewerPathname} from '../../../utils/parseBalancer';
15-
import {getBackendFromNodeHost} from '../../../utils/prepareBackend';
16+
import {getBackendFromNodeHost, getBackendFromRawNodeData} from '../../../utils/prepareBackend';
1617
import type {Cluster} from '../../Cluster/Cluster';
1718
import {useClusterData} from '../useClusterData';
1819

@@ -76,7 +77,9 @@ const getAdditionalTenantsProps = (
7677
) => {
7778
const additionalTenantsProps: AdditionalTenantsProps = {};
7879

79-
additionalTenantsProps.prepareTenantBackend = (nodeHost: string | undefined) => {
80+
additionalTenantsProps.prepareTenantBackend = (
81+
nodeHostOrAddress: string | NodeAddress | undefined,
82+
) => {
8083
// Proxy received from balancer value, so it's necessary
8184
if (!balancer) {
8285
return undefined;
@@ -86,11 +89,15 @@ const getAdditionalTenantsProps = (
8689
return removeViewerPathname(balancer);
8790
}
8891

89-
if (!nodeHost) {
92+
if (!nodeHostOrAddress) {
9093
return undefined;
9194
}
9295

93-
return getBackendFromNodeHost(nodeHost, balancer);
96+
if (typeof nodeHostOrAddress === 'string') {
97+
return getBackendFromNodeHost(nodeHostOrAddress, balancer);
98+
}
99+
100+
return getBackendFromRawNodeData(nodeHostOrAddress, balancer, true) ?? undefined;
94101
};
95102

96103
if (monitoring && getMonitoringLink) {

src/containers/Tenants/Tenants.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
} from '../../store/reducers/tenants/selectors';
2828
import {setSearchValue, tenantsApi} from '../../store/reducers/tenants/tenants';
2929
import type {PreparedTenant} from '../../store/reducers/tenants/types';
30-
import type {AdditionalTenantsProps} from '../../types/additionalProps';
30+
import type {AdditionalTenantsProps, NodeAddress} from '../../types/additionalProps';
3131
import {cn} from '../../utils/cn';
3232
import {DEFAULT_TABLE_SETTINGS} from '../../utils/constants';
3333
import {
@@ -93,8 +93,18 @@ export const Tenants = ({additionalTenantsProps}: TenantsProps) => {
9393

9494
const renderTable = () => {
9595
const getTenantBackend = (tenant: PreparedTenant) => {
96-
const backend = tenant.MonitoringEndpoint ?? tenant.backend;
97-
return additionalTenantsProps?.prepareTenantBackend?.(backend);
96+
if (typeof additionalTenantsProps?.prepareTenantBackend !== 'function') {
97+
return undefined;
98+
}
99+
100+
let backend: string | NodeAddress | undefined =
101+
tenant.MonitoringEndpoint ?? tenant.backend;
102+
const nodeIds = tenant.NodeIds ?? tenant.sharedNodeIds;
103+
if (!backend && nodeIds && nodeIds.length > 0) {
104+
const index = Math.floor(Math.random() * nodeIds.length);
105+
backend = {NodeId: nodeIds[index]};
106+
}
107+
return additionalTenantsProps.prepareTenantBackend(backend);
98108
};
99109

100110
const columns: Column<PreparedTenant>[] = [

src/store/reducers/tenants/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {METRIC_STATUS} from './contants';
66
export interface PreparedTenant extends TTenant {
77
backend: string | undefined;
88
sharedTenantName: string | undefined;
9+
sharedNodeIds: number[] | undefined;
910
controlPlaneName: string;
1011
cpu: number | undefined;
1112
memory: number | undefined;

src/store/reducers/tenants/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ const calculateTenantEntities = (tenant: TTenant) => {
178178
export const prepareTenants = (tenants: TTenant[], useNodeAsBackend: boolean): PreparedTenant[] => {
179179
return tenants.map((tenant) => {
180180
const backend = useNodeAsBackend ? getTenantBackend(tenant) : undefined;
181-
const sharedTenantName = tenants.find((item) => item.Id === tenant.ResourceId)?.Name;
181+
const sharedDatabase = tenants.find((item) => item.Id === tenant.ResourceId);
182+
const sharedTenantName = sharedDatabase?.Name;
183+
const sharedNodeIds = sharedDatabase?.NodeIds;
182184
const controlPlaneName = getControlPlaneValue(tenant);
183185
const {cpu, memory, blobStorage} = calculateTenantMetrics(tenant);
184186
const {nodesCount, groupsCount} = calculateTenantEntities(tenant);
@@ -188,6 +190,7 @@ export const prepareTenants = (tenants: TTenant[], useNodeAsBackend: boolean): P
188190

189191
backend,
190192
sharedTenantName,
193+
sharedNodeIds,
191194
controlPlaneName,
192195
cpu,
193196
memory,

src/types/additionalProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface AdditionalClusterProps {
1919
}
2020

2121
export interface AdditionalTenantsProps {
22-
prepareTenantBackend?: (backend: string | undefined) => string | undefined;
22+
prepareTenantBackend?: (backend: string | NodeAddress | undefined) => string | undefined;
2323
getMonitoringLink?: (name?: string, type?: ETenantType) => React.ReactNode;
2424
}
2525

0 commit comments

Comments
 (0)