type ctrl+c in each terminal (stop kafka before stop zookeeper)
check kafka broker and zookeeper process with jps command
jps
clear old data in previous lab
rm-rf/tmp/zookeep*rm-rf/tmp/kaf*
Deploying the Cruise Control Metrics Reporter
In the Kafka configuration file server-0.properties configure the Cruise Control Metrics Reporter:
Add the CruiseControlMetricsReporter class to the metric.reporters configuration option. Do not remove any existing Metrics Reporters. (add at bottom of properties file)
repeat with server-1.properties, server-2.properties in ~/amq-streams-2022/2-amq-streams-architecture/configs/kafka
start cluster
run start zookeeper command in different terminal (1 shell script 1 terminal)
run start kafka broker command in different terminal, start only broker 0 and broker 1 (we will start broker 2 later in this lab)
check zookeeper & kafka process (3 zookeeper & 2 kafka)
or
Prepare Test Topic
Create topic "demo"
example result
Note: replication factor can't larger than available broker.
Check Topic Description
example result, show partition of demo topic in broker 0 & broker 1
load data to topic "demo"
run start kafka broker 2 in different terminal
check all zookeeper & kafka process (3 zookeeper & 3 kafka)
recheck topic information of "demo" don't change after start broker 2
Enable Cruise Control
reviews cruise-control configuration in cruisecontrol.properties, Configure the properties used by Cruise Control and then start the Cruise Control server using the kafka-cruise-control-start.sh script.
start cruise-contral at port 9191
check Auto-created topics of cruise-control
example result, show new topic such as "__CruiseControlMetrics", "__KafkaCruiseControlPartitionMetricSamples" and "__KafkaCruiseControlModelTrainingSamples"
open new terminal, check cruise-control state
example result
review capacity limits for Kafka broker resources in config/config/capacityJBOD.json , To apply the same capacity limits to every broker monitored by Cruise Control, set capacity limits for broker ID -1. To set different capacity limits for individual brokers, specify each broker ID and its capacity configuration.
Test Auto Rebalance After Add Broker With Cruise-control
Test Generating optimization proposals with dryrun.
example result, Review the optimization proposal contained in the response.
if your found error 500 after call proposals such as
please wait and re try again because Cruise Control has not collect enough metric data to aggregate to a valid window. (around 2-3 minutes)
Approving an optimization proposal
Check progress
example result
call check until status change to Completed
Check Topic after call cruise-control/add_broker, some partition move to new broker
example result, show partition of demo topic in broker 0,broker 1 and broker 2
cd ~/amq-streams-2022/2-amq-streams-architecture/
./kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic demo
...
# The Kafka cluster to control.
bootstrap.servers=localhost:9092
# The replication factor of Kafka metric sample store topic
sample.store.topic.replication.factor=2
# The configuration for the BrokerCapacityConfigFileResolver (supports JBOD, non-JBOD, and heterogeneous CPU core capacities)
#capacity.config.file=config/capacity.json
#capacity.config.file=config/capacityCores.json
capacity.config.file=config/capacityJBOD.json
# The list of goals to optimize the Kafka cluster for with pre-computed proposals
default.goals=com.linkedin.kafka.cruisecontrol.analyzer.goals.ReplicaCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.DiskCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkInboundCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkOutboundCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.CpuCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.ReplicaDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.PotentialNwOutGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.DiskUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkInboundUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkOutboundUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.CpuUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.TopicReplicaDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.LeaderReplicaDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.LeaderBytesInDistributionGoal
# The list of supported goals
goals=com.linkedin.kafka.cruisecontrol.analyzer.goals.RackAwareGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.RackAwareDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.ReplicaCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.DiskCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkInboundCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkOutboundCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.CpuCapacityGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.ReplicaDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.PotentialNwOutGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.DiskUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkInboundUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkOutboundUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.CpuUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.TopicReplicaDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.LeaderReplicaDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.LeaderBytesInDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.kafkaassigner.KafkaAssignerDiskUsageDistributionGoal,com.linkedin.kafka.cruisecontrol.analyzer.kafkaassigner.KafkaAssignerEvenRackAwareGoal,com.linkedin.kafka.cruisecontrol.analyzer.goals.PreferredLeaderElectionGoal
# How often should the cached proposal be expired and recalculated if necessary
proposal.expiration.ms=60000
# The zookeeper connect of the Kafka cluster
zookeeper.connect=localhost:2181
cd ~/amq-streams-2022/4-management/cruise-control
./kafka-cruise-control-start.sh config/cruisecontrol.properties 9191
cd ~/amq-streams-2022/2-amq-streams-architecture/
./kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list --exclude-internal
{
"brokerCapacities":[
{
"brokerId": "-1",
"capacity": {
"DISK": "100000",
"CPU": "100",
"NW_IN": "10000",
"NW_OUT": "10000"
},
"doc": "This is the default capacity. Capacity unit used for disk is in MB, cpu is in percentage, network throughput is in KB."
},
{
"brokerId": "0",
"capacity": {
"DISK": "100000",
"CPU": "100",
"NW_IN": "10000",
"NW_OUT": "10000"
},
"doc": "This overrides the capacity for broker 0."
}
]
}
curl -v -X POST 'localhost:9191/kafkacruisecontrol/add_broker?brokerid=2'
Error processing POST request '/add_broker' due to: 'com.linkedin.kafka.cruisecontrol.exception.KafkaCruiseControlException: com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException: There are only 0 valid windows when aggregating in range [-1, 1670319259389] for aggregation options (minValidEntityRatio=0.95, minValidEntityGroupRatio=0.00, minValidWindows=1, numEntitiesToInclude=75, granularity=ENTITY)'
curl -v -X POST 'localhost:9191/kafkacruisecontrol/add_broker?dryrun=false&brokerid=2'
USER TASK ID CLIENT ADDRESS START TIME STATUS REQUEST URL
081d2454-5c1c-4c9f-be3c-90d282fdf0fe [0:0:0:0:0:0:0:1] 2022-11-24T06:20:30Z InExecution POST /kafkacruisecontrol/add_broker?brokerid=2&dryrun=false
7bb50955-f9e5-45e6-bb6b-6177d2b3dc8e [0:0:0:0:0:0:0:1] 2022-11-24T06:13:33Z Completed GET /kafkacruisecontrol/state
5c0d11d0-0b98-431b-965d-f030e3263835 [0:0:0:0:0:0:0:1] 2022-11-24T06:13:38Z Completed GET /kafkacruisecontrol/state
USER TASK ID CLIENT ADDRESS START TIME STATUS REQUEST URL
7bb50955-f9e5-45e6-bb6b-6177d2b3dc8e [0:0:0:0:0:0:0:1] 2022-11-24T06:13:33Z Completed GET /kafkacruisecontrol/state
...
081d2454-5c1c-4c9f-be3c-90d282fdf0fe [0:0:0:0:0:0:0:1] 2022-11-24T06:20:30Z Completed POST /kafkacruisecontrol/add_broker?brokerid=2&dryrun=false
cd ~/amq-streams-2022/4-management
./kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic demo