segmentio / topicctl

Tool for declarative management of Kafka topics
MIT License
580 stars 54 forks source link

Adding action rebalance #137

Closed ssingudasu closed 1 year ago

ssingudasu commented 1 year ago

Introduction: To rebalance a topic in topicctl, We currently use topicctl apply $topic --rebalance / topicctl apply $topic --rebalance --to-remove . In a production scale Kafka cluster, there is a need to rebalance all topics for a cluster.

Goal:

Considerations for action rebalance:

  1. expects --cluster-config (i.e cluster.yaml) and --path-prefix (topics folder)
  2. Uses underlying topicctl pkg/apply to rebalance a topic.

NOTE: A topic is not considered for rebalance if

Test Ouput:

Tested on local kafka cluster (3 brokers, 1 in each rack) with 3 topics test-1 -> exists in kafka. But settings mismatch with test-1 topic yaml config test-2 -> exists in kafka. settings match (replication 2) test-3 -> does not exist in kafka


# go run cmd/topicctl/main.go -h

Screenshot 2023-05-18 at 08 14 59

# go run cmd/topicctl/main.go rebalance -h

Screenshot 2023-05-18 at 08 07 15 Screenshot 2023-05-18 at 08 12 52

# go run cmd/topicctl/main.go rebalance --cluster-config $CLUSTER/cluster.yaml --path-prefix $CLUSTER/topics/ --auto-continue-rebalance --skip-confirm --partition-batch-size 5 --broker-throttle-mb 640

Screenshot 2023-05-18 at 22 43 12

# go run cmd/topicctl/main.go rebalance --cluster-config $CLUSTER/cluster.yaml --path-prefix $CLUSTER/topics/ --auto-continue-rebalance --skip-confirm --partition-batch-size 5 --broker-throttle-mb 640 --to-remove 3

Screenshot 2023-05-18 at 22 45 47 Screenshot 2023-05-18 at 22 46 13 Screenshot 2023-05-18 at 22 46 34 Screenshot 2023-05-18 at 22 47 38 Screenshot 2023-05-18 at 22 48 21 Screenshot 2023-05-18 at 22 48 48 Screenshot 2023-05-18 at 22 49 20
petedannemann commented 1 year ago

Please update the PR description to remove the examples where topics were being creating and add an example of what it looks when topics are rebalanced. A lot of logging was added and I wonder if things are too verbose now

ssingudasu commented 1 year ago

Please update the PR description to remove the examples where topics were being creating and add an example of what it looks when topics are rebalanced. A lot of logging was added and I wonder if things are too verbose now

PR description has been updated with detailed output screenshots along with test cluster and topic information

petedannemann commented 1 year ago

What do you think about doing checks for all the topics first, outputting a list of ones that will be skipped and why, prompting the user for (y/n) to continue based on that "plan", and then rebalancing the topics that have passed the checks? This way it's more obvious which topics actually failed to rebalance vs. which ones didn't attempt to rebalance at all

EDIT: I guess things can change between the plan and rebalance phase. Maybe this isn't a good idea

ssingudasu commented 1 year ago

Duplicate of https://github.com/segmentio/topicctl/pull/142

closing this