From: David Garcia Date: Fri, 11 Mar 2022 15:58:35 +0000 (+0100) Subject: Update exporters: migration to CharmHub X-Git-Tag: v12.0.0rc1~27 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F43%2F11743%2F1;p=osm%2Fdevops.git Update exporters: migration to CharmHub Also, added kafka_endpoint config to kafka exporter Change-Id: I24459e33841da33455b6780a4de2c808ddf30d0b Signed-off-by: David Garcia --- diff --git a/installers/charm/kafka-exporter/config.yaml b/installers/charm/kafka-exporter/config.yaml index 22e93871..59313360 100644 --- a/installers/charm/kafka-exporter/config.yaml +++ b/installers/charm/kafka-exporter/config.yaml @@ -56,3 +56,6 @@ options: description: Enables the security context of the pods type: boolean default: false + kafka_endpoint: + description: Host and port of Kafka in the format : + type: string diff --git a/installers/charm/kafka-exporter/metadata.yaml b/installers/charm/kafka-exporter/metadata.yaml index 1339d279..a70b3b68 100644 --- a/installers/charm/kafka-exporter/metadata.yaml +++ b/installers/charm/kafka-exporter/metadata.yaml @@ -19,7 +19,7 @@ # osm-charmers@lists.launchpad.net ## -name: kafka-exporter +name: kafka-exporter-k8s summary: OSM Prometheus Kafka Exporter description: | A CAAS charm to deploy OSM's Prometheus Kafka Exporter. @@ -38,7 +38,7 @@ resources: image: type: oci-image description: Image of kafka-exporter - upstream-source: "bitnami/kafka-exporter:latest" + upstream-source: "bitnami/kafka-exporter:1.4.2" requires: kafka: interface: kafka diff --git a/installers/charm/kafka-exporter/src/charm.py b/installers/charm/kafka-exporter/src/charm.py index e6b2bf76..ec6eaabe 100755 --- a/installers/charm/kafka-exporter/src/charm.py +++ b/installers/charm/kafka-exporter/src/charm.py @@ -54,6 +54,7 @@ class ConfigModel(ModelValidator): tls_secret_name: Optional[str] image_pull_policy: str security_context: bool + kafka_endpoint: Optional[str] @validator("site_url") def validate_site_url(cls, v): @@ -81,6 +82,18 @@ class ConfigModel(ModelValidator): raise ValueError("value must be always, ifnotpresent or never") return values[v] + @validator("kafka_endpoint") + def validate_kafka_endpoint(cls, v): + if v and len(v.split(":")) != 2: + raise ValueError("value must be in the format :") + return v + + +class KafkaEndpoint: + def __init__(self, host: str, port: str) -> None: + self.host = host + self.port = port + class KafkaExporterCharm(CharmedOsmBase): @@ -144,22 +157,23 @@ class KafkaExporterCharm(CharmedOsmBase): dashboard=Path("templates/kafka_exporter_dashboard.json").read_text(), ) - def _check_missing_dependencies(self, config: ConfigModel): - """Check if there is any relation missing. + def _is_kafka_endpoint_set(self, config: ConfigModel) -> bool: + """Check if Kafka endpoint is set.""" + return config.kafka_endpoint or self._is_kafka_relation_set() - Args: - config (ConfigModel): object with configuration information. + def _is_kafka_relation_set(self) -> bool: + """Check if the Kafka relation is set or not.""" + return self.kafka.host and self.kafka.port - Raises: - RelationsMissing: if kafka is missing. - """ - missing_relations = [] - - if not self.kafka.host or not self.kafka.port: - missing_relations.append("kafka") - - if missing_relations: - raise RelationsMissing(missing_relations) + @property + def kafka_endpoint(self) -> KafkaEndpoint: + config = ConfigModel(**dict(self.config)) + if config.kafka_endpoint: + host, port = config.kafka_endpoint.split(":") + else: + host = self.kafka.host + port = self.kafka.port + return KafkaEndpoint(host, port) def build_pod_spec(self, image_info): """Build the PodSpec to be used. @@ -174,7 +188,8 @@ class KafkaExporterCharm(CharmedOsmBase): config = ConfigModel(**dict(self.config)) # Check relations - self._check_missing_dependencies(config) + if not self._is_kafka_endpoint_set(config): + raise RelationsMissing(["kafka"]) # Create Builder for the PodSpec pod_spec_builder = PodSpecV3Builder( @@ -188,7 +203,7 @@ class KafkaExporterCharm(CharmedOsmBase): config.image_pull_policy, run_as_non_root=config.security_context, ) - container_builder.add_port(name=self.app.name, port=PORT) + container_builder.add_port(name="exporter", port=PORT) container_builder.add_http_readiness_probe( path="/api/health", port=PORT, @@ -208,7 +223,7 @@ class KafkaExporterCharm(CharmedOsmBase): container_builder.add_command( [ "kafka_exporter", - f"--kafka.server={self.kafka.host}:{self.kafka.port}", + f"--kafka.server={self.kafka_endpoint.host}:{self.kafka_endpoint.port}", ] ) container = container_builder.build() diff --git a/installers/charm/mongodb-exporter/metadata.yaml b/installers/charm/mongodb-exporter/metadata.yaml index 26b6dad4..c3a0b776 100644 --- a/installers/charm/mongodb-exporter/metadata.yaml +++ b/installers/charm/mongodb-exporter/metadata.yaml @@ -19,7 +19,7 @@ # osm-charmers@lists.launchpad.net ## -name: mongodb-exporter +name: mongodb-exporter-k8s summary: OSM Prometheus Mongodb Exporter description: | A CAAS charm to deploy OSM's Prometheus Mongodb Exporter. @@ -38,7 +38,7 @@ resources: image: type: oci-image description: Image of mongodb-exporter - upstream-source: "bitnami/mongodb-exporter:latest" + upstream-source: "bitnami/mongodb-exporter:0.30.0" provides: prometheus-scrape: interface: prometheus diff --git a/installers/charm/mongodb-exporter/src/charm.py b/installers/charm/mongodb-exporter/src/charm.py index 500a1e3d..0ee127c8 100755 --- a/installers/charm/mongodb-exporter/src/charm.py +++ b/installers/charm/mongodb-exporter/src/charm.py @@ -210,7 +210,7 @@ class MongodbExporterCharm(CharmedOsmBase): config.image_pull_policy, run_as_non_root=config.security_context, ) - container_builder.add_port(name=self.app.name, port=PORT) + container_builder.add_port(name="exporter", port=PORT) container_builder.add_http_readiness_probe( path="/api/health", port=PORT, diff --git a/installers/charm/mysqld-exporter/metadata.yaml b/installers/charm/mysqld-exporter/metadata.yaml index 5720b968..7f6fb6ea 100644 --- a/installers/charm/mysqld-exporter/metadata.yaml +++ b/installers/charm/mysqld-exporter/metadata.yaml @@ -19,7 +19,7 @@ # osm-charmers@lists.launchpad.net ## -name: mysqld-exporter +name: mysqld-exporter-k8s summary: OSM Prometheus Mysql Exporter description: | A CAAS charm to deploy OSM's Prometheus Mysql Exporter. @@ -38,7 +38,7 @@ resources: image: type: oci-image description: Image of mysqld-exporter - upstream-source: "bitnami/mysqld-exporter:latest" + upstream-source: "bitnami/mysqld-exporter:0.14.0" provides: prometheus-scrape: interface: prometheus diff --git a/installers/charm/mysqld-exporter/src/charm.py b/installers/charm/mysqld-exporter/src/charm.py index 46588b9a..153dbfd9 100755 --- a/installers/charm/mysqld-exporter/src/charm.py +++ b/installers/charm/mysqld-exporter/src/charm.py @@ -209,7 +209,7 @@ class MysqlExporterCharm(CharmedOsmBase): config.image_pull_policy, run_as_non_root=config.security_context, ) - container_builder.add_port(name=self.app.name, port=PORT) + container_builder.add_port(name="exporter", port=PORT) container_builder.add_http_readiness_probe( path="/api/health", port=PORT, diff --git a/installers/charm/mysqld-exporter/tox.ini b/installers/charm/mysqld-exporter/tox.ini index 8e3318a4..4c7970df 100644 --- a/installers/charm/mysqld-exporter/tox.ini +++ b/installers/charm/mysqld-exporter/tox.ini @@ -99,7 +99,7 @@ whitelist_externals = charmcraft sh commands = - charmcraft build + charmcraft pack sh -c 'ubuntu_version=20.04; \ architectures="amd64-aarch64-arm64"; \ charm_name=`cat metadata.yaml | grep -E "^name: " | cut -f 2 -d " "`; \