Skip to content

Commit

Permalink
fix: wrong proxy expose type for psmdb (#801)
Browse files Browse the repository at this point in the history
* fix: wrong proxy expose type for psmdb

* chore: remove log
  • Loading branch information
fabio-silva authored Nov 6, 2024
1 parent b5de6fd commit bfe142e
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 126 deletions.
66 changes: 26 additions & 40 deletions ui/apps/everest/src/hooks/api/db-cluster/useUpdateDbCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { getProxySpec } from './utils';
import { DbType } from '@percona/types';
import { DbEngineType } from 'shared-types/dbEngines.types';
import { dbEngineToDbType } from '@percona/utils';

type UpdateDbClusterArgType = {
dbPayload: DbWizardType;
Expand Down Expand Up @@ -99,35 +100,19 @@ const formValuesToPayloadOverrides = (
monitoringConfigName: dbPayload?.monitoringInstance!,
}),
},
proxy:
dbPayload.dbType === DbType.Mongo && !dbPayload.sharding
? {}
: {
...dbCluster.spec.proxy,
...getProxySpec(
dbPayload.dbType,
dbPayload.numberOfProxies,
dbPayload.customNrOfProxies || '',
dbPayload.externalAccess,
dbPayload.proxyCpu,
dbPayload.proxyMemory,
dbPayload.sharding,
dbPayload.sourceRanges || []
),
// replicas: numberOfNodes,
// expose: {
// ...dbCluster.spec.proxy.expose,
// type: dbPayload.externalAccess
// ? ProxyExposeType.external
// : ProxyExposeType.internal,
// ...(!!dbPayload.externalAccess &&
// dbPayload.sourceRanges && {
// ipSourceRanges: dbPayload.sourceRanges.flatMap((source) =>
// source.sourceRange ? [source.sourceRange] : []
// ),
// }),
// },
},
proxy: {
...dbCluster.spec.proxy,
...getProxySpec(
dbPayload.dbType,
dbPayload.numberOfProxies,
dbPayload.customNrOfProxies || '',
dbPayload.externalAccess,
dbPayload.proxyCpu,
dbPayload.proxyMemory,
dbPayload.sharding,
dbPayload.sourceRanges || []
),
},
...(dbPayload.dbType === DbType.Mongo && {
sharding: {
enabled: dbPayload.sharding,
Expand Down Expand Up @@ -278,17 +263,18 @@ export const useUpdateDbClusterResources = () =>
size: `${newResources.disk}${newResources.diskUnit}`,
},
},
proxy:
dbCluster.spec.engine.type === DbEngineType.PSMDB && !sharding
? {}
: ({
...dbCluster.spec.proxy,
replicas: newResources.numberOfProxies,
resources: {
cpu: `${newResources.proxyCpu}`,
memory: `${newResources.proxyMemory}G`,
},
} as Proxy),
proxy: getProxySpec(
dbEngineToDbType(dbCluster.spec.engine.type),
newResources.numberOfProxies.toString(),
'',
(dbCluster.spec.proxy as Proxy).expose.type === 'external',
newResources.proxyCpu,
newResources.proxyMemory,
!!sharding,
((dbCluster.spec.proxy as Proxy).expose.ipSourceRanges || []).map(
(sourceRange) => ({ sourceRange })
)
),
...(dbCluster.spec.engine.type === DbEngineType.PSMDB &&
sharding && {
sharding: {
Expand Down
37 changes: 23 additions & 14 deletions ui/apps/everest/src/hooks/api/db-cluster/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import { DbType } from '@percona/types';
import { dbTypeToProxyType } from '@percona/utils';
import { CUSTOM_NR_UNITS_INPUT_VALUE } from 'components/cluster-form';
import { Proxy, ProxyExposeType } from 'shared-types/dbCluster.types';
import {
Proxy,
ProxyExposeConfig,
ProxyExposeType,
} from 'shared-types/dbCluster.types';

const getExposteConfig = (
externalAccess: boolean,
sourceRanges?: Array<{ sourceRange?: string }>
): ProxyExposeConfig => ({
type: externalAccess ? ProxyExposeType.external : ProxyExposeType.internal,
...(!!externalAccess &&
sourceRanges && {
ipSourceRanges: sourceRanges.flatMap((source) =>
source.sourceRange ? [source.sourceRange] : []
),
}),
});

export const getProxySpec = (
dbType: DbType,
Expand All @@ -12,9 +29,11 @@ export const getProxySpec = (
memory: number,
sharding: boolean,
sourceRanges?: Array<{ sourceRange?: string }>
): Proxy | Record<string, never> => {
): Proxy | ProxyExposeConfig => {
if (dbType === DbType.Mongo && !sharding) {
return {};
return {
expose: getExposteConfig(externalAccess, sourceRanges),
} as unknown as ProxyExposeConfig;
}
const proxyNr = parseInt(
numberOfProxies === CUSTOM_NR_UNITS_INPUT_VALUE
Expand All @@ -32,16 +51,6 @@ export const getProxySpec = (
cpu: `${cpu}`,
memory: `${memory}G`,
},
expose: {
type: externalAccess
? ProxyExposeType.external
: ProxyExposeType.internal,
...(!!externalAccess &&
sourceRanges && {
ipSourceRanges: sourceRanges.flatMap((source) =>
source.sourceRange ? [source.sourceRange] : []
),
}),
},
expose: getExposteConfig(externalAccess, sourceRanges),
};
};
44 changes: 28 additions & 16 deletions ui/apps/everest/src/pages/database-form/database-form.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import {
getDefaultNumberOfconfigServersByNumberOfNodes,
matchFieldsValueToResourceSize,
NODES_DB_TYPE_MAP,
ResourceSize,
NODES_DEFAULT_SIZES,
PROXIES_DEFAULT_SIZES,
} from 'components/cluster-form';
import { isProxy } from 'utils/db.tsx';

const replicasToNodes = (replicas: string, dbType: DbType): string => {
const nodeOptions = NODES_DB_TYPE_MAP[dbType];
Expand All @@ -51,7 +53,9 @@ export const DbClusterPayloadToFormValues = (
): DbWizardType => {
const backup = dbCluster?.spec?.backup;
const replicas = dbCluster?.spec?.engine?.replicas.toString();
const proxies = (dbCluster?.spec?.proxy?.replicas || 0).toString();
const proxies = (
isProxy(dbCluster?.spec?.proxy) ? dbCluster?.spec?.proxy?.replicas || 0 : 0
).toString();
const diskValues = memoryParser(
dbCluster?.spec?.engine?.storage?.size.toString()
);
Expand All @@ -61,6 +65,9 @@ export const DbClusterPayloadToFormValues = (
replicas,
dbEngineToDbType(dbCluster?.spec?.engine?.type)
);
const sourceRangesSource = isProxy(dbCluster?.spec?.proxy)
? dbCluster?.spec?.proxy?.expose.ipSourceRanges
: dbCluster?.spec?.proxy.ipSourceRanges;

return {
//basic info
Expand All @@ -77,17 +84,15 @@ export const DbClusterPayloadToFormValues = (
)
: dbCluster?.metadata?.name,
[DbWizardFormFields.dbVersion]: dbCluster?.spec?.engine?.version || '',
[DbWizardFormFields.externalAccess]:
dbCluster?.spec?.proxy?.expose?.type === ProxyExposeType.external,
[DbWizardFormFields.externalAccess]: isProxy(dbCluster?.spec?.proxy)
? dbCluster?.spec?.proxy?.expose?.type === ProxyExposeType.external
: dbCluster?.spec?.proxy.type === ProxyExposeType.external,
// [DbWizardFormFields.internetFacing]: true,
[DbWizardFormFields.engineParametersEnabled]:
!!dbCluster?.spec?.engine?.config,
[DbWizardFormFields.engineParameters]: dbCluster?.spec?.engine?.config,
[DbWizardFormFields.sourceRanges]: dbCluster?.spec?.proxy?.expose
?.ipSourceRanges
? dbCluster?.spec?.proxy?.expose?.ipSourceRanges.map((item) => ({
sourceRange: item,
}))
[DbWizardFormFields.sourceRanges]: sourceRangesSource
? sourceRangesSource.map((sourceRange) => ({ sourceRange }))
: [{ sourceRange: '' }],
[DbWizardFormFields.monitoring]:
!!dbCluster?.spec?.monitoring?.monitoringConfigName,
Expand All @@ -104,10 +109,14 @@ export const DbClusterPayloadToFormValues = (
NODES_DEFAULT_SIZES[dbEngineToDbType(dbCluster?.spec?.engine?.type)],
dbCluster?.spec?.engine?.resources
),
[DbWizardFormFields.resourceSizePerProxy]: matchFieldsValueToResourceSize(
PROXIES_DEFAULT_SIZES[dbEngineToDbType(dbCluster?.spec?.engine?.type)],
dbCluster?.spec?.proxy.resources
),
[DbWizardFormFields.resourceSizePerProxy]: isProxy(dbCluster?.spec?.proxy)
? matchFieldsValueToResourceSize(
PROXIES_DEFAULT_SIZES[
dbEngineToDbType(dbCluster?.spec?.engine?.type)
],
dbCluster?.spec?.proxy.resources
)
: ResourceSize.small,
[DbWizardFormFields.sharding]: dbCluster?.spec?.sharding?.enabled || false,
[DbWizardFormFields.shardConfigServers]: (
sharding?.configServer?.replicas ||
Expand All @@ -120,17 +129,20 @@ export const DbClusterPayloadToFormValues = (
[DbWizardFormFields.cpu]: cpuParser(
dbCluster?.spec?.engine?.resources?.cpu.toString() || '0'
),
[DbWizardFormFields.proxyCpu]: cpuParser(
dbCluster?.spec?.proxy?.resources?.cpu.toString() || '0'
),
[DbWizardFormFields.proxyCpu]: isProxy(dbCluster?.spec?.proxy)
? cpuParser(dbCluster?.spec?.proxy?.resources?.cpu.toString() || '0')
: 0,
[DbWizardFormFields.disk]: diskValues.value,
[DbWizardFormFields.diskUnit]: diskValues.originalUnit,
[DbWizardFormFields.memory]: memoryParser(
(dbCluster?.spec?.engine?.resources?.memory || 0).toString(),
'G'
).value,
[DbWizardFormFields.proxyMemory]: memoryParser(
(dbCluster?.spec?.proxy?.resources?.memory || 0).toString(),
(isProxy(dbCluster?.spec?.proxy)
? dbCluster?.spec?.proxy?.resources?.memory || 0
: 0
).toString(),
'G'
).value,
[DbWizardFormFields.storageClass]:
Expand Down
12 changes: 9 additions & 3 deletions ui/apps/everest/src/pages/databases/DbClusterView.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ export const convertDbClusterPayloadToTableFormat = (
memory: cluster.spec.engine.resources?.memory || '',
storage: cluster.spec.engine.storage.size,
nodes: cluster.spec.engine.replicas,
proxies: cluster.spec.proxy.replicas || 0,
proxyCpu: cluster.spec.proxy.resources?.cpu || '',
proxyMemory: cluster.spec.proxy.resources?.memory || '',
proxies: isProxy(cluster.spec.proxy)
? cluster.spec.proxy.replicas || 0
: 0,
proxyCpu: isProxy(cluster.spec.proxy)
? cluster.spec.proxy.resources?.cpu || ''
: '',
proxyMemory: isProxy(cluster.spec.proxy)
? cluster.spec.proxy.resources?.memory || ''
: '',
hostName: cluster.status ? cluster.status.hostname : '',
exposetype: isProxy(cluster.spec.proxy)
? cluster.spec.proxy.expose.type
Expand Down
31 changes: 18 additions & 13 deletions ui/apps/everest/src/pages/databases/expandedRow/ExpandedRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ExpandedRow = ({
port,
raw,
} = row.original;

const parsedDiskValues = memoryParser(storage.toString());
const parsedMemoryValues = memoryParser(memory.toString());
const parsedProxyMemoryValues = memoryParser(proxyMemory.toString());
Expand Down Expand Up @@ -169,19 +170,23 @@ export const ExpandedRow = ({
value={storageResourcesStr}
/>
<Divider sx={{ margin: '10px 0' }} />
<LabelValue
label={`Nº ${getProxyUnitNamesFromDbType(dbEngineToDbType(dbType)).plural}`}
value={nodes}
/>
<LabelValue
label={Messages.expandedRow.cpu}
value={cpuProxyResourcesStr}
/>
<LabelValue
label={Messages.expandedRow.memory}
value={memoryProxyResourcesStr}
/>
<Divider sx={{ margin: '10px 0' }} />
{proxies > 0 && (
<>
<LabelValue
label={`Nº ${getProxyUnitNamesFromDbType(dbEngineToDbType(dbType)).plural}`}
value={proxies}
/>
<LabelValue
label={Messages.expandedRow.cpu}
value={cpuProxyResourcesStr}
/>
<LabelValue
label={Messages.expandedRow.memory}
value={memoryProxyResourcesStr}
/>
<Divider sx={{ margin: '10px 0' }} />
</>
)}
<LabelValue
label={Messages.expandedRow.externalAccess}
value={
Expand Down
Loading

0 comments on commit bfe142e

Please sign in to comment.