Skip to content

Commit 3c48ce8

Browse files
Attempt to stabilize exporter tests in light of bind-address in use issues (#154)
Counterpart of canonical/mysql-router-k8s-operator#254 ## Summary 1. Use `requests.get(stream=False)` to avoid open connections on the router exporter 2. Split the two exporter tests into different files so that they end up in different integration test groups 3. Use a much larger timeout (7mins) that the TIME_WAIT timeout (60s/1min) to see if the snap daemon (mysql-router-exporter) will restart successfully
1 parent b12dcee commit 3c48ce8

File tree

7 files changed

+554
-259
lines changed

7 files changed

+554
-259
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def _on_topic_requested(self, event: TopicRequestedEvent):
331331

332332
# Increment this PATCH version before using `charmcraft publish-lib` or reset
333333
# to 0 if you are raising the major API version
334-
LIBPATCH = 37
334+
LIBPATCH = 38
335335

336336
PYDEPS = ["ops>=2.0.0"]
337337

@@ -2606,6 +2606,14 @@ def set_version(self, relation_id: int, version: str) -> None:
26062606
"""
26072607
self.update_relation_data(relation_id, {"version": version})
26082608

2609+
def set_subordinated(self, relation_id: int) -> None:
2610+
"""Raises the subordinated flag in the application relation databag.
2611+
2612+
Args:
2613+
relation_id: the identifier for a particular relation.
2614+
"""
2615+
self.update_relation_data(relation_id, {"subordinated": "true"})
2616+
26092617

26102618
class DatabaseProviderEventHandlers(EventHandlers):
26112619
"""Provider-side of the database relation handlers."""
@@ -2842,6 +2850,21 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None:
28422850

28432851
def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
28442852
"""Event emitted when the database relation has changed."""
2853+
is_subordinate = False
2854+
remote_unit_data = None
2855+
for key in event.relation.data.keys():
2856+
if isinstance(key, Unit) and not key.name.startswith(self.charm.app.name):
2857+
remote_unit_data = event.relation.data[key]
2858+
elif isinstance(key, Application) and key.name != self.charm.app.name:
2859+
is_subordinate = event.relation.data[key].get("subordinated") == "true"
2860+
2861+
if is_subordinate:
2862+
if not remote_unit_data:
2863+
return
2864+
2865+
if remote_unit_data.get("state") != "ready":
2866+
return
2867+
28452868
# Check which data has changed to emit customs events.
28462869
diff = self._diff(event)
28472870

0 commit comments

Comments
 (0)