Skip to content

Commit

Permalink
Socket and config flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Aug 27, 2024
1 parent e646caa commit 3bcf09c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: localhost
description: |
Type of local connectivity to provide. Must be either 'localhost' or 'socket'. Only applies to the database interface.
type: string

pool_mode:
default: session
description: |
Expand Down
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ class CharmConfig(BaseConfigModel):
listen_port: PositiveInt
metrics_port: PositiveInt
vip: Optional[IPvAnyAddress]
local_connection_type: Literal["localhost", "socket"]
pool_mode: Literal["session", "transaction", "statement"]
max_db_connections: conint(ge=0)
11 changes: 8 additions & 3 deletions src/relations/pgbouncer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
RelationDepartedEvent,
)

from constants import CLIENT_RELATION_NAME
from constants import CLIENT_RELATION_NAME, PGB_RUN_DIR

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -239,8 +239,6 @@ def update_connection_info(self, relation):
user = f"relation_id_{relation.id}"
password = self.database_provides.fetch_my_relation_field(relation.id, "password")

host = "localhost"
uri_host = host
if exposed:
if self.charm.config.vip:
host = str(self.charm.config.vip)
Expand All @@ -251,6 +249,13 @@ def update_connection_info(self, relation):
self.charm.leader_ip,
*[ip for ip in self.charm.peers.units_ips if ip != self.charm.leader_ip],
])
elif self.charm.config.local_connection_type == "socket":
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "socket"},
),
ops_test.model.deploy(
PG,
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down

0 comments on commit 3bcf09c

Please # to comment.