Skip to content

Commit

Permalink
fix(banzai/KafkaCluster): Update health.lua (#15962)
Browse files Browse the repository at this point in the history
fix(banzai/KafkaCluster): Update health.lua (#15962)

Uses ipairs() to correctly iterates over indexed elements

Signed-off-by: Jordan Moore <[email protected]>
  • Loading branch information
OneCricketeer authored Oct 25, 2023
1 parent f37d24f commit f1d3d66
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
local health_status = {}
if obj.status ~= nil then
if obj.status.brokersState ~= nil then
local counter = 0
local brokerReady = 0
for i, broker in pairs(obj.status.brokersState) do
if (brokerReady <= tonumber(i)) then
brokerReady = tonumber(i)+1
else
brokerReady = brokerReady
end
if broker.configurationState == "ConfigInSync" and broker.gracefulActionState.cruiseControlState == "GracefulUpscaleSucceeded" then
counter = counter + 1
end
if broker.configurationState == "ConfigInSync" and broker.gracefulActionState.cruiseControlState == "GracefulDownscaleSucceeded" then
counter = counter + 1
local numberBrokers = 0
local healthyBrokers = 0
for _, broker in pairs(obj.status.brokersState) do
numberBrokers = numberBrokers + 1
if broker.configurationState == "ConfigInSync" then
if broker.gracefulActionState.cruiseControlState == "GracefulUpscaleSucceeded" or broker.gracefulActionState.cruiseControlState == "GracefulDownscaleSucceeded" then
healthyBrokers = healthyBrokers + 1
end
end
end
if counter == brokerReady then
if numberBrokers == healthyBrokers then
if obj.status.cruiseControlTopicStatus == "CruiseControlTopicReady" and obj.status.state == "ClusterRunning" then
health_status.message = "Kafka Brokers, CruiseControl and cluster are in Healthy State."
health_status.status = "Healthy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ tests:
- healthStatus:
status: Healthy
message: "Kafka Brokers, CruiseControl and cluster are in Healthy State."
inputPath: testdata/healthy.yaml
inputPath: testdata/healthy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ spec: {}
status:
alertCount: 0
brokersState:
"0":
"101":
configurationState: ConfigInSync
gracefulActionState:
cruiseControlState: GracefulUpscaleSucceeded
errorMessage: CruiseControl not yet ready
rackAwarenessState: |
broker.rack=us-east-1,us-east-1c
"1":
"102":
configurationState: ConfigInSync
gracefulActionState:
cruiseControlState: GracefulUpscaleSucceeded
errorMessage: CruiseControl not yet ready
rackAwarenessState: |
broker.rack=us-east-1,us-east-1b
"2":
"103":
configurationState: ConfigInSync
gracefulActionState:
cruiseControlState: GracefulUpscaleSucceeded
Expand Down

0 comments on commit f1d3d66

Please sign in to comment.