Skip to content

Commit

Permalink
fix(ui): topic - consumer group lag is not displayed (#378)
Browse files Browse the repository at this point in the history
close #368
  • Loading branch information
polarising-java committed Aug 28, 2020
1 parent 07a3fb9 commit 20eb5fd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
Expand Up @@ -109,7 +109,7 @@ class ConsumerGroupList extends Component {
const noPropagation = e => e.stopPropagation();
return Object.keys(groupedTopicOffset).map(topicId => {
const topicOffsets = groupedTopicOffset[topicId];
const offsetLag = calculateTopicOffsetLag(topicOffsets);
const offsetLag = calculateTopicOffsetLag(topicOffsets, topicId);

return (
<a
Expand Down
Expand Up @@ -50,7 +50,7 @@ class TopicGroups extends Component {
if (!topics) return {};
return topics.reduce(function(a, e) {
let key = e.topic;
a[key] ? (a[key] = a[key] + e.offsetLag) : (a[key] = e.offsetLag);
a[key] ? (a[key] = a[key] + e.offsetLag) : (a[key] = e.offsetLag || 0);
return a;
}, {});
}
Expand Down
9 changes: 3 additions & 6 deletions client/src/containers/Topic/TopicList/TopicList.jsx
Expand Up @@ -141,11 +141,10 @@ class TopicList extends Component {
if (consumerGroups) {
return consumerGroups.map(consumerGroup => {
let className = 'btn btn-sm mb-1 mr-1 btn-';
let offsetLag = calculateTopicOffsetLag(consumerGroup.offsets);
let offsetLag = calculateTopicOffsetLag(consumerGroup.offsets, topicId);

if (consumerGroup.activeTopics) {
const activeTopic = consumerGroup.activeTopics.find(
activeTopic => activeTopic === topicId
const activeTopic = consumerGroup.activeTopics && consumerGroup.activeTopics.find(
activeTopic => activeTopic === topicId
);
activeTopic ? (className += 'success') : (className += 'warning');

Expand All @@ -161,8 +160,6 @@ class TopicList extends Component {
{consumerGroup.id} <div className="badge badge-secondary"> Lag: {offsetLag}</div>
</a>
);
}
return null;
});
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/utils/converters.js
Expand Up @@ -2,12 +2,12 @@ import _ from 'lodash';
import moment from 'moment';
import { ROLE_TYPE } from './constants';

export function calculateTopicOffsetLag(topicOffsets) {
export function calculateTopicOffsetLag(topicOffsets, topicId) {
let offsetLag = 0;
let offset = 0;
let lastOffset = 0;

topicOffsets.forEach(topicOffset => {
topicOffsets.filter(topicOffset => topicOffset.topic === topicId).forEach(topicOffset => {
offset = topicOffset.offset || 0;
lastOffset = topicOffset.lastOffset || 0;
offsetLag += lastOffset - offset;
Expand Down

0 comments on commit 20eb5fd

Please sign in to comment.