Skip to content

Commit

Permalink
Minor improvements to how requests to router exporter are made
Browse files Browse the repository at this point in the history
  • Loading branch information
shayancanonical committed Jul 1, 2024
1 parent 4ac2cb7 commit 721b70d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
20 changes: 8 additions & 12 deletions tests/integration/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ async def test_exporter_endpoint(ops_test: OpsTest, mysql_router_charm_series: s
unit_address = await unit.get_public_address()

try:
with requests.Session() as session:
session.get(f"http://{unit_address}:49152/metrics", stream=False)
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
except requests.exceptions.ConnectionError as e:
assert "[Errno 111] Connection refused" in str(e), "❌ expected connection refused error"
else:
Expand All @@ -137,14 +136,12 @@ async def test_exporter_endpoint(ops_test: OpsTest, mysql_router_charm_series: s
wait=tenacity.wait_fixed(10),
):
with attempt:
with requests.Session() as session:
response = session.get(f"http://{unit_address}:49152/metrics", stream=False)
assert (
response.status_code == 200
), "❌ cannot connect to metrics endpoint with relation with cos"
assert "mysqlrouter_route_health" in str(
response.text
), "❌ did not find expected metric in response"
response = requests.get(f"http://{unit_address}:49152/metrics", stream=False)
response.raise_for_status()
assert (
"mysqlrouter_route_health" in response.text
), "❌ did not find expected metric in response"
response.close()

logger.info("Removing relation between mysqlrouter and grafana agent")
await mysql_router_app.remove_relation(
Expand All @@ -158,8 +155,7 @@ async def test_exporter_endpoint(ops_test: OpsTest, mysql_router_charm_series: s
):
with attempt:
try:
with requests.Session() as session:
session.get(f"http://{unit_address}:49152/metrics", stream=False)
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
except requests.exceptions.ConnectionError as e:
assert "[Errno 111] Connection refused" in str(
e
Expand Down
20 changes: 8 additions & 12 deletions tests/integration/test_exporter_with_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ async def test_exporter_endpoint(ops_test: OpsTest, mysql_router_charm_series: s
):
with attempt:
try:
with requests.Session() as session:
session.get(f"http://{unit_address}:49152/metrics", stream=False)
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
except requests.exceptions.ConnectionError as e:
assert "[Errno 111] Connection refused" in str(
e
Expand All @@ -180,14 +179,12 @@ async def test_exporter_endpoint(ops_test: OpsTest, mysql_router_charm_series: s
wait=tenacity.wait_fixed(10),
):
with attempt:
with requests.Session() as session:
response = session.get(f"http://{unit_address}:49152/metrics", stream=False)
assert (
response.status_code == 200
), "❌ cannot connect to metrics endpoint with relation with cos"
assert "mysqlrouter_route_health" in str(
response.text
), "❌ did not find expected metric in response"
response = requests.get(f"http://{unit_address}:49152/metrics", stream=False)
response.raise_for_status()
assert (
"mysqlrouter_route_health" in response.text
), "❌ did not find expected metric in response"
response.close()

for attempt in tenacity.Retrying(
reraise=True,
Expand Down Expand Up @@ -216,8 +213,7 @@ async def test_exporter_endpoint(ops_test: OpsTest, mysql_router_charm_series: s
):
with attempt:
try:
with requests.Session() as session:
session.get(f"http://{unit_address}:49152/metrics", stream=False)
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
except requests.exceptions.ConnectionError as e:
assert "[Errno 111] Connection refused" in str(
e
Expand Down

0 comments on commit 721b70d

Please sign in to comment.