diff --git a/lib/charms/tempo_k8s/v1/charm_tracing.py b/lib/charms/tempo_k8s/v1/charm_tracing.py index fa926539b..2dbdddd68 100644 --- a/lib/charms/tempo_k8s/v1/charm_tracing.py +++ b/lib/charms/tempo_k8s/v1/charm_tracing.py @@ -224,7 +224,6 @@ def _remove_stale_otel_sdk_packages(): _remove_stale_otel_sdk_packages() - import functools import inspect import logging @@ -271,7 +270,7 @@ def _remove_stale_otel_sdk_packages(): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 14 +LIBPATCH = 15 PYDEPS = ["opentelemetry-exporter-otlp-proto-http==1.21.0"] @@ -281,7 +280,6 @@ def _remove_stale_otel_sdk_packages(): # set this to 0 if you are debugging/developing this library source dev_logger.setLevel(logging.CRITICAL) - _CharmType = Type[CharmBase] # the type CharmBase and any subclass thereof _C = TypeVar("_C", bound=_CharmType) _T = TypeVar("_T", bound=type) @@ -333,9 +331,22 @@ def _get_tracer() -> Optional[Tracer]: try: return tracer.get() except LookupError: + # fallback: this course-corrects for a user error where charm_tracing symbols are imported + # from different paths (typically charms.tempo_k8s... and lib.charms.tempo_k8s...) try: ctx: Context = copy_context() if context_tracer := _get_tracer_from_context(ctx): + logger.warning( + "Tracer not found in `tracer` context var. " + "Verify that you're importing all `charm_tracing` symbols from the same module path. \n" + "For example, DO" + ": `from charms.lib...charm_tracing import foo, bar`. \n" + "DONT: \n" + " \t - `from charms.lib...charm_tracing import foo` \n" + " \t - `from lib...charm_tracing import bar` \n" + "For more info: https://python-notes.curiousefficiency.org/en/latest/python" + "_concepts/import_traps.html#the-double-import-trap" + ) return context_tracer.get() else: return None diff --git a/src/relations/pgbouncer_provider.py b/src/relations/pgbouncer_provider.py index f360c22cb..33d99b944 100644 --- a/src/relations/pgbouncer_provider.py +++ b/src/relations/pgbouncer_provider.py @@ -250,16 +250,27 @@ def update_endpoints(self, relation=None) -> None: # This is a relation that is going away and finds itself in a broken state # proceed to the next relation continue + user = f"relation_id_{relation.id}" + database = self.database_provides.fetch_relation_field(relation.id, "database") + password = self.database_provides.fetch_my_relation_field(relation.id, "password") # Read-write endpoint if relation.data[relation.app].get("external-node-connectivity", "false") == "true": self.database_provides.set_endpoints(relation.id, nodeports["rw"]) self.database_provides.set_read_only_endpoints(relation.id, nodeports["ro"]) + self.database_provides.set_uris( + relation.id, + f"postgresql://{user}:{password}@{nodeports['rw']}/{database}", + ) else: self.database_provides.set_endpoints(relation.id, internal_rw) self.database_provides.set_read_only_endpoints( relation.id, ",".join([f"{host}:{internal_port}" for host in internal_hostnames]), ) + self.database_provides.set_uris( + relation.id, + f"postgresql://{user}:{password}@{internal_rw}/{database}", + ) def get_database(self, relation): """Gets database name from relation.""" diff --git a/tests/integration/relations/pgbouncer_provider/helpers.py b/tests/integration/relations/pgbouncer_provider/helpers.py index 2cd88efc3..f2465b0b6 100644 --- a/tests/integration/relations/pgbouncer_provider/helpers.py +++ b/tests/integration/relations/pgbouncer_provider/helpers.py @@ -268,15 +268,19 @@ def check_exposed_connection(credentials, tls): table_name = "expose_test" smoke_val = str(uuid4()) - host, port = credentials["postgresql"]["endpoints"].split(":") - user = credentials["postgresql"]["username"] - password = credentials["postgresql"]["password"] - database = credentials["postgresql"]["database"] if tls: sslmode = "require" else: sslmode = "disable" - connstr = f"dbname='{database}' user='{user}' host='{host}' port='{port}' password='{password}' connect_timeout=1 sslmode={sslmode}" + if "uris" in credentials["postgresql"]: + uri = credentials["postgresql"]["uris"] + connstr = f"{uri}?connect_timeout=1&sslmode={sslmode}" + else: + host, port = credentials["postgresql"]["endpoints"].split(":") + user = credentials["postgresql"]["username"] + password = credentials["postgresql"]["password"] + database = credentials["postgresql"]["database"] + connstr = f"dbname='{database}' user='{user}' host='{host}' port='{port}' password='{password}' connect_timeout=1 sslmode={sslmode}" connection = psycopg2.connect(connstr) connection.autocommit = True smoke_query = (