Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVEREST-1559 | remove proxy config for mongo with no sharding #760

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 @@ -139,7 +139,16 @@ test.describe('DB Cluster creation', () => {

await resourcesStepCheck(page);

// Same number of proxies as nodes, as user hasn't changed it
// Sharding off, no routers available
await expect(page.getByText('Routers (3)')).not.toBeVisible();

await moveBack(page);
await page
.getByTestId('switch-input-sharding-label')
.getByRole('checkbox')
.check();
await moveForward(page);

await expect(page.getByText('Routers (3)')).toBeVisible();
await page.getByTestId('proxies-accordion').getByRole('button').click();
await page.getByTestId('toggle-button-routers-1').click();
Expand Down Expand Up @@ -180,6 +189,10 @@ test.describe('DB Cluster creation', () => {
await page.getByTestId('button-edit-preview-basic-information').click();
// Because 2 nodes is not valid for MongoDB, the default will be picked
await page.getByTestId('mongodb-toggle-button').click();
await page
.getByTestId('switch-input-sharding-label')
.getByRole('checkbox')
.check();
await expect(page.getByText('Nº nodes: 3')).toBeVisible();
await page.getByTestId('button-edit-preview-backups').click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,25 @@ export const getDefaultNumberOfconfigServersByNumberOfNodes = (
} else return '7';
};

const numberOfResourcesValidator = (
numberOfResourcesStr: string,
customNrOfResoucesStr: string,
fieldPath: string,
ctx: z.RefinementCtx
) => {
if (numberOfResourcesStr === CUSTOM_NR_UNITS_INPUT_VALUE) {
const intNr = parseInt(customNrOfResoucesStr, 10);

if (Number.isNaN(intNr) || intNr < 1) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Please enter a valid number',
path: [fieldPath],
});
}
}
};

export const resourcesFormSchema = (passthrough?: boolean) => {
const objectShape = {
[DbWizardFormFields.shardNr]: z.string().optional(),
Expand Down Expand Up @@ -199,26 +218,21 @@ export const resourcesFormSchema = (passthrough?: boolean) => {
},
ctx
) => {
[
[numberOfNodes, customNrOfNodes, DbWizardFormFields.customNrOfNodes],
[
numberOfResourcesValidator(
numberOfNodes,
customNrOfNodes,
DbWizardFormFields.customNrOfNodes,
ctx
);

if (dbType !== DbType.Mongo || (dbType === DbType.Mongo && !!sharding)) {
numberOfResourcesValidator(
numberOfProxies,
customNrOfProxies,
customNrOfNodes,
DbWizardFormFields.customNrOfProxies,
],
].forEach(([nr, customNr, path]) => {
if (nr === CUSTOM_NR_UNITS_INPUT_VALUE) {
const intNr = parseInt(customNr, 10);

if (Number.isNaN(intNr) || intNr < 1) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Please enter a valid number',
path: [path],
});
}
}
});
ctx
);
}

if (
numberOfNodes === CUSTOM_NR_UNITS_INPUT_VALUE &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@
}
setValue(memoryInputName, sizeOptions[resourceSizePerUnit].memory);
}
}, [resourceSizePerUnit, allowDiskInputUpdate, setValue]);

Check warning on line 192 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has missing dependencies: 'cpuInputName', 'diskInputName', 'memoryInputName', and 'sizeOptions'. Either include them or remove the dependency array

useEffect(() => {
if (diskCapacityExceeded) {
setError(diskInputName, { type: 'custom' });
} else clearErrors(diskInputName);
}, [diskCapacityExceeded, clearErrors, setError]);

Check warning on line 198 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has a missing dependency: 'diskInputName'. Either include it or remove the dependency array

useEffect(() => {
if (
Expand All @@ -204,7 +204,7 @@
) {
setValue(resourceSizePerUnitInputName, ResourceSize.custom);
}
}, [cpu, setValue]);

Check warning on line 207 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has missing dependencies: 'resourceSizePerUnit', 'resourceSizePerUnitInputName', and 'sizeOptions'. Either include them or remove the dependency array

useEffect(() => {
if (
Expand All @@ -213,7 +213,7 @@
) {
setValue(resourceSizePerUnitInputName, ResourceSize.custom);
}
}, [disk, setValue]);

Check warning on line 216 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has missing dependencies: 'resourceSizePerUnit', 'resourceSizePerUnitInputName', and 'sizeOptions'. Either include them or remove the dependency array

useEffect(() => {
if (
Expand All @@ -222,7 +222,7 @@
) {
setValue(resourceSizePerUnitInputName, ResourceSize.custom);
}
}, [memory, setValue]);

Check warning on line 225 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has missing dependencies: 'resourceSizePerUnit', 'resourceSizePerUnitInputName', and 'sizeOptions'. Either include them or remove the dependency array

