From fef3ad5a82f197092cd9ff865270b82243d0d0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Li=C3=A9tar?= Date: Mon, 2 Dec 2024 16:05:35 +0000 Subject: [PATCH] Update nginx exporter --- .github/workflows/test.yml | 3 +- config/basic/montagu.yml | 2 +- config/ci/montagu.yml | 2 +- config/complete/montagu.yml | 2 +- tests/test_constellation.py | 188 ++++++++++++++++++++---------------- 5 files changed, 110 insertions(+), 87 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3032521..d8b4e55 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,8 +38,7 @@ jobs: - name: Pull images run: | docker pull mher/flower:0.9.5 - docker pull nginx/nginx-prometheus-exporter:0.10.0 - docker pull nginx/nginx-prometheus-exporter:0.4.1 + docker pull nginx/nginx-prometheus-exporter:1.3.0 docker pull reachfive/fake-smtp-server:latest docker pull redis docker pull redis:5.0 diff --git a/config/basic/montagu.yml b/config/basic/montagu.yml index 90cb445..e517529 100644 --- a/config/basic/montagu.yml +++ b/config/basic/montagu.yml @@ -72,7 +72,7 @@ proxy: metrics: repo: nginx name: nginx-prometheus-exporter - tag: 0.10.0 + tag: 1.3.0 contrib: name: montagu-contrib-portal tag: master diff --git a/config/ci/montagu.yml b/config/ci/montagu.yml index 1385d7b..ab5f122 100644 --- a/config/ci/montagu.yml +++ b/config/ci/montagu.yml @@ -89,7 +89,7 @@ proxy: metrics: repo: nginx name: nginx-prometheus-exporter - tag: 0.10.0 + tag: 1.3.0 contrib: name: montagu-contrib-portal tag: master diff --git a/config/complete/montagu.yml b/config/complete/montagu.yml index e25a84b..22a7853 100644 --- a/config/complete/montagu.yml +++ b/config/complete/montagu.yml @@ -82,7 +82,7 @@ proxy: metrics: repo: nginx name: nginx-prometheus-exporter - tag: 0.4.1 + tag: 1.3.0 ## This section describes how to get the certificate in. We ## support two sources: ## diff --git a/tests/test_constellation.py b/tests/test_constellation.py index 6f1630c..e7a303a 100644 --- a/tests/test_constellation.py +++ b/tests/test_constellation.py @@ -10,137 +10,161 @@ def test_start_and_stop(): cfg = MontaguConfig("config/basic") obj = montagu_constellation(cfg) - obj.start() - - cl = docker.client.from_env() - - assert docker_util.network_exists(cfg.network) - assert docker_util.volume_exists(cfg.volumes["db"]) - assert docker_util.volume_exists(cfg.volumes["burden_estimates"]) - assert docker_util.volume_exists(cfg.volumes["emails"]) - assert docker_util.volume_exists(cfg.volumes["mq"]) - assert docker_util.volume_exists(cfg.volumes["templates"]) - assert docker_util.volume_exists(cfg.volumes["guidance"]) - - assert docker_util.container_exists("montagu-api") - assert docker_util.container_exists("montagu-db") - assert docker_util.container_exists("montagu-proxy") - assert docker_util.container_exists("montagu-proxy-metrics") - assert docker_util.container_exists("montagu-admin") - assert docker_util.container_exists("montagu-contrib") - assert docker_util.container_exists("montagu-mq") - assert docker_util.container_exists("montagu-flower") - assert docker_util.container_exists("montagu-task-queue") - assert docker_util.container_exists("montagu-fake-smtp") - - containers = cl.containers.list() - assert len(containers) == 10 - - obj.stop(kill=True, remove_volumes=True) + try: + obj.start() + + cl = docker.client.from_env() + + assert docker_util.network_exists(cfg.network) + assert docker_util.volume_exists(cfg.volumes["db"]) + assert docker_util.volume_exists(cfg.volumes["burden_estimates"]) + assert docker_util.volume_exists(cfg.volumes["emails"]) + assert docker_util.volume_exists(cfg.volumes["mq"]) + assert docker_util.volume_exists(cfg.volumes["templates"]) + assert docker_util.volume_exists(cfg.volumes["guidance"]) + + assert docker_util.container_exists("montagu-api") + assert docker_util.container_exists("montagu-db") + assert docker_util.container_exists("montagu-proxy") + assert docker_util.container_exists("montagu-proxy-metrics") + assert docker_util.container_exists("montagu-admin") + assert docker_util.container_exists("montagu-contrib") + assert docker_util.container_exists("montagu-mq") + assert docker_util.container_exists("montagu-flower") + assert docker_util.container_exists("montagu-task-queue") + assert docker_util.container_exists("montagu-fake-smtp") + + 'montagu-fake-smtp', + 'montagu-task-queue', + 'montagu-flower', + 'montagu-mq', + 'montagu-proxy', + 'montagu-contrib', + 'montagu-admin', + 'montagu-db', + 'montagu-api' + + containers = cl.containers.list() + print([c.name for c in containers]) + assert len(containers) == 10 + + finally: + obj.stop(kill=True, remove_volumes=True) def test_api_configured(): cfg = MontaguConfig("config/basic") obj = montagu_constellation(cfg) - obj.start() - - api = get_container(cfg, "api") - api_config = docker_util.string_from_container(api, "/etc/montagu/api/config.properties").split("\n") + try: + obj.start() - assert "app.url=https://localhost/api" in api_config - assert "db.host=db" in api_config - assert "db.username=api" in api_config - assert "db.password=apipassword" in api_config - assert "allow.localhost=False" in api_config - assert "upload.dir=/upload_dir" in api_config - assert "email.mode=real" not in api_config + api = get_container(cfg, "api") + api_config = docker_util.string_from_container(api, "/etc/montagu/api/config.properties").split("\n") - res = http_get("https://localhost/api/v1") - assert '"status": "success"' in res + assert "app.url=https://localhost/api" in api_config + assert "db.host=db" in api_config + assert "db.username=api" in api_config + assert "db.password=apipassword" in api_config + assert "allow.localhost=False" in api_config + assert "upload.dir=/upload_dir" in api_config + assert "email.mode=real" not in api_config - obj.stop(kill=True, remove_volumes=True) + res = http_get("https://localhost/api/v1") + assert '"status": "success"' in res + finally: + obj.stop(kill=True, remove_volumes=True) cfg = MontaguConfig("config/complete") obj = montagu_constellation(cfg) - obj.start() - api = get_container(cfg, "api") - api_config = docker_util.string_from_container(api, "/etc/montagu/api/config.properties").split("\n") - assert "email.mode=real" in api_config - assert "email.password=changeme" in api_config - assert "flow.url=fakeurl" in api_config + try: + obj.start() + api = get_container(cfg, "api") + api_config = docker_util.string_from_container(api, "/etc/montagu/api/config.properties").split("\n") + assert "email.mode=real" in api_config + assert "email.password=changeme" in api_config + assert "flow.url=fakeurl" in api_config - obj.stop(kill=True, remove_volumes=True) + finally: + obj.stop(kill=True, remove_volumes=True) def test_proxy_configured_self_signed(): cfg = MontaguConfig("config/basic") obj = montagu_constellation(cfg) - obj.start() + try: + obj.start() - api = get_container(cfg, "proxy") - cert = docker_util.string_from_container(api, "/etc/montagu/proxy/certificate.pem") - key = docker_util.string_from_container(api, "/etc/montagu/proxy/ssl_key.pem") - param = docker_util.string_from_container(api, "/etc/montagu/proxy/dhparam.pem") - assert cert is not None - assert key is not None - assert param is not None + api = get_container(cfg, "proxy") + cert = docker_util.string_from_container(api, "/etc/montagu/proxy/certificate.pem") + key = docker_util.string_from_container(api, "/etc/montagu/proxy/ssl_key.pem") + param = docker_util.string_from_container(api, "/etc/montagu/proxy/dhparam.pem") + assert cert is not None + assert key is not None + assert param is not None - res = http_get("https://localhost") - assert "Montagu" in res + res = http_get("https://localhost") + assert "Montagu" in res - obj.stop(kill=True, remove_volumes=True) + finally: + obj.stop(kill=True, remove_volumes=True) def test_db_configured(): cfg = MontaguConfig("config/complete") obj = montagu_constellation(cfg) - obj.start() + try: + obj.start() - db = get_container(cfg, "db") - res = docker_util.exec_safely(db, f'psql -U {cfg.db_root_user} -d postgres -c "\\du"') - res = res.output.decode("UTF-8") + db = get_container(cfg, "db") + res = docker_util.exec_safely(db, f'psql -U {cfg.db_root_user} -d postgres -c "\\du"') + res = res.output.decode("UTF-8") - for u in cfg.db_users: - assert u in res + for u in cfg.db_users: + assert u in res - query = "SELECT * FROM pg_replication_slots WHERE slot_name = 'barman'" - res = docker_util.exec_safely(db, f'psql -U {cfg.db_root_user} -d postgres -c "{query}"') - res = res.output.decode("UTF-8") + query = "SELECT * FROM pg_replication_slots WHERE slot_name = 'barman'" + res = docker_util.exec_safely(db, f'psql -U {cfg.db_root_user} -d postgres -c "{query}"') + res = res.output.decode("UTF-8") - assert "barman" in res + assert "barman" in res - obj.stop(kill=True, remove_volumes=True) + finally: + obj.stop(kill=True, remove_volumes=True) def test_proxy_configured_ssl(): cfg = MontaguConfig("config/complete") obj = montagu_constellation(cfg) - obj.start() + try: + obj.start() - api = get_container(cfg, "proxy") - cert = docker_util.string_from_container(api, "/etc/montagu/proxy/certificate.pem") - key = docker_util.string_from_container(api, "/etc/montagu/proxy/ssl_key.pem") - param = docker_util.string_from_container(api, "/etc/montagu/proxy/dhparam.pem") - assert cert == "cert" - assert key == "k3y" - assert param == "param" + api = get_container(cfg, "proxy") + cert = docker_util.string_from_container(api, "/etc/montagu/proxy/certificate.pem") + key = docker_util.string_from_container(api, "/etc/montagu/proxy/ssl_key.pem") + param = docker_util.string_from_container(api, "/etc/montagu/proxy/dhparam.pem") + assert cert == "cert" + assert key == "k3y" + assert param == "param" - obj.stop(kill=True, remove_volumes=True) + finally: + obj.stop(kill=True, remove_volumes=True) def test_metrics(): cfg = MontaguConfig("config/basic") obj = montagu_constellation(cfg) - obj.start() - http_get("http://localhost:9113/metrics") + try: + obj.start() + http_get("http://localhost:9113/metrics") - obj.stop(kill=True) + finally: + obj.stop(kill=True) def get_container(cfg, name):