segmentio / topicctl

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

[DP-1767] - topicctl get action partitions-status #152

Closed ssingudasu closed 1 year ago

ssingudasu commented 1 year ago

Description

This PR is to add new action: partitions-status for topicctl get

Expectations:

partitions-status - Under replicated partitions:

Kafka cluster is in under replicated state if the number of ISR are less than the Replicas available for the partition

partitions-status - Offline partitions:

Kafka cluster is in offline state if partition leader broker ID is not found. (i.e) kafka-go metadata call with partitions having ListenerNotFound Error observed for leader partition

Gotcha: what if offline partition has valid ISRs? Not sure how to replicate this! No matter what, Partition is offline is there is no Leader broker ID

partitions-status - Preferred Leader partitions:

if the leader partition broker id is equal to first available Replicas broker id

partitions-status - Not Preferred Leader partitions:

if the leader partition broker id is not equal to first available Replicas broker id

NOTE:


Local Set UP Details:


Build


(Used later) Copy the amd64 build to zookeeper docker

Run help

#./build/topicctl get partitions-status --help

Screenshot 2023-09-18 at 21 25 23

Get all partitions-status via kafka broker url

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

Screenshot 2023-09-18 at 21 27 07 Screenshot 2023-09-18 at 21 27 41

Get all partitions-status via kafka broker url --full

NOTE: --full flag is not applicable to partitions-status

Screenshot 2023-09-18 at 21 28 57 Screenshot 2023-09-18 at 21 29 18

Run the same command with --zk-addr

NOTE: since this is local set up, we will build an run this inside the zookeeper. Because zookeeper stores the kafka Broker name information and network can get tricky with Docker from local machine # docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions-status --zk-addr localhost:2181

Screenshot 2023-09-18 at 21 37 01 Screenshot 2023-09-18 at 21 37 23

Partitions Information (created a topic threepartition)

Screenshot 2023-09-18 at 21 52 17

topic: threepartition information

If you observe, partitions 0,1 replicas are in brokers 1, 2

Screenshot 2023-09-18 at 21 52 34

Get all partitions-status via --zk-addr

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

Screenshot 2023-09-18 at 21 54 27 Screenshot 2023-09-18 at 21 54 44

Get preferred-leader partitions only

# docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions-status --zk-addr localhost:2181 --status preferred-leader

Screenshot 2023-09-18 at 21 55 49

Get preferred-leader partitions --full mode

# ./build/topicctl get partitions-status --broker-addr localhost:39092 --status preferred-leader --full

Screenshot 2023-09-18 at 21 56 30 Screenshot 2023-09-18 at 21 56 44

Get preferred-leader partitions --topics test-1,threepartition

# ./build/topicctl get partitions-status --broker-addr localhost:39092 --status preferred-leader --full --topics test-1,threepartition # ./build/topicctl get partitions-status --broker-addr localhost:39092 --status preferred-leader --topics test-1,threepartition

Screenshot 2023-09-18 at 21 59 00

Get Under replicated partitions

# docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions-status --zk-addr localhost:2181 --status under-replicated # docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions-status --zk-addr localhost:2181 --status under-replicated --full

Screenshot 2023-09-18 at 22 00 26

Kill Broker IDs 1, 2

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


Getting all partition status (via --zk-addr)

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

Screenshot 2023-09-18 at 22 05 08 Screenshot 2023-09-18 at 22 05 23

Get all under-replicated partitions (via broker-addr)

# ./build/topicctl get partitions-status --broker-addr localhost:19092 --status preferred-leader # ./build/topicctl get partitions-status --broker-addr localhost:19092 --status preferred-leader --full

Screenshot 2023-09-18 at 22 07 15 Screenshot 2023-09-18 at 22 07 32

Get all offline partitions (via --zk-addr)

# docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions-status --zk-addr localhost:2181 --status offline # docker exec -u root -it zookeeper /tmp/topicctl-linux-amd64 get partitions-status --zk-addr localhost:2181 --status offline --full

Screenshot 2023-09-18 at 22 08 29

Get all preferred leader (via kafka broker-addr) filter for topics __consumer_offsets

# ./build/topicctl get partitions-status --broker-addr localhost:19092 --status preferred-leader --topics __consumer_offsets # ./build/topicctl get partitions-status --broker-addr localhost:19092 --status preferred-leader --topics __consumer_offsets --full

Screenshot 2023-09-18 at 22 10 18 Screenshot 2023-09-18 at 22 10 33

Start Broker IDs 1, 2

# docker start kafka-2; docker start kafka-3


Get all partition Status

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

Screenshot 2023-09-18 at 22 13 18 Screenshot 2023-09-18 at 22 13 48

Get Not Preferred Leader partitions

# ./build/topicctl get partitions-status --broker-addr localhost:29092 --status not-preferred-leader # ./build/topicctl get partitions-status --broker-addr localhost:29092 --status not-preferred-leader --full

Screenshot 2023-09-18 at 22 14 50 Screenshot 2023-09-18 at 22 15 03
ssingudasu commented 1 year ago

Closing this PR as we have decided to implement the same in

# topicctl get partitions