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-1399 | bad resources toggle selection #804

Merged
24 changes: 18 additions & 6 deletions ui/apps/everest/.e2e/pr/db-cluster/db-cluster-overview.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect } from '@playwright/test';
import { createDbClusterFn, deleteDbClusterFn } from '@e2e/utils/db-cluster';
import { EVEREST_CI_NAMESPACES } from '@e2e/constants';
import { findDbAndClickRow } from '@e2e/utils/db-clusters-list';

test.describe('DB Cluster Overview', async () => {
const dbClusterName = 'cluster-overview-test';
Expand All @@ -10,9 +11,10 @@ test.describe('DB Cluster Overview', async () => {
dbName: dbClusterName,
dbType: 'mysql',
numberOfNodes: '1',
cpu: 0.6,
disk: 1,
memory: 1,
cpu: 1,
memory: 2,
proxyCpu: 0.5,
proxyMemory: 0.8,
externalAccess: true,
sourceRanges: [
{
Expand All @@ -31,9 +33,7 @@ test.describe('DB Cluster Overview', async () => {
});

test('Overview information', async ({ page }) => {
const row = await page.getByText(dbClusterName);

await row.click();
await findDbAndClickRow(page, dbClusterName);

await expect(
page.getByRole('heading', {
Expand Down Expand Up @@ -79,6 +79,18 @@ test.describe('DB Cluster Overview', async () => {
).toBeVisible();
});

test('Show the correct resources during editing', async ({ page }) => {
await findDbAndClickRow(page, dbClusterName);
await page.getByTestId('edit-resources-button').click();
await expect(
page.getByTestId('node-resources-toggle-button-small')
).toHaveAttribute('aria-pressed', 'true');
await page.getByTestId('proxies-accordion').click();
await expect(
page.getByTestId('proxy-resources-toggle-button-medium')
).toHaveAttribute('aria-pressed', 'true');
});

test('Delete Action', async ({ page, request }) => {
const dbName = 'delete-test';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ test.describe('DB Cluster Editing Resources Step (Mongo)', () => {
dbName: mongoDBName,
dbType: DbType.Mongo,
numberOfNodes: '5',
sharding: true,
cpu: 1,
memory: 4,
proxyCpu: 2,
proxyMemory: 4,
});
});

Expand All @@ -48,6 +53,13 @@ test.describe('DB Cluster Editing Resources Step (Mongo)', () => {
await moveForward(page);

await expect(page.getByTestId('toggle-button-nodes-5')).toBeVisible();
await expect(
page.getByTestId('node-resources-toggle-button-small')
).toHaveAttribute('aria-pressed', 'true');
await page.getByTestId('proxies-accordion').click();
await expect(
page.getByTestId('router-resources-toggle-button-medium')
).toHaveAttribute('aria-pressed', 'true');
const a = page
.getByRole('button', { pressed: true })
.filter({ hasText: '5 nodes' });
Expand All @@ -59,4 +71,56 @@ test.describe('DB Cluster Editing Resources Step (Mongo)', () => {
await page.getByTestId('button-edit-preview-resources').click();
await expect(page.getByTestId('text-input-disk')).toBeDisabled();
});

test('Show custom resources during editing', async ({ page, request }) => {
const dbName = 'mongo-custom-resources';
await createDbClusterFn(request, {
dbName,
dbType: DbType.Mongo,
numberOfNodes: '5',
sharding: true,
cpu: 1,
memory: 4,
proxyCpu: 3,
proxyMemory: 4,
});
await findDbAndClickActions(page, dbName, 'Edit');
await page.getByTestId('button-edit-preview-resources').click();
await expect(
page.getByTestId('node-resources-toggle-button-small')
).toHaveAttribute('aria-pressed', 'true');
await page.getByTestId('proxies-accordion').click();
await expect(
page.getByTestId('router-resources-toggle-button-custom')
).toHaveAttribute('aria-pressed', 'true');
await deleteDbClusterFn(request, dbName);
});

test('Show predefined resources regardless of disk', async ({
page,
request,
}) => {
const dbName = 'mongo-disk-resources';
await createDbClusterFn(request, {
dbName,
dbType: DbType.Mongo,
numberOfNodes: '5',
sharding: true,
cpu: 1,
memory: 4,
disk: 1,
proxyCpu: 2,
proxyMemory: 4,
});
await findDbAndClickActions(page, dbName, 'Edit');
await page.getByTestId('button-edit-preview-resources').click();
await expect(
page.getByTestId('node-resources-toggle-button-small')
).toHaveAttribute('aria-pressed', 'true');
await page.getByTestId('proxies-accordion').click();
await expect(
page.getByTestId('router-resources-toggle-button-medium')
).toHaveAttribute('aria-pressed', 'true');
await deleteDbClusterFn(request, dbName);
});
});
20 changes: 18 additions & 2 deletions ui/apps/everest/.e2e/utils/db-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
// limitations under the License.

import { APIRequestContext, expect } from '@playwright/test';
import { dbTypeToDbEngine } from '@percona/utils';
import { dbTypeToDbEngine, dbTypeToProxyType } from '@percona/utils';
import { getEnginesVersions } from './database-engines';
import { getClusterDetailedInfo } from './storage-class';
import { getTokenFromLocalStorage } from './localStorage';
import { getNamespacesFn } from './namespaces';
import { DbType } from '@percona/types';

export const createDbClusterFn = async (
request: APIRequestContext,
Expand Down Expand Up @@ -93,7 +94,12 @@ export const createDbClusterFn = async (
// }),
},
proxy: {
replicas: +(customOptions?.numberOfNodes || 1),
type: dbTypeToProxyType(dbType),
replicas: +(customOptions?.numberOfProxies || 1),
resources: {
cpu: `${customOptions?.proxyCpu || 1}`,
memory: `${customOptions?.proxyMemory || 1}G`,
},
expose: {
type: customOptions?.externalAccess ? 'external' : 'internal',
...(!!customOptions?.externalAccess &&
Expand All @@ -104,6 +110,16 @@ export const createDbClusterFn = async (
}),
},
},
...(customOptions.sharding &&
dbType === DbType.Mongo && {
sharding: {
enabled: true,
shards: customOptions.shards || 1,
configServer: {
replicas: customOptions.configServerReplicas || 3,
},
},
}),
// TODO return for backups tests
// ...(backupDataSource?.dbClusterBackupName && {
// dataSource: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DbType } from '@percona/types';
import { z } from 'zod';
import { Resources } from 'shared-types/dbCluster.types';
import { DbWizardFormFields } from 'consts';
import { memoryParser } from 'utils/k8ResourceParser';
import { cpuParser, memoryParser } from 'utils/k8ResourceParser';
import { Messages } from './messages';

const resourceToNumber = (minimum = 0) =>
Expand All @@ -15,19 +15,25 @@ const resourceToNumber = (minimum = 0) =>
);

export const matchFieldsValueToResourceSize = (
dbType: DbType,
sizes: Record<
Exclude<ResourceSize, ResourceSize.custom>,
Record<'cpu' | 'memory', number>
>,
resources?: Resources
): ResourceSize => {
if (!resources) {
return ResourceSize.custom;
}
const memory = memoryParser(resources.memory.toString());

const res = Object.values(NODES_DEFAULT_SIZES[dbType]).findIndex(
(item) => item.cpu === Number(resources.cpu) && item.memory === memory.value
);
const memory = memoryParser(resources.memory.toString(), 'G');
const res = Object.values(sizes).findIndex((item) => {
const sizeParsedMemory = memoryParser(item.memory.toString(), 'G');
return (
cpuParser(item.cpu.toString()) === cpuParser(resources.cpu.toString()) &&
sizeParsedMemory.value === memory.value
);
});
return res !== -1
? (Object.keys(NODES_DEFAULT_SIZES[dbType])[res] as ResourceSize)
? (Object.keys(sizes)[res] as ResourceSize)
: ResourceSize.custom;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,15 @@
}
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);
} else {
clearErrors(diskInputName);
}
}, [diskCapacityExceeded, clearErrors, setError]);

Check warning on line 200 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,16 +206,17 @@
) {
setValue(resourceSizePerUnitInputName, ResourceSize.custom);
}
}, [cpu, setValue]);

Check warning on line 209 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 (
allowDiskInputUpdate &&
resourceSizePerUnit !== ResourceSize.custom &&
disk !== sizeOptions[resourceSizePerUnit].disk
) {
setValue(resourceSizePerUnitInputName, ResourceSize.custom);
}
}, [disk, setValue]);
}, [disk, allowDiskInputUpdate, setValue]);

