-
Notifications
You must be signed in to change notification settings - Fork 251
Feat/unix sockets #1329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hhamud
wants to merge
14
commits into
pgdogdev:main
Choose a base branch
from
hhamud:feat/unix-sockets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/unix sockets #1329
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
abb4560
feat: add unix socket to stream
hhamud 82fbe24
feat: create transport enum for address
hhamud 51b082c
fix: connection to unix socket
hhamud cc85206
fix: tests with new address
hhamud 4ca476e
feat: add more tests
hhamud f8a1a1e
fix: clippy warnings
hhamud d9f3926
fix: remove panics
hhamud 4f81140
fix: integration test to use setup scripts
hhamud 9ecc15c
fix: failing tests
hhamud ad1075c
feat: add further tests for cov
hhamud 21c45fc
chore: cleanup
hhamud 44a8ec3
chore: fix tests
hhamud 5920e39
feat: add into helper
hhamud cbb7b24
fix: reduce single allocation
hhamud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # ------------------------------------------------------------------------------ | ||
| # ----- General ---------------------------------------------------------------- | ||
|
|
||
| [general] | ||
| auth_type = "trust" | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # ----- Database :: pgdog ------------------------------------------------------ | ||
|
|
||
| [[databases]] | ||
| name = "pgdog" | ||
| host = "/tmp" | ||
| port = 5432 | ||
| database_name = "pgdog" | ||
| user = "pgdog" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/bin/bash | ||
| # End-to-end test: pgdog connecting to Postgres over a Unix domain socket. | ||
| set -euo pipefail | ||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
| source ${SCRIPT_DIR}/../common.sh | ||
|
|
||
| export PGPASSWORD=pgdog | ||
| CTL_PSQL=(psql -h 127.0.0.1 -p 5432 -U pgdog -d postgres -t -A) | ||
|
|
||
| # Detect socket dir + port from the running Postgres. | ||
| SOCKET_DIR=$("${CTL_PSQL[@]}" -c "show unix_socket_directories" | cut -d, -f1) | ||
| PG_BACKEND_PORT=$("${CTL_PSQL[@]}" -c "show port") | ||
| if [ -z "${SOCKET_DIR}" ]; then | ||
| echo "FAIL: could not detect unix_socket_directories from Postgres" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "Postgres unix socket directory: ${SOCKET_DIR} (port ${PG_BACKEND_PORT})" | ||
|
|
||
| # Pre-flight: pgdog must be able to reach Postgres over the socket as pgdog. | ||
| if ! psql -h "${SOCKET_DIR}" -p "${PG_BACKEND_PORT}" -U pgdog -d postgres \ | ||
| -c "select 1" >/dev/null 2>&1; then | ||
| echo "FAIL: cannot connect to Postgres over unix socket ${SOCKET_DIR} as pgdog." >&2 | ||
| echo " Check pg_hba.conf 'local' lines: trust, or peer with OS user pgdog." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Patch the static config with the detected socket dir/port into a temp dir. | ||
| TMP_CFG_DIR=$(mktemp -d /tmp/pgdog-unix-cfg.XXXXXX) | ||
| sed -e "s|^host = .*|host = \"${SOCKET_DIR}\"|" \ | ||
| -e "s|^port = .*|port = ${PG_BACKEND_PORT}|" \ | ||
| "${SCRIPT_DIR}/pgdog.toml" > "${TMP_CFG_DIR}/pgdog.toml" | ||
| cp "${SCRIPT_DIR}/users.toml" "${TMP_CFG_DIR}/" | ||
|
|
||
| run_pgdog "${TMP_CFG_DIR}" | ||
| wait_for_pgdog | ||
|
|
||
| # 1. Query through the proxy. | ||
| psql -h 127.0.0.1 -p 6432 -U pgdog -d pgdog -v ON_ERROR_STOP=1 \ | ||
| -c "select version()" >/dev/null | ||
| echo "PASS: query through pgdog" | ||
|
|
||
| # 2. Backend connections over the Unix socket have client_addr IS NULL. | ||
| CONNS=$("${CTL_PSQL[@]}" -c \ | ||
| "select count(*) from pg_stat_activity where usename = 'pgdog' and backend_type = 'client backend' and client_addr is null") | ||
| if [ -z "${CONNS}" ] || [ "${CONNS}" = "0" ]; then | ||
| echo "FAIL: no backend connections over Unix socket (client_addr IS NULL)" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "PASS: ${CONNS} backend connection(s) over Unix socket" | ||
|
|
||
| stop_pgdog | ||
| rm -rf "${TMP_CFG_DIR}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [[users]] | ||
| name = "pgdog" | ||
| database = "pgdog" | ||
| password = "pgdog" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this have to be added to the ci suite as new entry otherwise it won't run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean explicitly to be added to the
ci.yamlfile as another script to run?