Skip to content

Commit 1e4aa28

Browse files
committed
BE: Fixes #498 Added sort by number of messages
1 parent b491951 commit 1e4aa28

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

api/src/main/java/io/kafbat/ui/controller/TopicsController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ private Comparator<InternalTopic> getComparatorForTopic(
362362
case OUT_OF_SYNC_REPLICAS -> Comparator.comparing(t -> t.getReplicas() - t.getInSyncReplicas());
363363
case REPLICATION_FACTOR -> Comparator.comparing(InternalTopic::getReplicationFactor);
364364
case SIZE -> Comparator.comparing(InternalTopic::getSegmentSize);
365+
case MESSAGES_NUMBER -> Comparator.comparing(InternalTopic::getMessagesNumber);
365366
default -> defaultComparator;
366367
};
367368
}

api/src/main/java/io/kafbat/ui/model/InternalTopic.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.apache.kafka.clients.admin.ConfigEntry;
1212
import org.apache.kafka.clients.admin.TopicDescription;
1313
import org.apache.kafka.common.TopicPartition;
14+
import org.jetbrains.annotations.NotNull;
1415

1516
@Data
1617
@Builder(toBuilder = true)
@@ -143,4 +144,13 @@ public static InternalTopic from(TopicDescription topicDescription,
143144
return topic.build();
144145
}
145146

147+
public long getMessagesNumber() {
148+
long result = 0;
149+
if (partitions != null && !partitions.isEmpty()) {
150+
for (InternalPartition partition : partitions.values()) {
151+
result += (partition.getOffsetMax() - partition.getOffsetMin());
152+
}
153+
}
154+
return result;
155+
}
146156
}

contract-typespec/api/topics.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ enum TopicColumnsToSort {
156156
TOTAL_PARTITIONS,
157157
REPLICATION_FACTOR,
158158
SIZE,
159+
MESSAGES_NUMBER
159160
}
160161

161162
model Topic {

contract/src/main/resources/swagger/kafbat-ui-api.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,7 @@ components:
26922692
- TOTAL_PARTITIONS
26932693
- REPLICATION_FACTOR
26942694
- SIZE
2695+
- MESSAGES_NUMBER
26952696

26962697
SchemaColumnsToSort:
26972698
type: string

0 commit comments

Comments
 (0)