diff options
author | Paul Okstad <pokstad@gitlab.com> | 2020-07-20 21:10:26 +0300 |
---|---|---|
committer | Paul Okstad <pokstad@gitlab.com> | 2020-07-20 21:10:26 +0300 |
commit | bad706c97623772544a60dc65af18befc73a229d (patch) | |
tree | 1c14803efb7bdc711d5627a294f86c3954803753 | |
parent | 430be20e333ed8041fc342b587ccf7b0a711610b (diff) | |
parent | 4ba9322a76215af79583758e0a8063d5cdb2d516 (diff) |
Merge branch 'ps-add-pgbouncer' into 'master'
Praefect: include PgBouncer in CI
Closes #2816
See merge request gitlab-org/gitaly!2378
-rw-r--r-- | .gitlab-ci.yml | 9 | ||||
-rw-r--r-- | changelogs/unreleased/ps-add-pgbouncer.yml | 5 | ||||
-rw-r--r-- | internal/praefect/config/config.go | 21 | ||||
-rw-r--r-- | internal/praefect/config/config_test.go | 6 | ||||
-rw-r--r-- | internal/praefect/datastore/glsql/testdata/pgbouncer.ini | 9 |
5 files changed, 34 insertions, 16 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5c2a8d8fd..e9ddbbf1a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -238,16 +238,21 @@ praefect_sql_connect: praefect_sql_test: <<: *go_test_definition + image: registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.6-golang-1.14-git-2.27-pgbouncer-1.14 services: - - postgres:9.6 + - postgres:11.8 variables: - PGHOST: postgres + PGHOST: 0.0.0.0 PGPORT: 5432 PGUSER: postgres POSTGRES_HOST_AUTH_METHOD: trust script: - go version - git version + - pgbouncer --version + - adduser --no-create-home --disabled-password --disabled-login --quiet --force-badname --gecos '' pgbouncer-runner + - su pgbouncer-runner -c 'pgbouncer internal/praefect/datastore/glsql/testdata/pgbouncer.ini' & + - for i in {1..10}; do psql -U $PGUSER -c 'select now()' && break; done || { echo 'pgbouncer awaiting failed' ; exit 1; } - make test-postgres lint: diff --git a/changelogs/unreleased/ps-add-pgbouncer.yml b/changelogs/unreleased/ps-add-pgbouncer.yml new file mode 100644 index 000000000..ee6aa931b --- /dev/null +++ b/changelogs/unreleased/ps-add-pgbouncer.yml @@ -0,0 +1,5 @@ +--- +title: 'Praefect: include PgBouncer in CI' +merge_request: 2378 +author: +type: added diff --git a/internal/praefect/config/config.go b/internal/praefect/config/config.go index 4cd10154f..d8e07e970 100644 --- a/internal/praefect/config/config.go +++ b/internal/praefect/config/config.go @@ -189,21 +189,20 @@ func (c *Config) StorageNames() map[string][]string { // DB holds Postgres client configuration data. type DB struct { - Host string `toml:"host"` - Port int `toml:"port"` - User string `toml:"user"` - Password string `toml:"password"` - DBName string `toml:"dbname"` - SSLMode string `toml:"sslmode"` - SSLCert string `toml:"sslcert"` - SSLKey string `toml:"sslkey"` - SSLRootCert string `toml:"sslrootcert"` - StatementTimeoutMilliseconds int `toml:"default_timeout_ms"` + Host string `toml:"host"` + Port int `toml:"port"` + User string `toml:"user"` + Password string `toml:"password"` + DBName string `toml:"dbname"` + SSLMode string `toml:"sslmode"` + SSLCert string `toml:"sslcert"` + SSLKey string `toml:"sslkey"` + SSLRootCert string `toml:"sslrootcert"` } // ToPQString returns a connection string that can be passed to github.com/lib/pq. func (db DB) ToPQString() string { - fields := []string{fmt.Sprintf("statement_timeout=%d", db.StatementTimeoutMilliseconds)} + var fields []string if db.Port > 0 { fields = append(fields, fmt.Sprintf("port=%d", db.Port)) } diff --git a/internal/praefect/config/config_test.go b/internal/praefect/config/config_test.go index 51c2d254c..9e70ba676 100644 --- a/internal/praefect/config/config_test.go +++ b/internal/praefect/config/config_test.go @@ -354,7 +354,7 @@ func TestToPQString(t *testing.T) { in DB out string }{ - {desc: "empty", in: DB{}, out: "statement_timeout=0 binary_parameters=yes"}, + {desc: "empty", in: DB{}, out: "binary_parameters=yes"}, { desc: "basic example", in: DB{ @@ -368,14 +368,14 @@ func TestToPQString(t *testing.T) { SSLKey: "/path/to/key", SSLRootCert: "/path/to/root-cert", }, - out: `statement_timeout=0 port=2345 host=1.2.3.4 user=praefect-user password=secret dbname=praefect_production sslmode=require sslcert=/path/to/cert sslkey=/path/to/key sslrootcert=/path/to/root-cert binary_parameters=yes`, + out: `port=2345 host=1.2.3.4 user=praefect-user password=secret dbname=praefect_production sslmode=require sslcert=/path/to/cert sslkey=/path/to/key sslrootcert=/path/to/root-cert binary_parameters=yes`, }, { desc: "with spaces and quotes", in: DB{ Password: "secret foo'bar", }, - out: `statement_timeout=0 password=secret\ foo\'bar binary_parameters=yes`, + out: `password=secret\ foo\'bar binary_parameters=yes`, }, } diff --git a/internal/praefect/datastore/glsql/testdata/pgbouncer.ini b/internal/praefect/datastore/glsql/testdata/pgbouncer.ini new file mode 100644 index 000000000..59580510e --- /dev/null +++ b/internal/praefect/datastore/glsql/testdata/pgbouncer.ini @@ -0,0 +1,9 @@ +[pgbouncer] +listen_addr = * +listen_port = 5432 +auth_type = trust +pool_mode = transaction +ignore_startup_parameters = extra_float_digits +max_db_connections = 100 +[databases] +* = host=postgres port=5432 auth_user=postgres |