Skip to content

Commit

Permalink
Update nginx exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
plietar committed Dec 2, 2024
1 parent 2be248a commit fef3ad5
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 87 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/basic/montagu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/ci/montagu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/complete/montagu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
##
Expand Down
188 changes: 106 additions & 82 deletions tests/test_constellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fef3ad5

Please sign in to comment.