Skip to content

Commit 3852d86

Browse files
authored
[DPE-5611] Remove cruise-control metrics reporter if no balancer (#140)
1 parent e4ac263 commit 3852d86

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ name = "kafka-k8s-operator"
2727
version = "1.0"
2828
description = "kafka-k8s-operator"
2929
authors = []
30+
package-mode = false
3031

3132
[tool.poetry.dependencies]
3233
python = "^3.10"

src/managers/config.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from core.workload import CharmedKafkaPaths, WorkloadBase
2222
from literals import (
2323
ADMIN_USER,
24+
BALANCER,
2425
BALANCER_GOALS_TESTING,
2526
BROKER,
2627
DEFAULT_BALANCER_GOALS,
@@ -43,6 +44,8 @@
4344
authorizer.class.name=kafka.security.authorizer.AclAuthorizer
4445
allow.everyone.if.no.acl.found=false
4546
auto.create.topics.enable=false
47+
"""
48+
KAFKA_CRUISE_CONTROL_OPTIONS = """
4649
metric.reporters=com.linkedin.kafka.cruisecontrol.metricsreporter.CruiseControlMetricsReporter
4750
"""
4851
TESTING_OPTIONS = """
@@ -596,13 +599,16 @@ def server_properties(self) -> list[str]:
596599
+ self.default_replication_properties
597600
+ self.auth_properties
598601
+ self.rack_properties
599-
+ self.metrics_reporter_properties
600602
+ DEFAULT_CONFIG_OPTIONS.split("\n")
601603
)
602604

603605
if self.state.cluster.tls_enabled and self.state.unit_broker.certificate:
604606
properties += self.tls_properties + self.zookeeper_tls_properties
605607

608+
if self.state.runs_balancer or BALANCER.value in self.state.peer_cluster.roles:
609+
properties += KAFKA_CRUISE_CONTROL_OPTIONS.splitlines()
610+
properties += self.metrics_reporter_properties
611+
606612
if self.config.profile == PROFILE_TESTING:
607613
properties += TESTING_OPTIONS.split("\n")
608614

tests/integration/test_balancer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ async def test_tls(self, ops_test: OpsTest):
326326

327327
await ops_test.model.wait_for_idle(
328328
apps=list({APP_NAME, ZK_NAME, self.balancer_app}),
329-
status="active",
330329
idle_period=30,
331330
timeout=1800,
331+
raise_on_error=False,
332332
)
333333
async with ops_test.fast_forward(fast_interval="30s"):
334334
await asyncio.sleep(120) # ensure update-status adds broker-capacities if missed

tests/unit/test_config.py

+17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
JVM_MEM_MIN_GB,
2626
OAUTH_REL_NAME,
2727
PEER,
28+
PEER_CLUSTER_ORCHESTRATOR_RELATION,
2829
REL_NAME,
2930
SUBSTRATE,
3031
ZK,
@@ -575,3 +576,19 @@ def test_super_users(harness: Harness[KafkaCharm]):
575576
harness.update_relation_data(appii_relation_id, "appii", {"extra-user-roles": "consumer"})
576577

577578
assert len(harness.charm.state.super_users.split(";")) == (len(INTERNAL_USERS) + 1)
579+
580+
581+
def test_cruise_control_reporter_only_with_balancer(harness: Harness[KafkaCharm]):
582+
reporters_config_value = "metric.reporters=com.linkedin.kafka.cruisecontrol.metricsreporter.CruiseControlMetricsReporter"
583+
# Default roles value does not include balancer
584+
assert reporters_config_value not in harness.charm.broker.config_manager.server_properties
585+
586+
with harness.hooks_disabled():
587+
peer_cluster_relation_id = harness.add_relation(
588+
PEER_CLUSTER_ORCHESTRATOR_RELATION, CHARM_KEY
589+
)
590+
harness.update_relation_data(
591+
peer_cluster_relation_id, harness.charm.app.name, {"roles": "broker,balancer"}
592+
)
593+
594+
assert reporters_config_value in harness.charm.broker.config_manager.server_properties

0 commit comments

Comments
 (0)