segmentio / topicctl

Tool for declarative management of Kafka topics
MIT License
590 stars 55 forks source link

[DP-1774] - topicctl get partitions to display under replicated and offline #155

Closed ssingudasu closed 12 months ago

ssingudasu commented 1 year ago

Description:

topicctl get partitions currently displays the partitions status information as below:

Out-of-sync: This mean either under-replicated or offline partition Wrong Leader: This means partition does not have preferred leader replica Ok: This means partition is in a good state (inSync)

We need to know whether a partition is ok (inSync), under-replicated, offline and also check if the partition has a preferred replica leader.

Current topicctl get partitions problems/gaps:

topicctl get partitions Expectations:

This PR will add following features to topicctl

topicctl:repl> get partitions Expectations:

From terminal, topicctl get partitions can take more than one argument.

From repl, filtering multiple topics can get tricky. Current repl implementation takes only fixed number of words (command.args).

Hence in repl, we will make get partitions work with only one argument (topic) and PartitionStatus as "" implying all status

Partition Status:

Preferred Leader:

Considerations:

Local Set UP Details:


Build


topicctl get partitions --help

# ./build/topicctl get partitions --help

Screenshot 2023-09-20 at 19 57 43

Partitions Information

Created a topic threepartition

Screenshot 2023-09-20 at 20 04 59

topic: threepartition

Screenshot 2023-09-20 at 20 05 19

Get all partitions status

# ./build/topicctl get partitions --broker-addr localhost:19092 # docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions --zk-addr localhost:2181

Screenshot 2023-09-20 at 19 59 36 Screenshot 2023-09-20 at 19 59 55 Screenshot 2023-09-20 at 20 01 56 Screenshot 2023-09-20 at 20 02 15

Get all partitions status summary

# ./build/topicctl get partitions --broker-addr localhost:19092 --summary # docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions --zk-addr localhost:2181 --summary

Screenshot 2023-09-20 at 20 02 57 Screenshot 2023-09-20 at 20 03 22

Kill Broker IDs 1, 2

# docker stop kafka-2; docker stop kafka-3


Getting current all partition status

# ./build/topicctl get partitions --broker-addr localhost:19092 # docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions --zk-addr localhost:2181

Screenshot 2023-09-20 at 20 08 08 Screenshot 2023-09-20 at 20 08 23 Screenshot 2023-09-20 at 20 08 55 Screenshot 2023-09-20 at 20 09 09

Get current all partitions status --summary

# ./build/topicctl get partitions --broker-addr localhost:19092 --summary # docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions --zk-addr localhost:2181 --summary

Screenshot 2023-09-20 at 20 10 52 Screenshot 2023-09-20 at 20 11 08

start broker ID 1

docker start kafka-2


Getting current all partition status

# ./build/topicctl get partitions --broker-addr localhost:19092

Screenshot 2023-09-20 at 20 12 40 Screenshot 2023-09-20 at 20 12 51

repl and get partitions info for topic: __consumer_offsets

# ./build/topicctl repl --broker-addr localhost:19092 # get partitions __consumer_offsets # get partitions __consumer_offsets --summary

NOTE: repl can take only one topic argument and optional flag --summary

Screenshot 2023-09-20 at 20 14 24 Screenshot 2023-09-20 at 20 14 37 Screenshot 2023-09-20 at 20 14 53

start broker ID 2

# docker start kafka-3


Getting current all partition status and filter for test-1, threepartition

# ./build/topicctl get partitions --broker-addr localhost:29092 # ./build/topicctl get partitions test-1 threepartition --broker-addr localhost:29092 --summary # ./build/topicctl get partitions test-1 threepartition --broker-addr localhost:29092 --summary --status under-replicated

Screenshot 2023-09-20 at 20 18 11 Screenshot 2023-09-20 at 20 18 31 Screenshot 2023-09-20 at 20 18 49 Screenshot 2023-09-20 at 20 20 18

Getting stable all partition status

# ./build/topicctl get partitions --broker-addr localhost:29092

Screenshot 2023-09-20 at 20 21 21 Screenshot 2023-09-20 at 20 21 34

running preferred leader for topic: partitionthree fixes the wrong leader

Before preferred leader: # ./build/topicctl get partitions threepartition --broker-addr localhost:29092

Screenshot 2023-09-20 at 20 23 04

After preferred leader: # ./build/topicctl get partitions threepartiton --broker-addr localhost:29092

Screenshot 2023-09-20 at 20 23 54

threepartition summary: # ./build/topicctl get partitions threepartition --broker-addr localhost:29092 --summary

Screenshot 2023-09-20 at 20 24 38

threepartition topic summary filter for status ok: # ./build/topicctl get partitions threepartition --broker-addr localhost:29092 --summary --status ok

Screenshot 2023-09-20 at 20 25 23

fetching partition information for topic that does not displays error message

# ./build/topicctl get partitions topicdoesnotexist --broker-addr localhost:29092

Screenshot 2023-09-20 at 20 27 50
ssingudasu commented 12 months ago

All comments have been resolved. Merging the PR