diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index 6d6b156..b89e282 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -5,6 +5,7 @@ import logging import pytest +import requests from lightkube import AsyncClient from lightkube.resources.core_v1 import Pod from pytest_operator.plugin import OpsTest @@ -24,6 +25,8 @@ get_unit_number, ) +METRICS_PORT = 9121 + logger = logging.getLogger(__name__) @@ -79,6 +82,22 @@ async def test_application_is_up(ops_test: OpsTest): assert cli.ping() +@pytest.mark.abort_on_fail +async def test_metrics_exporter_is_up(ops_test: OpsTest): + """Check the availability of the metrics endpoint.""" + unit_map = await get_unit_map(ops_test) + leader_num = get_unit_number(unit_map["leader"]) + unit_address = await get_address(ops_test, unit_num=leader_num) + with requests.Session() as http: + redis_exporter_url = f"http://{unit_address}:{METRICS_PORT}/metrics" + resp = http.get(redis_exporter_url) + + assert resp.status_code == 200 + + # if configured correctly there should be more than one metric present + assert resp.text.count("redis") > 10 + + async def test_replication(ops_test: OpsTest): """Check that non leader units are replicas.""" unit_map = await get_unit_map(ops_test)