Skip to content

Commit

Permalink
add integration test coverage for metrics exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
reneradoi committed Jun 12, 2024
1 parent f3acfd5 commit 39b9098
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +25,8 @@
get_unit_number,
)

METRICS_PORT = 9121

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 39b9098

Please sign in to comment.