Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[DPE-4683] socket config flag #343

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 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: |
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["tcp", "uds"]
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 @@ -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)
Expand All @@ -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
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": "uds"},
),
ops_test.model.deploy(
PG,
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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
Loading