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

#128 [FE] Brokers, Topic details: Display disk usage. #129

Merged
merged 4 commits into from
Nov 30, 2020
Merged
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
22 changes: 20 additions & 2 deletions kafka-ui-react-app/src/components/Brokers/Brokers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cx from 'classnames';
import MetricsWrapper from 'components/common/Dashboard/MetricsWrapper';
import Indicator from 'components/common/Dashboard/Indicator';
import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb';
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';

interface Props extends ClusterStats {
clusterName: ClusterName;
Expand All @@ -14,7 +15,7 @@ interface Props extends ClusterStats {
fetchBrokers: (clusterName: ClusterName) => void;
}

const Topics: React.FC<Props> = ({
const Brokers: React.FC<Props> = ({
clusterName,
brokerCount,
activeControllers,
Expand All @@ -24,6 +25,7 @@ const Topics: React.FC<Props> = ({
inSyncReplicasCount,
outOfSyncReplicasCount,
underReplicatedPartitionCount,
diskUsage,
fetchClusterStats,
fetchBrokers,
}) => {
Expand Down Expand Up @@ -73,8 +75,24 @@ const Topics: React.FC<Props> = ({
{outOfSyncReplicasCount}
</Indicator>
</MetricsWrapper>

<MetricsWrapper levelClassName="level-multiline" title="Disk Usage">
{diskUsage?.map((brokerDiskUsage) => (
<React.Fragment key={brokerDiskUsage.brokerId}>
<Indicator className="is-one-third" label="Broker">
{brokerDiskUsage.brokerId}
</Indicator>
<Indicator className="is-one-third" label="Segment Size" title="">
<BytesFormatted value={brokerDiskUsage.segmentSize} />
</Indicator>
<Indicator className="is-one-third" label="Segment count">
{brokerDiskUsage.segmentCount}
</Indicator>
</React.Fragment>
))}
</MetricsWrapper>
</div>
);
};

export default Topics;
export default Brokers;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const mapStateToProps = (
underReplicatedPartitionCount: brokerSelectors.getUnderReplicatedPartitionCount(
state
),
diskUsage: brokerSelectors.getDiskUsage(state),
});

const mapDispatchToProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ClusterName, TopicName } from 'redux/interfaces';
import { Topic, TopicDetails } from 'generated-sources';
import MetricsWrapper from 'components/common/Dashboard/MetricsWrapper';
import Indicator from 'components/common/Dashboard/Indicator';
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';

interface Props extends Topic, TopicDetails {
isFetched: boolean;
Expand All @@ -22,6 +23,8 @@ const Overview: React.FC<Props> = ({
partitionCount,
internal,
replicationFactor,
segmentSize,
segmentCount,
fetchTopicDetails,
}) => {
React.useEffect(() => {
Expand Down Expand Up @@ -53,6 +56,10 @@ const Overview: React.FC<Props> = ({
{internal ? 'Internal' : 'External'}
</span>
</Indicator>
<Indicator label="Segment Size" title="">
<BytesFormatted value={segmentSize} />
</Indicator>
<Indicator label="Segment count">{segmentCount}</Indicator>
</MetricsWrapper>
<div className="box">
<table className="table is-striped is-fullwidth">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

interface Props {
value: string | number | undefined;
precision?: number;
}

const BytesFormatted: React.FC<Props> = ({ value, precision }) => {
const formatBytes = React.useCallback(() => {
const numVal = typeof value === 'string' ? parseInt(value, 10) : value;
if (!numVal) return 0;
const pow = Math.floor(Math.log2(numVal) / 10);
const multiplier = 10 ** (precision || 2);
return (
Math.round((numVal * multiplier) / 1024 ** pow) / multiplier +
['Bytes', 'KB', 'MB', 'GB', 'TB'][pow]
);
}, [value]);
return <span>{formatBytes()}</span>;
};

export default BytesFormatted;
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import cx from 'classnames';

interface Props {
label: string;
title?: string;
className?: string;
}

const Indicator: React.FC<Props> = ({ label, title, children }) => {
const Indicator: React.FC<Props> = ({ label, title, className, children }) => {
return (
<div className="level-item level-left">
<div className={cx('level-item', 'level-left', className)}>
<div title={title || label}>
<p className="heading">{label}</p>
<p className="title">{children}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import cx from 'classnames';
interface Props {
title?: string;
wrapperClassName?: string;
levelClassName?: string;
soffest marked this conversation as resolved.
Show resolved Hide resolved
}

const MetricsWrapper: React.FC<Props> = ({
title,
children,
wrapperClassName,
levelClassName,
}) => {
return (
<div className={cx('box', wrapperClassName)}>
{title && <h5 className="subtitle is-6">{title}</h5>}
<div className="level">{children}</div>
<div className={cx('level', levelClassName)}>{children}</div>
</div>
);
};
Expand Down
5 changes: 5 additions & 0 deletions kafka-ui-react-app/src/redux/reducers/brokers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ export const getUnderReplicatedPartitionCount = createSelector(
brokersState,
({ underReplicatedPartitionCount }) => underReplicatedPartitionCount
);

export const getDiskUsage = createSelector(
brokersState,
({ diskUsage }) => diskUsage
);
10 changes: 10 additions & 0 deletions kafka-ui-react-app/src/theme/bulma_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@
from { opacity: 0; }
to { opacity: 1; }
}

.level.level-multiline {
flex-wrap: wrap;
.level-item.is-one-third {
flex-basis: 26%;
}
.level-item.is-one-third:nth-child(n+4) {
margin-top: 10px;
}
}