Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPE-5611] Remove cruise-control metrics reporter if no balancer #250

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ name = "kafka-operator"
version = "1.0"
description = "kafka-operator"
authors = []
package-mode = false

[tool.poetry.dependencies]
python = ">=3.8,<4.0"
Expand All @@ -41,7 +42,7 @@ tenacity = ">=8.0.1"
pure-sasl = ">=0.6.2"
jsonschema = ">=4.10"
cryptography = ">42.0.0"
pydantic ="<2"
pydantic = "<2"
pyyaml = "^6.0.1"
requests = "^2.32.3"
lightkube = "0.15.0"
Expand Down Expand Up @@ -85,7 +86,7 @@ optional = true

[tool.poetry.group.unit.dependencies]
pytest = ">=7.2"
coverage = {extras = ["toml"], version = ">7.0"}
coverage = { extras = ["toml"], version = ">7.0" }
pytest-mock = "^3.11.1"
ops-scenario = "^7.0.0"

Expand All @@ -95,7 +96,7 @@ optional = true
[tool.poetry.group.integration.dependencies]
pytest = ">=7.2"
juju = "3.5.0.0"
coverage = {extras = ["toml"], version = ">7.0"}
coverage = { extras = ["toml"], version = ">7.0" }
pytest-operator = ">0.20"
kazoo = ">=2.8"
tenacity = ">=7.0"
Expand All @@ -105,8 +106,6 @@ requests = ">2.25"

pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v22.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
# To be enabled if we are using groups on integration tests
# pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v7", subdirectory = "python/pytest_plugins/pytest_operator_groups"}


[tool.poetry.group.format.dependencies]
pyright = "^1.1.301"
Expand All @@ -115,23 +114,23 @@ pyright = "^1.1.301"
line-length = 99
lint.select = ["E", "W", "F", "C", "N", "D", "I001"]
lint.extend-ignore = [
"D203",
"D204",
"D213",
"D215",
"D400",
"D401",
"D404",
"D406",
"D407",
"D408",
"D409",
"D413",
"D203",
"D204",
"D213",
"D215",
"D400",
"D401",
"D404",
"D406",
"D407",
"D408",
"D409",
"D413",
]
lint.ignore = ["E501", "D107"]
extend-exclude = ["__pycache__", "*.egg_info", "tests/integration/app-charm/lib"]
lint.per-file-ignores = {"tests/*" = ["D100","D101","D102","D103","D104", "E999"], "src/literals.py" = ["D101"]}
target-version="py310"
lint.per-file-ignores = { "tests/*" = ["D100", "D101", "D102", "D103", "D104", "E999"], "src/literals.py" = ["D101"] }
target-version = "py310"
src = ["src", "tests"]

[tool.ruff.lint.mccabe]
Expand Down
8 changes: 7 additions & 1 deletion src/managers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from core.workload import CharmedKafkaPaths, WorkloadBase
from literals import (
ADMIN_USER,
BALANCER,
BALANCER_GOALS_TESTING,
BROKER,
CONTROLLER_LISTENER_NAME,
Expand All @@ -45,6 +46,8 @@
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-512
allow.everyone.if.no.acl.found=false
auto.create.topics.enable=false
"""
KAFKA_CRUISE_CONTROL_OPTIONS = """
metric.reporters=com.linkedin.kafka.cruisecontrol.metricsreporter.CruiseControlMetricsReporter
"""
TESTING_OPTIONS = """
Expand Down Expand Up @@ -667,7 +670,6 @@ def server_properties(self) -> list[str]:
+ self.config_properties
+ self.default_replication_properties
+ self.rack_properties
+ self.metrics_reporter_properties
+ DEFAULT_CONFIG_OPTIONS.split("\n")
+ self.authorizer_class
+ self.controller_properties
Expand All @@ -678,6 +680,10 @@ def server_properties(self) -> list[str]:
if self.state.kraft_mode == False: # noqa: E712
properties += self.zookeeper_tls_properties

if self.state.runs_balancer or BALANCER.value in self.state.peer_cluster.roles:
properties += KAFKA_CRUISE_CONTROL_OPTIONS.splitlines()
properties += self.metrics_reporter_properties

if self.config.profile == PROFILE_TESTING:
properties += TESTING_OPTIONS.split("\n")

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
JVM_MEM_MIN_GB,
OAUTH_REL_NAME,
PEER,
PEER_CLUSTER_ORCHESTRATOR_RELATION,
SUBSTRATE,
ZK,
)
Expand Down Expand Up @@ -547,3 +548,19 @@ def test_super_users(harness: Harness[KafkaCharm]):
harness.update_relation_data(appii_relation_id, "appii", {"extra-user-roles": "consumer"})

assert len(harness.charm.state.super_users.split(";")) == (len(INTERNAL_USERS) + 1)


def test_cruise_control_reporter_only_with_balancer(harness: Harness[KafkaCharm]):
reporters_config_value = "metric.reporters=com.linkedin.kafka.cruisecontrol.metricsreporter.CruiseControlMetricsReporter"
# Default roles value does not include balancer
assert reporters_config_value not in harness.charm.broker.config_manager.server_properties

with harness.hooks_disabled():
peer_cluster_relation_id = harness.add_relation(
PEER_CLUSTER_ORCHESTRATOR_RELATION, CHARM_KEY
)
harness.update_relation_data(
peer_cluster_relation_id, harness.charm.app.name, {"roles": "broker,balancer"}
)

assert reporters_config_value in harness.charm.broker.config_manager.server_properties
Loading