import React from 'react'; import { ClusterName } from 'redux/interfaces'; import { useNavigate } from 'react-router-dom'; import PageHeading from 'components/common/PageHeading/PageHeading'; import * as Metrics from 'components/common/Metrics'; import useAppParams from 'lib/hooks/useAppParams'; import { useBrokers } from 'lib/hooks/api/brokers'; import { useClusterStats } from 'lib/hooks/api/clusters'; import Table, { LinkCell, SizeCell } from 'components/common/NewTable'; import CheckMarkRoundIcon from 'components/common/Icons/CheckMarkRoundIcon'; 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 SkewHeader from './SkewHeader/SkewHeader'; import * as S from './BrokersList.styled'; const NA = 'N/A'; const BrokersList: React.FC = () => { const navigate = useNavigate(); const { clusterName } = useAppParams<{ clusterName: ClusterName }>(); const { data: clusterStats = {} } = useClusterStats(clusterName); const { data: brokers } = useBrokers(clusterName); const { brokerCount, activeControllers, onlinePartitionCount, offlinePartitionCount, inSyncReplicasCount, outOfSyncReplicasCount, underReplicatedPartitionCount, diskUsage, version, } = clusterStats; const rows = React.useMemo(() => { let brokersResource; if (!diskUsage || !diskUsage?.length) { brokersResource = brokers?.map((broker) => { return { brokerId: broker.id, segmentSize: NA, segmentCount: NA, }; }) || []; } 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, }; }); }, [diskUsage, brokers]); const columns = React.useMemo[]>( () => [ { header: 'Broker ID', accessorKey: 'brokerId', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ row: { id }, getValue }) => ( ()}`} to={encodeURIComponent(`${getValue()}`)} /> {id === String(activeControllers) && ( } content="Active Controller" placement="right" /> )} ), }, { header: 'Disk usage', accessorKey: 'size', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue, table, cell, column, renderValue, row }) => getValue() === NA ? ( NA ) : ( ), }, { // eslint-disable-next-line react/no-unstable-nested-components header: () => , accessorKey: 'partitionsSkew', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue }) => { const value = getValue(); return ( = 10 && value < 20} attention={value >= 20} /> ); }, }, { header: 'Leaders', accessorKey: 'partitionsLeader' }, { header: 'Leader skew', accessorKey: 'leadersSkew', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue }) => { const value = getValue(); return ( = 10 && value < 20} attention={value >= 20} /> ); }, }, { header: 'Online partitions', accessorKey: 'inSyncPartitions', // eslint-disable-next-line react/no-unstable-nested-components cell: ({ getValue, row }) => { const value = getValue(); return ( ); }, }, { header: 'Port', accessorKey: 'port' }, { header: 'Host', accessorKey: 'host', }, ], [] ); const replicas = (inSyncReplicasCount ?? 0) + (outOfSyncReplicasCount ?? 0); const areAllInSync = inSyncReplicasCount && replicas === inSyncReplicasCount; const partitionIsOffline = offlinePartitionCount && offlinePartitionCount > 0; const isActiveControllerUnKnown = typeof activeControllers === 'undefined'; return ( <> {brokerCount} {isActiveControllerUnKnown ? ( No Active Controller ) : ( activeControllers )} {version} {partitionIsOffline ? ( {onlinePartitionCount} ) : ( onlinePartitionCount )} {` of ${ (onlinePartitionCount || 0) + (offlinePartitionCount || 0) } `} {!underReplicatedPartitionCount ? ( {underReplicatedPartitionCount} ) : ( {underReplicatedPartitionCount} )} {areAllInSync ? ( replicas ) : ( {inSyncReplicasCount} )} of {replicas} {outOfSyncReplicasCount} navigate(clusterBrokerPath(clusterName, brokerId)) } emptyMessage="No clusters are online" /> ); }; export default BrokersList;