From 1a24325a18f5e064c45bde96932e149ec8a02948 Mon Sep 17 00:00:00 2001 From: Judit Novak Date: Sun, 3 Dec 2023 16:09:45 +0100 Subject: [PATCH] Prometheus plugin is NOT removed if the relation is gone --- lib/charms/opensearch/v0/opensearch_cos.py | 12 ++--- .../opensearch/v0/opensearch_plugins.py | 13 ----- tests/integration/plugins/test_plugins.py | 48 ++----------------- 3 files changed, 6 insertions(+), 67 deletions(-) diff --git a/lib/charms/opensearch/v0/opensearch_cos.py b/lib/charms/opensearch/v0/opensearch_cos.py index fc0b37e8e..225af9fbb 100644 --- a/lib/charms/opensearch/v0/opensearch_cos.py +++ b/lib/charms/opensearch/v0/opensearch_cos.py @@ -7,7 +7,7 @@ from charms.grafana_agent.v0.cos_agent import COSAgentProvider from charms.opensearch.v0.opensearch_exceptions import OpenSearchError from charms.opensearch.v0.opensearch_plugins import OpenSearchPluginError -from ops import EventBase, RelationBrokenEvent, RelationCreatedEvent +from ops import EventBase, RelationCreatedEvent from ops.model import ActiveStatus, BlockedStatus, WaitingStatus logger = logging.getLogger(__name__) @@ -31,8 +31,6 @@ def __init__(self, charm, *args, **kwargs): def _run_plugin_manager(self, event: EventBase): """Execute plugin manager and handle prossible errors.""" - if not self._charm.unit.is_leader(): - return try: if self._charm.plugin_manager.run(): self._charm.on[self._charm.service_manager.name].acquire_lock.emit( @@ -52,11 +50,7 @@ def _run_plugin_manager(self, event: EventBase): def _on_cos_agent_relation_created(self, event: RelationCreatedEvent): """COS workflow initialization happens when the COS relation is created.""" - self._run_plugin_manager(event) - - def _on_cos_agent_relation_broken(self, event: RelationBrokenEvent): - """Re-run plugin configuration is the cos relation is not present anymore.""" - if self._charm.model.get_relation("cos-agent"): - event.defer() + if not self._charm.unit.is_leader(): return + self._run_plugin_manager(event) diff --git a/lib/charms/opensearch/v0/opensearch_plugins.py b/lib/charms/opensearch/v0/opensearch_plugins.py index 19144240e..16567dcbb 100644 --- a/lib/charms/opensearch/v0/opensearch_plugins.py +++ b/lib/charms/opensearch/v0/opensearch_plugins.py @@ -361,8 +361,6 @@ def name(self) -> str: class OpenSearchPrometheusExporter(OpenSearchPlugin): """Implements the opensearch-knn plugin.""" - REMOVE_ON_DISABLE = True - @property def name(self) -> str: """Returns the name of the plugin.""" @@ -378,14 +376,3 @@ def config(self) -> OpenSearchPluginConfig: "prometheus.nodes.filter": "_all", } ) - - def disable(self) -> OpenSearchPluginConfig: - """No config changes apply on disable.""" - return OpenSearchPluginConfig( - config_entries_to_del={ - "prometheus.metric_name.prefix": "opensearch_", - "prometheus.indices": False, - "prometheus.cluster.settings": False, - "prometheus.nodes.filter": "_all", - } - ) diff --git a/tests/integration/plugins/test_plugins.py b/tests/integration/plugins/test_plugins.py index 6ad578477..3db448a74 100644 --- a/tests/integration/plugins/test_plugins.py +++ b/tests/integration/plugins/test_plugins.py @@ -65,35 +65,14 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None: await ops_test.model.wait_for_idle( apps=[TLS_CERTIFICATES_APP_NAME, APP_NAME], status="active", - timeout=1400, + timeout=3400, idle_period=IDLE_PERIOD, ) assert len(ops_test.model.applications[APP_NAME].units) == 3 -async def test_prometheus_exporter_disabled_by_default(ops_test): - # Test that Prometheus Exporter is NOT running before the relation is there - leader_unit_ip = await get_leader_unit_ip(ops_test, app=APP_NAME) - endpoint = f"https://{leader_unit_ip}:9200/_prometheus/metrics" - response = await http_request(ops_test, "get", endpoint, app=APP_NAME) - assert response == { - "error": "no handler found for uri [/_prometheus/metrics] and method [GET]" - } - - -async def test_prometheus_exporter_enabled_by_cos_relation(ops_test): - await ops_test.model.deploy(COS_APP_NAME, channel="edge"), - await ops_test.model.relate(APP_NAME, COS_APP_NAME) - # NOTE: As for now, COS agent remains blocked, as we only have a partial config - await ops_test.model.wait_for_idle( - apps=[APP_NAME], - status="active", - timeout=1400, - idle_period=IDLE_PERIOD, - ) - config = await ops_test.model.applications[APP_NAME].get_config() - assert config["prometheus_exporter_plugin_url"]["default"].startswith("https://") - +async def test_prometheus_exporter_enabled_by_default(ops_test): + """Test that Prometheus Exporter is running before the relation is there.""" leader_unit_ip = await get_leader_unit_ip(ops_test, app=APP_NAME) endpoint = f"https://{leader_unit_ip}:9200/_prometheus/metrics" response = await http_request(ops_test, "get", endpoint, app=APP_NAME, json_resp=False) @@ -103,27 +82,6 @@ async def test_prometheus_exporter_enabled_by_cos_relation(ops_test): assert len(response_str.split("\n")) > 500 -async def test_prometheus_exporter_disabled_by_cos_relation_gone(ops_test): - await ops_test.juju("remove-relation", APP_NAME, COS_APP_NAME) - - # Wait 90s as the update-status is supposed to happen every 1m - # If model config is updated, update this routine as well. - await asyncio.sleep(150) - await ops_test.model.wait_for_idle( - apps=[APP_NAME], - status="active", - timeout=1400, - idle_period=IDLE_PERIOD, - ) - - leader_unit_ip = await get_leader_unit_ip(ops_test, app=APP_NAME) - endpoint = f"https://{leader_unit_ip}:9200/_prometheus/metrics" - response = await http_request(ops_test, "get", endpoint, app=APP_NAME) - assert response == { - "error": "no handler found for uri [/_prometheus/metrics] and method [GET]" - } - - async def test_knn_endabled_disabled(ops_test): config = await ops_test.model.applications[APP_NAME].get_config() assert config["plugin_opensearch_knn"]["default"] is False