return (
<FormGroup sx={{ mt: 3 }}>
Expand Down Expand Up @@ -423,8 +423,10 @@
allowDiskInputUpdate,
pairProxiesWithNodes,
showSharding,
hideProxies = false,
}: {
dbType: DbType;
hideProxies?: boolean;
disableDiskInput?: boolean;
allowDiskInputUpdate?: boolean;
pairProxiesWithNodes?: boolean;
Expand Down Expand Up @@ -485,7 +487,7 @@
setValue(DbWizardFormFields.numberOfProxies, CUSTOM_NR_UNITS_INPUT_VALUE);
setValue(DbWizardFormFields.customNrOfProxies, customNrOfNodes);
}
}, [setValue, getFieldState, customNrOfNodes, dbType, numberOfNodes]);

Check warning on line 490 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has a missing dependency: 'pairProxiesWithNodes'. Either include it or remove the dependency array

useEffect(() => {
const { isDirty: isConfigServersDirty } = getFieldState(
Expand All @@ -508,7 +510,7 @@
}

trigger(DbWizardFormFields.shardConfigServers);
}, [setValue, getFieldState, numberOfNodes, customNrOfNodes]);

Check warning on line 513 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has missing dependencies: 'clearErrors' and 'trigger'. Either include them or remove the dependency array

