diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 009277f6..46db740e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,8 +17,7 @@ Deploy the charm: ```bash charmcraft pack juju deploy ./wordpress-k8s_ubuntu-22.04-amd64.charm \ - --resource jenkins-image=localhost:32000/wordpress:test \ - --resource apache-prometheus-exporter-image=bitnami/apache-exporter:0.11.0 + --resource jenkins-image=localhost:32000/wordpress:test ``` ## Generating src docs for every commit diff --git a/docs/explanation/containers.md b/docs/explanation/containers.md index 03d83f0f..37f6a1ea 100644 --- a/docs/explanation/containers.md +++ b/docs/explanation/containers.md @@ -1,7 +1,6 @@ # Containers -The core component of wordpress-k8s charm consists of a wordpress-k8s main workload container and a -`apache-prometheus-exporter` sidecar container. Both services inside the containers are driven by +The core component of wordpress-k8s charm consists of a wordpress-k8s main workload container with an Apache Prometheus exporter. The services inside the container are driven by Pebble, a lightweight API-driven process supervisor that controls the lifecycle of a service. Learn more about pebble and its layer configurations [here](https://github.com/canonical/pebble). @@ -35,14 +34,6 @@ to both `access.log`, `error.log` files and container logs in [`000-default.conf`](https://github.com/canonical/wordpress-k8s-operator/blob/main/files/000-default.conf). These files are essential for promtail to read and push latest logs to loki periodically. -### apache-prometheus-exporter - -This is a sidecar container that contains a golang binary to periodically scrape `/server-status` -route from the main wordpress container. It exposes WordPress Apache server’s metrics in open -metrics format on port 9117. It should be noted that some of its own metrics from the Prometheus -Golang client are exposed that are not part of the WordPress Apache’s metrics and are denoted by -`go_` prefix. - ### charm This container is the main point of contact with the juju controller. It communicates with juju to diff --git a/docs/explanation/oci-image.md b/docs/explanation/oci-image.md index 098a17e5..5e6470b2 100644 --- a/docs/explanation/oci-image.md +++ b/docs/explanation/oci-image.md @@ -18,10 +18,4 @@ image during build step. The latest CLI php archive file from source is used. Currently, WordPress version 5.9.3 is used alongside Ubuntu 20.04 base image. The Ubuntu base image hasn't yet been upgraded to 22.04 due to an unsupported php version 8 for `wordpress-launchpad-integration` plugin (supported php version 7). All other plugins and themes use -the latest stable version by default, downloaded from the source. - -### apache-prometheus-exporter-image - -This is the image required for sidecar container apache-prometheus-exporter. Openly available image -`bitnami/apache-exporter` is used. Read more about the image from the official Docker Hub -[source](https://hub.docker.com/r/bitnami/apache-exporter/). \ No newline at end of file +the latest stable version by default, downloaded from the source. \ No newline at end of file diff --git a/docs/how-to/contribute.md b/docs/how-to/contribute.md index 78d8e3d6..321bf8b6 100644 --- a/docs/how-to/contribute.md +++ b/docs/how-to/contribute.md @@ -59,8 +59,7 @@ Deploy the locally built WordPress charm with the following command. ``` juju deploy ./wordpress-k8s_ubuntu-22.04-amd64_ubuntu-20.04-amd64.charm \ - --resource wordpress-image=wordpress \ - --resource apache-prometheus-exporter-image=bitnami/apache-exporter:0.11.0 + --resource wordpress-image=wordpress ``` You should now be able to see your local wordpress-k8s charm progress through the stages of the diff --git a/metadata.yaml b/metadata.yaml index 8367b433..7b14e703 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -30,8 +30,6 @@ containers: mounts: - storage: uploads location: /var/www/html/wp-content/uploads - apache-prometheus-exporter: - resource: apache-prometheus-exporter-image storage: uploads: @@ -46,10 +44,6 @@ resources: wordpress-image: type: oci-image description: OCI image for wordpress - apache-prometheus-exporter-image: - type: oci-image - description: Prometheus exporter for apache - upstream-source: bitnami/apache-exporter:0.13.3 provides: metrics-endpoint: diff --git a/src/charm.py b/src/charm.py index 9275cb10..c0ce0523 100755 --- a/src/charm.py +++ b/src/charm.py @@ -29,19 +29,18 @@ from ops.charm import ActionEvent, CharmBase, HookEvent, PebbleReadyEvent, UpgradeCharmEvent from ops.framework import EventBase from ops.main import main -from ops.model import ( - ActiveStatus, - BlockedStatus, - MaintenanceStatus, - RelationDataContent, - WaitingStatus, -) +from ops.model import ActiveStatus, RelationDataContent, WaitingStatus from ops.pebble import ExecProcess from yaml import safe_load import exceptions import types_ -from cos import APACHE_LOG_PATHS, PROM_EXPORTER_PEBBLE_CONFIG, WORDPRESS_SCRAPE_JOBS +from cos import ( + _APACHE_EXPORTER_PEBBLE_SERVICE, + APACHE_LOG_PATHS, + PROM_EXPORTER_PEBBLE_CONFIG, + WORDPRESS_SCRAPE_JOBS, +) from state import CharmConfigInvalidError, State # MySQL logger prints database credentials on debug level, silence it @@ -176,10 +175,6 @@ def __init__(self, *args, **kwargs): self.framework.observe(self.on.wordpress_pebble_ready, self._set_version) self.framework.observe(self.on.wordpress_pebble_ready, self._reconciliation) self.framework.observe(self.on["wordpress-replica"].relation_changed, self._reconciliation) - self.framework.observe( - self.on.apache_prometheus_exporter_pebble_ready, - self._on_apache_prometheus_exporter_pebble_ready, - ) def _set_version(self, _: PebbleReadyEvent) -> None: """Set WordPress application version to Juju charm's app version status.""" @@ -716,6 +711,9 @@ def _init_pebble_layer(self): }, } self._container().add_layer("wordpress", layer, combine=True) + self._container().add_layer( + _APACHE_EXPORTER_PEBBLE_SERVICE.name, PROM_EXPORTER_PEBBLE_CONFIG, combine=True + ) def _start_server(self): """Start WordPress (apache) server. On leader unit, also make sure WordPress is installed. @@ -761,6 +759,8 @@ def _start_server(self): self._init_pebble_layer() if not self._container().get_service(self._SERVICE_NAME).is_running(): self._container().start(self._SERVICE_NAME) + if not self._container().get_service(_APACHE_EXPORTER_PEBBLE_SERVICE.name).is_running(): + self._container().start(_APACHE_EXPORTER_PEBBLE_SERVICE.name) def _current_wp_config(self): """Retrieve the current version of wp-config.php from server, return None if not exists. @@ -1473,23 +1473,6 @@ def _reconciliation(self, _event: EventBase) -> None: else: self.unit.status = WaitingStatus("Waiting for pebble") - def _on_apache_prometheus_exporter_pebble_ready(self, event: PebbleReadyEvent): - """Configure and start apache prometheus exporter. - - Args: - event: Event triggering the handler. - """ - if not event.workload: - self.unit.status = BlockedStatus("Internal Error, pebble container not found.") - return - container = event.workload - pebble: ops.pebble.Client = container.pebble - self.unit.status = MaintenanceStatus(f"Adding {container.name} layer to pebble") - container.add_layer(container.name, PROM_EXPORTER_PEBBLE_CONFIG, combine=True) - self.unit.status = MaintenanceStatus(f"Starting {container.name} container") - pebble.replan_services() - self._reconciliation(event) - if __name__ == "__main__": # pragma: no cover main(WordpressCharm) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index afa8a2de..07b17175 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -84,7 +84,6 @@ async def wordpress_fixture( charm, resources={ "wordpress-image": wordpress_image, - "apache-prometheus-exporter-image": "bitnami/apache-exporter:0.11.0", }, num_units=1, series="focal", diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 5a47d407..dcd3a3fa 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -14,9 +14,6 @@ import ops.pebble import ops.testing import pytest -from ops.charm import PebbleReadyEvent -from ops.model import Container -from ops.pebble import Client import types_ from charm import WordpressCharm @@ -309,40 +306,6 @@ def test_addon_reconciliation_fail(harness: ops.testing.Harness, monkeypatch: py charm._addon_reconciliation("theme") -@pytest.mark.usefixtures("attach_storage") -def test_prom_exporter_pebble_ready( - patch: WordpressPatch, - harness: ops.testing.Harness, - setup_replica_consensus: typing.Callable[[], dict], - setup_database_relation_no_port: typing.Callable[[], typing.Tuple[int, dict]], -): - """ - arrange: after required relations ready but before prometheus exporter pebble ready. - act: run prometheus exporter pebble ready. - assert: unit should be active. - """ - harness.set_can_connect(harness.model.unit.containers["wordpress"], True) - setup_replica_consensus() - charm: WordpressCharm = typing.cast(WordpressCharm, harness.charm) - _, db_info = setup_database_relation_no_port() - patch.database.prepare_database( - host=db_info["endpoints"], - database=db_info["database"], - user=db_info["username"], - password=db_info["password"], - ) - mock_event = unittest.mock.MagicMock(spec=PebbleReadyEvent) - mock_event.workload = unittest.mock.MagicMock(spec=Container) - mock_event.workload.name = "apache-prometheus-exporter" - mock_event.workload.pebble = unittest.mock.MagicMock(spec=Client) - - charm._on_apache_prometheus_exporter_pebble_ready(mock_event) - - assert isinstance( - harness.model.unit.status, ops.charm.model.ActiveStatus - ), "unit should be in ActiveStatus" - - @pytest.mark.usefixtures("attach_storage") def test_core_reconciliation( patch: WordpressPatch, diff --git a/wordpress_rock/rockcraft.yaml b/wordpress_rock/rockcraft.yaml index 78707c97..63ae8c68 100644 --- a/wordpress_rock/rockcraft.yaml +++ b/wordpress_rock/rockcraft.yaml @@ -74,6 +74,8 @@ parts: - WP_VERSION: 6.4.2 build-packages: - curl + stage-snaps: + - rocks-apache-prometheus-exporter/latest/edge override-build: | curl -sSL --create-dirs https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -o wp chmod +x wp