Skip to content

Commit

Permalink
Everest-1546 | Proxy resources (#794)
Browse files Browse the repository at this point in the history
* feat: add proxy resources to db preview sidebar

* feat: show proxy resources on expanded row

* feat: add dividers to db details row

* feat: show proxy resources on db details page

* fix: test

* fix: default value

* fix: test

---------

Co-authored-by: Diana Birsan <[email protected]>
  • Loading branch information
fabio-silva and dianabirs authored Oct 30, 2024
1 parent 36d02d2 commit cadb28a
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('DatabasePreview', () => {
expect(screen.getByText('Version: 1.0.0')).toBeInTheDocument();

expect(screen.getByText('Nº nodes: 1')).toBeInTheDocument();
expect(screen.getByText('CPU: 1.00 CPU')).toBeInTheDocument();
expect(screen.getAllByText('CPU: 1.00 CPU').length).toBeGreaterThan(1);
expect(screen.getByText('Disk: 30.00 Gi')).toBeInTheDocument();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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 { StackProps } from '@mui/material';
import { StackProps, TypographyProps } from '@mui/material';

export type DatabasePreviewProps = {
// zero indexed
Expand All @@ -35,4 +35,4 @@ export type PreviewSectionProps = {
export type PreviewContentTextProps = {
text: string;
dataTestId?: string;
};
} & TypographyProps;
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ export const PreviewSection = ({
export const PreviewContentText = ({
text,
dataTestId,
...typographyProps
}: PreviewContentTextProps) => (
<Typography
variant="caption"
color="text.secondary"
data-testid={
dataTestId ? `${dataTestId}-preview-content` : 'preview-content'
}
{...typographyProps}
>
{text}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
import { CUSTOM_NR_UNITS_INPUT_VALUE } from 'components/cluster-form';
import { PreviewContentText } from '../preview-section';
import { SectionProps } from './section.types';
import { getProxyUnitNamesFromDbType } from 'components/cluster-form/resources/utils';

export const ResourcesPreviewSection = ({
dbType,
numberOfNodes,
customNrOfNodes,
numberOfProxies,
customNrOfProxies,
cpu,
disk,
diskUnit,
memory,
proxyCpu,
proxyMemory,
sharding,
shardNr,
shardConfigServers,
}: SectionProps) => {
const proxyUnitNames = getProxyUnitNamesFromDbType(dbType);
if (numberOfNodes === CUSTOM_NR_UNITS_INPUT_VALUE) {
numberOfNodes = customNrOfNodes || '';
}

if (numberOfProxies === CUSTOM_NR_UNITS_INPUT_VALUE) {
numberOfProxies = customNrOfProxies || '';
}

let intNumberOfNodes = Math.max(parseInt(numberOfNodes, 10), 0);
let intNumberOfProxies = Math.max(parseInt(numberOfProxies, 10), 0);

if (Number.isNaN(intNumberOfNodes)) {
intNumberOfNodes = 0;
}

if (Number.isNaN(intNumberOfProxies)) {
intNumberOfProxies = 0;
}

const parsedCPU = Number(cpu) * intNumberOfNodes;
const parsedDisk = Number(disk) * intNumberOfNodes;
const parsedMemory = Number(memory) * intNumberOfNodes;
const parsedProxyCPU = Number(proxyCpu) * intNumberOfProxies;
const parsedProxyMemory = Number(proxyMemory) * intNumberOfProxies;

return (
<>
Expand All @@ -49,6 +67,20 @@ export const ResourcesPreviewSection = ({
<PreviewContentText
text={`Disk: ${Number.isNaN(parsedDisk) ? '' : `${parsedDisk.toFixed(2)} ${diskUnit}`}`}
/>
<PreviewContentText
text={`Nº ${proxyUnitNames.plural}: ${intNumberOfProxies}`}
mt={2}
/>
<PreviewContentText
text={`CPU: ${Number.isNaN(parsedProxyCPU) ? '' : `${parsedProxyCPU.toFixed(2)} CPU`}`}
/>
<PreviewContentText
text={`Memory: ${
Number.isNaN(parsedProxyMemory)
? ''
: `${parsedProxyMemory.toFixed(2)} GB`
}`}
/>
</>
);
};
3 changes: 3 additions & 0 deletions ui/apps/everest/src/pages/databases/DbClusterView.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ 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 || '',
hostName: cluster.status ? cluster.status.hostname : '',
exposetype: isProxy(cluster.spec.proxy)
? cluster.spec.proxy.expose.type
Expand Down
3 changes: 3 additions & 0 deletions ui/apps/everest/src/pages/databases/dbClusterView.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export interface DbClusterTableElement {
cpu: string | number;
memory: string | number;
storage: string | number;
proxyCpu: string | number;
proxyMemory: string | number;
nodes: number;
proxies: number;
hostName: string;
port?: number;
exposetype?: ProxyExposeType;
Expand Down
33 changes: 32 additions & 1 deletion ui/apps/everest/src/pages/databases/expandedRow/ExpandedRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { Box, Skeleton, Typography } from '@mui/material';
import { Box, Divider, Skeleton, Typography } from '@mui/material';
import { CopyToClipboardButton } from '@percona/ui-lib';
import { HiddenPasswordToggle } from 'components/hidden-row';
import { useDbClusterCredentials } from 'hooks/api/db-cluster/useCreateDbCluster';
Expand All @@ -28,17 +28,23 @@ import {
getTotalResourcesDetailedString,
memoryParser,
} from 'utils/k8ResourceParser';
import { getProxyUnitNamesFromDbType } from 'components/cluster-form/resources/utils';
import { dbEngineToDbType } from '@percona/utils';

export const ExpandedRow = ({
row,
}: {
row: MRT_Row<DbClusterTableElement>;
}) => {
const {
dbType,
cpu,
memory,
storage,
nodes,
proxies,
proxyCpu,
proxyMemory,
exposetype,
namespace,
databaseName,
Expand All @@ -48,16 +54,27 @@ export const ExpandedRow = ({
} = row.original;
const parsedDiskValues = memoryParser(storage.toString());
const parsedMemoryValues = memoryParser(memory.toString());
const parsedProxyMemoryValues = memoryParser(proxyMemory.toString());
const cpuResourcesStr = getTotalResourcesDetailedString(
cpuParser(cpu.toString() || '0'),
nodes,
'CPU'
);
const cpuProxyResourcesStr = getTotalResourcesDetailedString(
cpuParser(proxyCpu.toString() || '0'),
proxies,
'CPU'
);
const memoryResourcesStr = getTotalResourcesDetailedString(
parsedMemoryValues.value,
nodes,
parsedMemoryValues.originalUnit
);
const memoryProxyResourcesStr = getTotalResourcesDetailedString(
parsedProxyMemoryValues.value,
proxies,
parsedProxyMemoryValues.originalUnit
);
const storageResourcesStr = getTotalResourcesDetailedString(
parsedDiskValues.value,
nodes,
Expand Down Expand Up @@ -151,6 +168,20 @@ export const ExpandedRow = ({
label={Messages.expandedRow.disk}
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' }} />
<LabelValue
label={Messages.expandedRow.externalAccess}
value={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { dbEngineToDbType } from '@percona/utils';
import { DB_CLUSTER_QUERY, useUpdateDbClusterResources } from 'hooks';
import { DbType } from '@percona/types';
import { isProxy } from 'utils/db';
import { getProxyUnitNamesFromDbType } from 'components/cluster-form/resources/utils';

export const ResourcesDetails = ({
dbCluster,
Expand All @@ -57,6 +58,7 @@ export const ResourcesDetails = ({
const disk = dbCluster.spec.engine.storage.size;
const parsedDiskValues = memoryParser(disk.toString());
const parsedMemoryValues = memoryParser(memory.toString());
const parsedProxyMemoryValues = memoryParser(proxyMemory.toString());
const dbType = dbEngineToDbType(dbCluster.spec.engine.type);
const replicas = dbCluster.spec.engine.replicas.toString();
const proxies = isProxy(dbCluster.spec.proxy)
Expand Down Expand Up @@ -193,6 +195,27 @@ export const ResourcesDetails = ({
)}
/>
</OverviewSection>
<OverviewSection
title={`${proxies} ${getProxyUnitNamesFromDbType(dbEngineToDbType(dbCluster.spec.engine.type))[+proxies > 1 ? 'plural' : 'singular']}`}
loading={loading}
>
<OverviewSectionRow
label={Messages.fields.cpu}
contentString={getTotalResourcesDetailedString(
cpuParser(proxyCpu.toString() || '0'),
parseInt(proxies, 10),
'CPU'
)}
/>
<OverviewSectionRow
label={Messages.fields.memory}
contentString={getTotalResourcesDetailedString(
parsedProxyMemoryValues.value,
parseInt(proxies, 10),
parsedProxyMemoryValues.originalUnit
)}
/>
</OverviewSection>
</Stack>
</OverviewCard>
{openEditModal && (
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/everest/src/utils/k8ResourceParser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ export const getTotalResourcesDetailedString = (

const totalResources = value * numberOfNodes;

return `${numberOfNodes} x ${value} ${unit} = ${totalResources} ${unit}`;
return `${numberOfNodes} x ${value} ${unit} = ${totalResources.toFixed(2)} ${unit}`;
};

0 comments on commit cadb28a

Please sign in to comment.