return (
<>
Expand Down Expand Up @@ -559,37 +561,41 @@
disableCustom={dbType === DbType.Mysql}
/>
</Accordion>
<Accordion
expanded={expanded === 'proxies'}
data-testid="proxies-accordion"
onChange={handleAccordionChange('proxies')}
sx={{
px: 2,
}}
>
<CustomAccordionSummary
unitPlural={proxyUnitNames.plural}
nr={parseInt(proxiesAccordionSummaryNumber, 10)}
/>
<Divider />
<ResourcesToggles
dbType={dbType}
unit={proxyUnitNames.singular}
unitPlural={proxyUnitNames.plural}
options={NODES_DB_TYPE_MAP[dbType]}
sizeOptions={PROXIES_DEFAULT_SIZES[dbType]}
resourceSizePerUnitInputName={DbWizardFormFields.resourceSizePerProxy}
cpuInputName={DbWizardFormFields.proxyCpu}
memoryInputName={DbWizardFormFields.proxyMemory}
numberOfUnitsInputName={DbWizardFormFields.numberOfProxies}
customNrOfUnitsInputName={DbWizardFormFields.customNrOfProxies}
/>
{proxyFieldError && (
<FormHelperText error={true}>
{proxyFieldError?.message}
</FormHelperText>
)}
</Accordion>
{!hideProxies && (
<Accordion
expanded={expanded === 'proxies'}
data-testid="proxies-accordion"
onChange={handleAccordionChange('proxies')}
sx={{
px: 2,
}}
>
<CustomAccordionSummary
unitPlural={proxyUnitNames.plural}
nr={parseInt(proxiesAccordionSummaryNumber, 10)}
/>
<Divider />
<ResourcesToggles
dbType={dbType}
unit={proxyUnitNames.singular}
unitPlural={proxyUnitNames.plural}
options={NODES_DB_TYPE_MAP[dbType]}
sizeOptions={PROXIES_DEFAULT_SIZES[dbType]}
resourceSizePerUnitInputName={
DbWizardFormFields.resourceSizePerProxy
}
cpuInputName={DbWizardFormFields.proxyCpu}
memoryInputName={DbWizardFormFields.proxyMemory}
numberOfUnitsInputName={DbWizardFormFields.numberOfProxies}
customNrOfUnitsInputName={DbWizardFormFields.customNrOfProxies}
/>
{proxyFieldError && (
<FormHelperText error={true}>
{proxyFieldError?.message}
</FormHelperText>
)}
</Accordion>
)}
{!!showSharding && !!sharding && (
<CustomPaper sx={{ mt: 2 }}>
<Typography variant="sectionHeading">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const formValuesToPayloadMapping = (
dbPayload.externalAccess,
dbPayload.proxyCpu,
dbPayload.proxyMemory,
dbPayload.sharding,
dbPayload.sourceRanges || []
),
...(dbPayload.dbType === DbType.Mongo && {
Expand Down
78 changes: 44 additions & 34 deletions ui/apps/everest/src/hooks/api/db-cluster/useUpdateDbCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

import { UseMutationOptions, useMutation } from '@tanstack/react-query';
import { updateDbClusterFn } from 'api/dbClusterApi';
import { DbCluster } from 'shared-types/dbCluster.types';
import { DbCluster, Proxy } from 'shared-types/dbCluster.types';
import { DbWizardType } from 'pages/database-form/database-form-schema.ts';
import cronConverter from 'utils/cron-converter';
import { CUSTOM_NR_UNITS_INPUT_VALUE } from 'components/cluster-form';
import { getProxySpec } from './utils';
import { DbType } from '@percona/types';
import { DbEngineType } from 'shared-types/dbEngines.types';

type UpdateDbClusterArgType = {
dbPayload: DbWizardType;
Expand Down Expand Up @@ -95,31 +96,35 @@ const formValuesToPayloadOverrides = (
monitoringConfigName: dbPayload?.monitoringInstance!,
}),
},
proxy: {
...dbCluster.spec.proxy,
...getProxySpec(
dbPayload.dbType,
dbPayload.numberOfProxies,
dbPayload.customNrOfProxies || '',
dbPayload.externalAccess,
dbPayload.proxyCpu,
dbPayload.proxyMemory,
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:
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] : []
// ),
// }),
// },
},
...(dbPayload.dbType === DbType.Mongo && {
sharding: {
enabled: dbPayload.sharding,
Expand Down Expand Up @@ -235,6 +240,7 @@ export const useUpdateDbClusterResources = () =>
mutationFn: ({
dbCluster,
newResources,
sharding,
}: {
dbCluster: DbCluster;
newResources: {
Expand All @@ -247,6 +253,7 @@ export const useUpdateDbClusterResources = () =>
proxyMemory: number;
numberOfProxies: number;
};
sharding: boolean;
}) =>
updateDbClusterFn(dbCluster.metadata.name, dbCluster.metadata.namespace, {
...dbCluster,
Expand All @@ -264,14 +271,17 @@ export const useUpdateDbClusterResources = () =>
size: `${newResources.disk}${newResources.diskUnit}`,
},
},
proxy: {
...dbCluster.spec.proxy,
replicas: newResources.numberOfProxies,
resources: {
cpu: `${newResources.proxyCpu}`,
memory: `${newResources.proxyMemory}G`,
},
},
proxy:
dbCluster.spec.engine.type === DbEngineType.PSMDB && !sharding
? {}
: ({
...dbCluster.spec.proxy,
replicas: newResources.numberOfProxies,
resources: {
cpu: `${newResources.proxyCpu}`,
memory: `${newResources.proxyMemory}G`,
},
} as Proxy),
},
}),
});
Expand Down
12 changes: 11 additions & 1 deletion ui/apps/everest/src/hooks/api/db-cluster/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ export const getProxySpec = (
externalAccess: boolean,
cpu: number,
memory: number,
sharding: boolean,
sourceRanges?: Array<{ sourceRange?: string }>
): Proxy => {
): Proxy | Record<string, never> => {
console.log('dbType', dbType);
console.log('sharding', sharding);
if (dbType === DbType.Mongo && !sharding) {
console.log('returning empty object');
return {};
}
const proxyNr = parseInt(
numberOfProxies === CUSTOM_NR_UNITS_INPUT_VALUE
? customNrOfProxies
: numberOfProxies,
10
);
// const showResources =
// dbType !== DbType.Mongo || (dbType === DbType.Mongo && !sharding);

return {
type: dbTypeToProxyType(dbType),
replicas: proxyNr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ResourcesStep = () => {
const { watch } = useFormContext();
const mode = useDatabasePageMode();
const dbType: DbType = watch(DbWizardFormFields.dbType);
const shardingEnabled = watch(DbWizardFormFields.sharding);

return (
<>
Expand All @@ -23,6 +24,7 @@ export const ResourcesStep = () => {
disableDiskInput={mode === 'edit'}
allowDiskInputUpdate={mode !== 'edit'}
showSharding={dbType === DbType.Mongo}
hideProxies={dbType === DbType.Mongo && !shardingEnabled}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const DbClusterPayloadToFormValues = (
): DbWizardType => {
const backup = dbCluster?.spec?.backup;
const replicas = dbCluster?.spec?.engine?.replicas.toString();
const proxies = dbCluster?.spec?.proxy?.replicas.toString();
const proxies = (dbCluster?.spec?.proxy?.replicas || 0).toString();
const diskValues = memoryParser(
dbCluster?.spec?.engine?.storage?.size.toString()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DbClusterForNamespaceResult } from '../../hooks/api/db-clusters/useDbCl
import { Messages } from './dbClusterView.messages';
import { DbClusterTableElement } from './dbClusterView.types';
import { Backup, BackupStatus } from 'shared-types/backups.types';
import { isProxy } from 'utils/db';

const DB_CLUSTER_STATUS_HUMANIFIED: Record<DbClusterStatus, string> = {
[DbClusterStatus.ready]: Messages.statusProvider.up,
Expand Down Expand Up @@ -55,7 +56,9 @@ export const convertDbClusterPayloadToTableFormat = (
storage: cluster.spec.engine.storage.size,
nodes: cluster.spec.engine.replicas,
hostName: cluster.status ? cluster.status.hostname : '',
exposetype: cluster.spec.proxy.expose.type,
exposetype: isProxy(cluster.spec.proxy)
? cluster.spec.proxy.expose.type
: undefined,
port: cluster.status?.port,
monitoringConfigName:
cluster.spec.monitoring?.monitoringConfigName ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface DbClusterTableElement {
nodes: number;
hostName: string;
port?: number;
exposetype: ProxyExposeType;
exposetype?: ProxyExposeType;
monitoringConfigName?: string;
raw: DbCluster;
}
Loading
Loading