diff --git a/config.yaml b/config.yaml index 1eb6ba8a9..c7bf23a72 100644 --- a/config.yaml +++ b/config.yaml @@ -21,6 +21,12 @@ options: Virtual IP to use to front pgbouncer units. Used only in case of external node connection. type: string + local_connection_type: + default: tcp + description: | + Type of local connectivity to provide. Must be either 'tcp' or 'uds'. Only applies to the database interface. + type: string + pool_mode: default: session description: | diff --git a/src/config.py b/src/config.py index 7883de226..e8794e0e9 100644 --- a/src/config.py +++ b/src/config.py @@ -19,5 +19,6 @@ class CharmConfig(BaseConfigModel): listen_port: PositiveInt metrics_port: PositiveInt vip: Optional[IPvAnyAddress] + local_connection_type: Literal["tcp", "uds"] pool_mode: Literal["session", "transaction", "statement"] max_db_connections: conint(ge=0) diff --git a/src/relations/pgbouncer_provider.py b/src/relations/pgbouncer_provider.py index a7e3287b9..35f332fe6 100644 --- a/src/relations/pgbouncer_provider.py +++ b/src/relations/pgbouncer_provider.py @@ -60,7 +60,7 @@ RelationDepartedEvent, ) -from constants import CLIENT_RELATION_NAME +from constants import CLIENT_RELATION_NAME, PGB_RUN_DIR logger = logging.getLogger(__name__) @@ -246,8 +246,6 @@ def update_connection_info(self, relation): if not database or not password: return - host = "localhost" - uri_host = host if exposed: if self.charm.config.vip: host = str(self.charm.config.vip) @@ -258,6 +256,13 @@ def update_connection_info(self, relation): self.charm.peers.leader_ip, *[ip for ip in self.charm.peers.units_ips if ip != self.charm.peers.leader_ip], ]) + elif self.charm.config.local_connection_type == "uds": + host = f"{PGB_RUN_DIR}/{self.charm.app.name}/instance_0" + uri_host = host + else: + host = "localhost" + uri_host = host + port = self.charm.config.listen_port initial_status = self.charm.unit.status diff --git a/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py b/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py index dd0442b57..ca5c2f95c 100644 --- a/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py +++ b/tests/integration/relations/pgbouncer_provider/test_pgbouncer_provider.py @@ -61,6 +61,7 @@ async def test_database_relation_with_charm_libraries(ops_test: OpsTest, pgb_cha pgb_charm_jammy, application_name=PGB, num_units=None, + config={"local_connection_type": "uds"}, ), ops_test.model.deploy( PG, diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index 3426d9874..093f9000c 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -40,6 +40,7 @@ async def test_build_and_deploy(ops_test: OpsTest, pgb_charm_jammy): pgb_charm_jammy, application_name=PGB, num_units=None, + config={"local_connection_type": "uds"}, ), ops_test.model.deploy( PG, diff --git a/tests/integration/test_config.py b/tests/integration/test_config.py index 8488f23e1..d18940b49 100644 --- a/tests/integration/test_config.py +++ b/tests/integration/test_config.py @@ -58,6 +58,7 @@ async def test_config_parameters(ops_test: OpsTest, pgb_charm_jammy) -> None: "listen_port": "0", "metrics_port": "0", "vip": test_string, + "local_connection_type": test_string, "pool_mode": test_string, "max_db_connections": "-1", }