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

FE: Broker not shown in a list if disk usage is unknown for it #3981

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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 @@ -12,17 +12,18 @@ import { ColumnDef } from '@tanstack/react-table';
import { clusterBrokerPath } from 'lib/paths';
import Tooltip from 'components/common/Tooltip/Tooltip';
import ColoredCell from 'components/common/NewTable/ColoredCell';
import { BrokerDiskUsage } from 'generated-sources';

import SkewHeader from './SkewHeader/SkewHeader';
import * as S from './BrokersList.styled';

const NA = 'N/A';
const NA = 'N/A' as unknown;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are going to do type casting can't we do it all of it here ? otherwise it the half of it are someplace.


const BrokersList: React.FC = () => {
const navigate = useNavigate();
const { clusterName } = useAppParams<{ clusterName: ClusterName }>();
const { data: clusterStats = {} } = useClusterStats(clusterName);
const { data: brokers } = useBrokers(clusterName);
const { data: brokers = [] } = useBrokers(clusterName);

const {
brokerCount,
Expand All @@ -37,34 +38,46 @@ const BrokersList: React.FC = () => {
} = clusterStats;

const rows = React.useMemo(() => {
let brokersResource;
let brokersResource: BrokerDiskUsage[];
if (!diskUsage || !diskUsage?.length) {
brokersResource =
brokers?.map((broker) => {
return {
brokerId: broker.id,
segmentSize: NA,
segmentCount: NA,
segmentSize: NA as number,
segmentCount: NA as number,
};
}) || [];
} else {
brokersResource = diskUsage;
}

return brokersResource.map(({ brokerId, segmentSize, segmentCount }) => {
const broker = brokers?.find(({ id }) => id === brokerId);
return {
brokerId,
size: segmentSize || NA,
count: segmentCount || NA,
port: broker?.port,
host: broker?.host,
partitionsLeader: broker?.partitionsLeader,
partitionsSkew: broker?.partitionsSkew,
leadersSkew: broker?.leadersSkew,
inSyncPartitions: broker?.inSyncPartitions,
};
});
return brokers?.map(
({
id,
port,
host,
partitionsLeader,
partitionsSkew,
leadersSkew,
inSyncPartitions,
}) => {
const brokerResource = brokersResource.find(
({ brokerId }) => id === brokerId
);
return {
brokerId: id,
size: brokerResource?.segmentSize || NA,
count: brokerResource?.segmentCount || NA,
port,
host,
partitionsLeader,
partitionsSkew,
leadersSkew,
inSyncPartitions,
};
}
);
}, [diskUsage, brokers]);

const columns = React.useMemo<ColumnDef<(typeof rows)[number]>[]>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ describe('BrokersList Component', () => {
});
it('opens broker when row clicked', async () => {
renderComponent();
await userEvent.click(screen.getByRole('cell', { name: '0' }));
await userEvent.click(screen.getByRole('cell', { name: '1' }));

await waitFor(() =>
expect(mockedUsedNavigate).toBeCalledWith(
clusterBrokerPath(clusterName, '0')
clusterBrokerPath(clusterName, '1')
)
);
});
Expand Down Expand Up @@ -166,5 +166,24 @@ describe('BrokersList Component', () => {
);
});
});

describe('when some brokers have no diskUsage', () => {
beforeEach(() => {
(useBrokers as jest.Mock).mockImplementation(() => ({
data: brokersPayload,
}));
(useClusterStats as jest.Mock).mockImplementation(() => ({
data: {
...clusterStatsPayload,
diskUsage: [clusterStatsPayload.diskUsage[0]],
},
}));
});
it('renders list of all brokers', async () => {
renderComponent();
expect(screen.getByRole('table')).toBeInTheDocument();
expect(screen.getAllByRole('row').length).toEqual(3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make the .toEqual(3); the number inside to be dynamic based on the mock data ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done

});
});
});
});