feat: configurable PostgreSQL connection (discrete fields, TLS, pool) - #1584
feat: configurable PostgreSQL connection (discrete fields, TLS, pool)#1584dcoric wants to merge 20 commits into
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/postgres #1584 +/- ##
=================================================
+ Coverage 90.41% 90.56% +0.15%
=================================================
Files 87 92 +5
Lines 8661 9182 +521
Branches 1603 1711 +108
=================================================
+ Hits 7831 8316 +485
- Misses 799 835 +36
Partials 31 31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # src/config/generated/config.ts
| * loudly rather than silently defaulting to `localhost`. | ||
| */ | ||
| const hasConnectionConfig = (db: DatabaseConfig): boolean => | ||
| Boolean(db.connectionString || db.host || process.env.PGHOST); |
There was a problem hiding this comment.
This only checks PGHOST, but the message says "or the PG* env variables". A setup with PGUSER/PGDATABASE and no PGHOST is valid but gets refused. Could the check also look at PGUSER/PGDATABASE/PGHOSTADDR so only the truly-empty case is blocked?
| */ | ||
| const buildPoolConfig = (db: DatabaseConfig): PoolConfig => { | ||
| const config: PoolConfig = {}; | ||
| if (db.connectionString) { |
There was a problem hiding this comment.
When both connectionString and the discrete fields are set, the discrete fields are silently ignored. It's documented as the intended precedence, but it's an easy operational trap (e.g. someone changes host to repoint the DB, nothing happens because an old connectionString is still winning with no signal). Worth a console.warn here noting the discrete fields are being ignored?
# Conflicts: # website/docs/architecture/architecture.md
…-connection-config # Conflicts: # website/docs/architecture/architecture.md
4fc5065 to
1d6a005
Compare
Signed-off-by: Juan Escalada <97265671+jescalada@users.noreply.github.com>
jescalada
left a comment
There was a problem hiding this comment.
LGTM after fixing up Fabio's comments 👍🏼
Description
Makes the PostgreSQL sink's connection fully configurable, bringing it closer to parity with the mongo backend.
host,port,user,password,database, used whenconnectionStringis not set. If those are not set either, the standardPGHOST/PGPORT/PGUSER/PGPASSWORD/PGDATABASEenvironment variables are read by the client.ssl:truefor TLS with default certificate verification, or an object of TLS options (rejectUnauthorized,ca,cert,key, ...).pool: connection pool tuning (max,idleTimeoutMillis,connectionTimeoutMillis).Precedence:
connectionString(the config field, thenGIT_PROXY_POSTGRES_CONNECTION_STRING) wins; otherwise the discrete fields; otherwise thePG*environment variables.sslandpoolapply in all cases. If none of these resolve to a connection, GitProxy refuses to start rather than silently defaulting tolocalhost.Unit tests cover the precedence, discrete fields, env fallback,
ssl(boolean and object) andpooloptions.Related Issue
Resolves #1560
Checklist
General
Documentation
Configuration
config.schema.json) was modified:npm run generate-config-types)npm run gen-schema-docrequires the externalgenerate-schema-doctool; needs running in an environment that has it)Tests
npm test)npm run lintandnpm run format:check)npm run check-types)