From 250a7aac3ee1ec6432a4fdc697d2e5bfc42a5bd7 Mon Sep 17 00:00:00 2001 From: gtrkiller Date: Thu, 4 Jan 2024 15:06:14 -0300 Subject: [PATCH 1/2] adding exporter to rock --- content-cache_rock/rockcraft.yaml | 2 ++ metadata.yaml | 7 ----- src/charm.py | 44 ++++--------------------------- tests/integration/conftest.py | 8 ------ 4 files changed, 7 insertions(+), 54 deletions(-) diff --git a/content-cache_rock/rockcraft.yaml b/content-cache_rock/rockcraft.yaml index babe753..83be8e0 100644 --- a/content-cache_rock/rockcraft.yaml +++ b/content-cache_rock/rockcraft.yaml @@ -15,6 +15,8 @@ parts: - nginx-light - bash - coreutils + stage-snaps: + - gtrkiller-nginx-prometheus-exporter/latest/edge copy-config: plugin: dump source: . diff --git a/metadata.yaml b/metadata.yaml index e002a22..1715f46 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -35,18 +35,11 @@ source: https://github.com/canonical/content-cache-k8s-operator containers: content-cache: resource: content-cache-image - nginx-prometheus-exporter: - resource: nginx-prometheus-exporter-image resources: content-cache-image: type: oci-image description: Docker image for content-cache to run - nginx-prometheus-exporter-image: - type: oci-image - description: Prometheus exporter for nginx - auto-fetch: true - upstream-source: nginx/nginx-prometheus-exporter:0.11.0 provides: metrics-endpoint: diff --git a/src/charm.py b/src/charm.py index c07fd40..ab7fef8 100755 --- a/src/charm.py +++ b/src/charm.py @@ -20,13 +20,7 @@ IngressRequires, ) from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider -from ops.charm import ( - ActionEvent, - CharmBase, - ConfigChangedEvent, - PebbleReadyEvent, - UpgradeCharmEvent, -) +from ops.charm import ActionEvent, CharmBase, ConfigChangedEvent, UpgradeCharmEvent from ops.main import main from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus from tabulate import tabulate @@ -79,10 +73,6 @@ def __init__(self, *args): self.framework.observe( self.on.content_cache_pebble_ready, self._on_content_cache_pebble_ready ) - self.framework.observe( - self.on.nginx_prometheus_exporter_pebble_ready, - self._on_nginx_prometheus_exporter_pebble_ready, - ) # Provide ability for Content-cache to be scraped by Prometheus using prometheus_scrape self._metrics_endpoint = MetricsEndpointProvider( self, jobs=[{"static_configs": [{"targets": ["*:9113"]}]}] @@ -117,17 +107,6 @@ def _on_content_cache_pebble_ready(self, event) -> None: self.model.unit.status = MaintenanceStatus(msg) self.on.config_changed.emit() - def _on_nginx_prometheus_exporter_pebble_ready(self, event: PebbleReadyEvent) -> None: - """Handle content_cache_pebble_ready event and configure workload container. - - Args: - event: Event triggering the pebble ready hook for the nginx prometheus exporter. - """ - msg = "Configuring workload container (nginx-prometheus-exporter-pebble-ready)" - logger.info(msg) - self.model.unit.status = MaintenanceStatus(msg) - self.on.config_changed.emit() - def _on_start(self, event) -> None: """Handle workload container started. @@ -257,23 +236,10 @@ def configure_workload_container(self, event: ConfigChangedEvent) -> None: logger.info(msg) self.unit.status = MaintenanceStatus(msg) container.add_layer(CONTAINER_NAME, pebble_config, combine=True) + container.add_layer(EXPORTER_CONTAINER_NAME, exporter_config, combine=True) container.pebble.replan_services() else: - self.unit.status = WaitingStatus("Waiting for Pebble to start (content-cache)") - event.defer() - return - - exporter_container = self.unit.get_container(EXPORTER_CONTAINER_NAME) - if exporter_container.can_connect(): - msg = "Updating exporter pebble layer config" - logger.info(msg) - self.unit.status = MaintenanceStatus(msg) - exporter_container.add_layer(EXPORTER_CONTAINER_NAME, exporter_config, combine=True) - exporter_container.pebble.replan_services() - else: - self.unit.status = WaitingStatus( - "Waiting for Pebble to start (nginx-prometheus-exporter)" - ) + self.unit.status = WaitingStatus("Waiting for Pebble to start") event.defer() return @@ -298,13 +264,13 @@ def _get_nginx_prometheus_exporter_pebble_config(self): """Generate pebble config for the nginx-prometheus-exporter container. Returns: - Pebble layer config for the nginx-prometheus-exporter container. + Pebble layer config for the nginx-prometheus-exporter layer. """ return { "summary": "Nginx prometheus exporter", "description": "Prometheus exporter for nginx", "services": { - "nginx-exporter": { + "nginx-prometheus-exporter": { "override": "replace", "summary": "Nginx Prometheus Exporter", "command": ( diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index d0b24af..5e35bb5 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -93,12 +93,6 @@ async def get_unit_ip_list_action(): yield get_unit_ip_list_action -@fixture(scope="module") -def nginx_prometheus_exporter_image(metadata): - """Provide the statsd prometheus exporter image from the metadata.""" - yield metadata["resources"]["nginx-prometheus-exporter-image"]["upstream-source"] - - @pytest_asyncio.fixture(scope="function") async def unit_ip_list(get_unit_ip_list): """Yield ip addresses of current units.""" @@ -131,7 +125,6 @@ async def app( app_name: str, charm_file: str, content_cache_image: str, - nginx_prometheus_exporter_image: str, nginx_integrator_app: Application, run_action, ): @@ -162,7 +155,6 @@ async def app( application_name=app_name, resources={ "content-cache-image": content_cache_image, - "nginx-prometheus-exporter-image": nginx_prometheus_exporter_image, }, series="jammy", ) From 4f119cd5fde1d0df03a4380af0bac39f0e89cbf3 Mon Sep 17 00:00:00 2001 From: gtrkiller Date: Fri, 5 Jan 2024 11:35:09 -0300 Subject: [PATCH 2/2] address comments --- content-cache_rock/rockcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content-cache_rock/rockcraft.yaml b/content-cache_rock/rockcraft.yaml index 66fce64..6f36dc4 100644 --- a/content-cache_rock/rockcraft.yaml +++ b/content-cache_rock/rockcraft.yaml @@ -16,7 +16,7 @@ parts: - bash - coreutils stage-snaps: - - gtrkiller-nginx-prometheus-exporter/latest/edge + - rocks-nginx-prometheus-exporter/latest/edge copy-config: plugin: dump source: .