From 16ee479f87a5a0ca2e26da25760cff05e314dcc5 Mon Sep 17 00:00:00 2001 From: Judit Novak Date: Mon, 4 Dec 2023 20:04:37 +0100 Subject: [PATCH] OpensearchCOS module not needed, using COSAgent directly --- lib/charms/opensearch/v0/constants_charm.py | 1 - .../opensearch/v0/opensearch_base_charm.py | 9 +-- lib/charms/opensearch/v0/opensearch_cos.py | 56 ------------------- .../v0/opensearch_plugin_manager.py | 6 -- .../opensearch/v0/opensearch_plugins.py | 20 ------- tests/integration/plugins/test_plugins.py | 2 +- 6 files changed, 3 insertions(+), 91 deletions(-) delete mode 100644 lib/charms/opensearch/v0/opensearch_cos.py diff --git a/lib/charms/opensearch/v0/constants_charm.py b/lib/charms/opensearch/v0/constants_charm.py index edac4bedf..519311872 100644 --- a/lib/charms/opensearch/v0/constants_charm.py +++ b/lib/charms/opensearch/v0/constants_charm.py @@ -76,7 +76,6 @@ ClientRelationName = "opensearch-client" PeerRelationName = "opensearch-peers" PeerClusterRelationName = "peer-cluster" -COSRelationName = "cos-agent" COSPort = "9200" diff --git a/lib/charms/opensearch/v0/opensearch_base_charm.py b/lib/charms/opensearch/v0/opensearch_base_charm.py index 69db97d4b..1436b5f92 100644 --- a/lib/charms/opensearch/v0/opensearch_base_charm.py +++ b/lib/charms/opensearch/v0/opensearch_base_charm.py @@ -8,6 +8,7 @@ from datetime import datetime from typing import Dict, List, Optional, Type +from charms.grafana_agent.v0.cos_agent import COSAgentProvider from charms.opensearch.v0.constants_charm import ( AdminUserInitProgress, CertsExpirationError, @@ -15,7 +16,6 @@ ClusterHealthRed, ClusterHealthUnknown, COSPort, - COSRelationName, PeerRelationName, PluginConfigChangeError, RequestUnitServiceOps, @@ -45,7 +45,6 @@ generate_password, ) from charms.opensearch.v0.opensearch_config import OpenSearchConfig -from charms.opensearch.v0.opensearch_cos import OpenSearchCOSProvider from charms.opensearch.v0.opensearch_distro import OpenSearchDistribution from charms.opensearch.v0.opensearch_exceptions import ( OpenSearchError, @@ -137,7 +136,7 @@ def __init__(self, *args, distro: Type[OpenSearchDistribution] = None): self.status = Status(self) self.health = OpenSearchHealth(self) self.ops_lock = OpenSearchOpsLock(self) - self.cos_integration = OpenSearchCOSProvider( + self.cos_integration = COSAgentProvider( self, metrics_endpoints=[ {"path": "/_prometheus/metrics", "port": COSPort}, @@ -175,10 +174,6 @@ def __init__(self, *args, distro: Type[OpenSearchDistribution] = None): self.framework.observe( self.on[STORAGE_NAME].storage_detaching, self._on_opensearch_data_storage_detaching ) - self.framework.observe( - self.on[COSRelationName].relation_created, - self.cos_integration._on_cos_agent_relation_created, - ) self.framework.observe(self.on.set_password_action, self._on_set_password_action) self.framework.observe(self.on.get_password_action, self._on_get_password_action) diff --git a/lib/charms/opensearch/v0/opensearch_cos.py b/lib/charms/opensearch/v0/opensearch_cos.py deleted file mode 100644 index 225af9fbb..000000000 --- a/lib/charms/opensearch/v0/opensearch_cos.py +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright 2023 Canonical Ltd. -# See LICENSE file for licensing details. -"""COS integration.""" - -import logging - -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, RelationCreatedEvent -from ops.model import ActiveStatus, BlockedStatus, WaitingStatus - -logger = logging.getLogger(__name__) - -# The unique Charmhub library identifier, never change it -LIBID = "dcc76298a3a5435fb9a23e4d60b1bcbe" - -# Increment this major API version when introducing breaking changes -LIBAPI = 0 - -# Increment this PATCH version before using `charmcraft publish-lib` or reset -# to 0 if you are raising the major API version -LIBPATCH = 1 - - -class OpenSearchCOSProvider(COSAgentProvider): - """COS integration -- specific to OpenSearch.""" - - def __init__(self, charm, *args, **kwargs): - super().__init__(charm, *args, **kwargs) - - def _run_plugin_manager(self, event: EventBase): - """Execute plugin manager and handle prossible errors.""" - try: - if self._charm.plugin_manager.run(): - self._charm.on[self._charm.service_manager.name].acquire_lock.emit( - callback_override="_restart_opensearch" - ) - except OpenSearchError as e: - if isinstance(e, OpenSearchPluginError): - self._charm.unit.status = WaitingStatus("Cluster not ready yet") - else: - self._charm.unit.status = BlockedStatus( - "Unexpected error during plugin configuration, check the logs" - ) - # There was an unexpected error, log it and block the unit - logger.error(e) - event.defer() - self._charm.unit.status = ActiveStatus() - - def _on_cos_agent_relation_created(self, event: RelationCreatedEvent): - """COS workflow initialization happens when the COS relation is created.""" - if not self._charm.unit.is_leader(): - return - - self._run_plugin_manager(event) diff --git a/lib/charms/opensearch/v0/opensearch_plugin_manager.py b/lib/charms/opensearch/v0/opensearch_plugin_manager.py index 968c216e0..bed458b50 100644 --- a/lib/charms/opensearch/v0/opensearch_plugin_manager.py +++ b/lib/charms/opensearch/v0/opensearch_plugin_manager.py @@ -23,7 +23,6 @@ OpenSearchPluginInstallError, OpenSearchPluginMissingDepsError, OpenSearchPluginRemoveError, - OpenSearchPrometheusExporter, PluginState, ) @@ -47,11 +46,6 @@ "config": "plugin_opensearch_knn", "relation": None, }, - "prometheus-exporter": { - "class": OpenSearchPrometheusExporter, - "config": None, - "relation": "cos-agent", - }, } diff --git a/lib/charms/opensearch/v0/opensearch_plugins.py b/lib/charms/opensearch/v0/opensearch_plugins.py index 16567dcbb..786e8952c 100644 --- a/lib/charms/opensearch/v0/opensearch_plugins.py +++ b/lib/charms/opensearch/v0/opensearch_plugins.py @@ -356,23 +356,3 @@ def disable(self) -> OpenSearchPluginConfig: def name(self) -> str: """Returns the name of the plugin.""" return "opensearch-knn" - - -class OpenSearchPrometheusExporter(OpenSearchPlugin): - """Implements the opensearch-knn plugin.""" - - @property - def name(self) -> str: - """Returns the name of the plugin.""" - return "prometheus-exporter" - - def config(self) -> OpenSearchPluginConfig: - """Returns a plugin config object to be applied for enabling the current plugin.""" - return OpenSearchPluginConfig( - config_entries_to_add={ - "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 3db448a74..47b4ce13d 100644 --- a/tests/integration/plugins/test_plugins.py +++ b/tests/integration/plugins/test_plugins.py @@ -65,7 +65,7 @@ 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=3400, + timeout=1400, idle_period=IDLE_PERIOD, ) assert len(ops_test.model.applications[APP_NAME].units) == 3