Check warning on line 219 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 +225,7 @@
) {
setValue(resourceSizePerUnitInputName, ResourceSize.custom);
}
}, [memory, setValue]);

Check warning on line 228 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 @@ -487,7 +490,14 @@
setValue(DbWizardFormFields.numberOfProxies, CUSTOM_NR_UNITS_INPUT_VALUE);
setValue(DbWizardFormFields.customNrOfProxies, customNrOfNodes);
}
}, [setValue, getFieldState, customNrOfNodes, dbType, numberOfNodes]);
}, [
setValue,
getFieldState,
customNrOfNodes,
dbType,
numberOfNodes,
pairProxiesWithNodes,
]);

useEffect(() => {
const { isTouched: isConfigServersTouched } = getFieldState(
Expand All @@ -510,11 +520,11 @@
}

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

Check warning on line 523 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

useEffect(() => {
trigger();
}, [numberOfNodes, customNrOfNodes]);

Check warning on line 527 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: 'trigger'. Either include it or remove the dependency array

return (
<>
Expand Down
5 changes: 1 addition & 4 deletions ui/apps/everest/src/hooks/api/db-cluster/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 { dbTypeToProxyType } from 'utils/db';

export const getProxySpec = (
dbType: DbType,
Expand All @@ -13,10 +13,7 @@ export const getProxySpec = (
sharding: boolean,
sourceRanges?: Array<{ sourceRange?: string }>
): 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
getDefaultNumberOfconfigServersByNumberOfNodes,
matchFieldsValueToResourceSize,
NODES_DB_TYPE_MAP,
NODES_DEFAULT_SIZES,
PROXIES_DEFAULT_SIZES,
} from 'components/cluster-form';

const replicasToNodes = (replicas: string, dbType: DbType): string => {
Expand Down Expand Up @@ -99,11 +101,11 @@ export const DbClusterPayloadToFormValues = (
[DbWizardFormFields.customNrOfNodes]: replicas,
[DbWizardFormFields.customNrOfProxies]: proxies,
[DbWizardFormFields.resourceSizePerNode]: matchFieldsValueToResourceSize(
dbEngineToDbType(dbCluster?.spec?.engine?.type),
NODES_DEFAULT_SIZES[dbEngineToDbType(dbCluster?.spec?.engine?.type)],
dbCluster?.spec?.engine?.resources
),
[DbWizardFormFields.resourceSizePerProxy]: matchFieldsValueToResourceSize(
dbEngineToDbType(dbCluster?.spec?.engine?.type),
PROXIES_DEFAULT_SIZES[dbEngineToDbType(dbCluster?.spec?.engine?.type)],
dbCluster?.spec?.proxy.resources
),
[DbWizardFormFields.sharding]: dbCluster?.spec?.sharding?.enabled || false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
CUSTOM_NR_UNITS_INPUT_VALUE,
matchFieldsValueToResourceSize,
NODES_DB_TYPE_MAP,
NODES_DEFAULT_SIZES,
PROXIES_DEFAULT_SIZES,
resourcesFormSchema,
} from 'components/cluster-form';
import OverviewSection from '../overview-section';
Expand Down Expand Up @@ -138,6 +140,7 @@ export const ResourcesDetails = ({
size="small"
startIcon={<EditOutlinedIcon />}
onClick={() => setOpenEditModal(true)}
data-testid="edit-resources-button"
>
Edit
</Button>
Expand Down Expand Up @@ -245,11 +248,11 @@ export const ResourcesDetails = ({
customNrOfNodes: replicas,
customNrOfProxies: proxies,
resourceSizePerNode: matchFieldsValueToResourceSize(
dbType,
NODES_DEFAULT_SIZES[dbType],
dbCluster.spec.engine.resources
),
resourceSizePerProxy: matchFieldsValueToResourceSize(
dbType,
PROXIES_DEFAULT_SIZES[dbType],
isProxy(dbCluster.spec.proxy)
? dbCluster.spec.proxy.resources
: undefined
Expand Down
3 changes: 2 additions & 1 deletion ui/apps/everest/src/shared-types/dbCluster.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { DbEngineType, ProxyType } from './dbEngines.types';
import { ProxyType } from '@percona/types';
import { DbEngineType } from './dbEngines.types';

export enum ProxyExposeType {
internal = 'internal',
Expand Down
2 changes: 0 additions & 2 deletions ui/apps/everest/src/shared-types/dbEngines.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,3 @@ export type OperatorsUpgradePlan = {
upgrades: OperatorUpgradeTask[];
pendingActions: OperatorUpgradePendingAction[];
};

export type ProxyType = 'mongos' | 'haproxy' | 'proxysql' | 'pgbouncer';
12 changes: 0 additions & 12 deletions ui/apps/everest/src/utils/db.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MongoIcon, MySqlIcon, PostgreSqlIcon } from '@percona/ui-lib';
import { DbType } from '@percona/types';
import { ProxyType } from 'shared-types/dbEngines.types';
import { Proxy } from 'shared-types/dbCluster.types';

export const dbTypeToIcon = (dbType: DbType) => {
Expand Down Expand Up @@ -30,17 +29,6 @@ export const shortenOperatorName = (name: string) => {
return name;
};

export const dbTypeToProxyType = (dbType: DbType): ProxyType => {
switch (dbType) {
case DbType.Mongo:
return 'mongos';
case DbType.Mysql:
return 'haproxy';
default:
return 'pgbouncer';
}
};

export const isProxy = (
proxy: Proxy | Record<string, never>
): proxy is Proxy => {
Expand Down
Loading
Loading