Skip to content

Commit cb87104

Browse files
[DPE-4173] Stabilize exporter tests by using listen-port to avoid ephemeral ports (#277)
## Issue We are finding connections in `TIME_WAIT` between router exporter and mysql (still investigating what is happening here). Due to pebble's `on-failure: restart`, the exporter service eventually is able to start up when the connection in `TIME_WAIT` terminates after 60s - however, our retry in the test is 3 mins sometimes does not provide enough time for pebble's exponential backoff to work ## Solution Extend the timeout to 7 mins
1 parent c5db3af commit cb87104

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

metadata.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ resources:
5757
mysql-router-image:
5858
type: oci-image
5959
description: OCI image for mysql-router
60-
upstream-source: ghcr.io/canonical/charmed-mysql@sha256:4a605458a09dc53feed91a0d81310dca267b2ac273ed7e1798bc4cb50c14fe68
60+
upstream-source: ghcr.io/canonical/charmed-mysql@sha256:89b8305613f6ce94f78a7c9b4baedef78f2816fd6bc74c00f6607bc5e57bd8e6
6161
assumes:
6262
- k8s-api

src/relations/cos.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class ExporterConfig:
2929
url: str
3030
username: str
3131
password: str
32+
listen_port: str
3233

3334

3435
class COSRelation:
3536
"""Relation with the cos bundle."""
3637

37-
_EXPORTER_PORT = "49152"
38+
_EXPORTER_PORT = "9152"
3839
HTTP_SERVER_PORT = "8443"
3940
_METRICS_RELATION_NAME = "metrics-endpoint"
4041
_LOGGING_RELATION_NAME = "logging"
@@ -86,6 +87,7 @@ def exporter_user_config(self) -> ExporterConfig:
8687
url=f"https://127.0.0.1:{self.HTTP_SERVER_PORT}",
8788
username=self.MONITORING_USERNAME,
8889
password=self.get_monitoring_password(),
90+
listen_port=self._EXPORTER_PORT,
8991
)
9092

9193
@property

src/rock.py

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def update_mysql_router_exporter_service(
161161
startup = ops.pebble.ServiceStartup.ENABLED.value
162162

163163
environment = {
164+
"MYSQLROUTER_EXPORTER_LISTEN_PORT": config.listen_port,
164165
"MYSQLROUTER_EXPORTER_USER": config.username,
165166
"MYSQLROUTER_EXPORTER_PASS": config.password,
166167
"MYSQLROUTER_EXPORTER_URL": config.url,

tests/integration/test_exporter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def test_exporter_endpoint(ops_test: OpsTest) -> None:
112112
unit_address = await get_unit_address(ops_test, unit.name)
113113

114114
try:
115-
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
115+
requests.get(f"http://{unit_address}:9152/metrics", stream=False)
116116
except requests.exceptions.ConnectionError as e:
117117
assert "[Errno 111] Connection refused" in str(e), "❌ expected connection refused error"
118118
else:
@@ -137,7 +137,7 @@ async def test_exporter_endpoint(ops_test: OpsTest) -> None:
137137
wait=tenacity.wait_fixed(10),
138138
):
139139
with attempt:
140-
response = requests.get(f"http://{unit_address}:49152/metrics", stream=False)
140+
response = requests.get(f"http://{unit_address}:9152/metrics", stream=False)
141141
response.raise_for_status()
142142
assert (
143143
"mysqlrouter_route_health" in response.text
@@ -156,7 +156,7 @@ async def test_exporter_endpoint(ops_test: OpsTest) -> None:
156156
):
157157
with attempt:
158158
try:
159-
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
159+
requests.get(f"http://{unit_address}:9152/metrics", stream=False)
160160
except requests.exceptions.ConnectionError as e:
161161
assert "[Errno 111] Connection refused" in str(
162162
e

tests/integration/test_exporter_with_tls.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def test_exporter_endpoint(ops_test: OpsTest) -> None:
161161
):
162162
with attempt:
163163
try:
164-
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
164+
requests.get(f"http://{unit_address}:9152/metrics", stream=False)
165165
except requests.exceptions.ConnectionError as e:
166166
assert "[Errno 111] Connection refused" in str(
167167
e
@@ -187,7 +187,7 @@ async def test_exporter_endpoint(ops_test: OpsTest) -> None:
187187
wait=tenacity.wait_fixed(10),
188188
):
189189
with attempt:
190-
response = requests.get(f"http://{unit_address}:49152/metrics", stream=False)
190+
response = requests.get(f"http://{unit_address}:9152/metrics", stream=False)
191191
response.raise_for_status()
192192
assert (
193193
"mysqlrouter_route_health" in response.text
@@ -222,7 +222,7 @@ async def test_exporter_endpoint(ops_test: OpsTest) -> None:
222222
):
223223
with attempt:
224224
try:
225-
requests.get(f"http://{unit_address}:49152/metrics", stream=False)
225+
requests.get(f"http://{unit_address}:9152/metrics", stream=False)
226226
except requests.exceptions.ConnectionError as e:
227227
assert "[Errno 111] Connection refused" in str(
228228
e

0 commit comments

Comments
 (0)