postgres_exporter
postgres_exporter copied to clipboard
'postgres://' designator is not supported in connection string
The exporter is not able to use connection strings that starts with postgres://
. Only connection string starting with postgresql://
is working.
What did you do?
I'm trying to connect the exporter to a managed DB
What did you expect to see?
Successful connection is expected as psql
is able to connect to the DB with the same connection string:
$ psql "postgres://admin:PASSWORD_REMOVED@xxxxxxxx:21699/defaultdb?sslmode=require"
psql (14.4 (Debian 14.4-1.pgdg110+1))
Connexion SSL (protocole : TLSv1.3, chiffrement : TLS_AES_256_GCM_SHA384, bits : 256, compression : désactivé)
Saisissez « help » pour l'aide.
defaultdb=>
What did you see instead? Under which circumstances?
An error during connection :
Unable to parse DSN as either URI or connstring" dsn="postgres://admin:PASSWORD_REMOVED@xxxxxxxx:21699/defaultdb?sslmode=require
The documentation explains that both designator are allowed:
- postgresql://
- postgres://
The URI scheme designator can be either postgresql:// or postgres://.
Environment
- System information:
Linux 5.10.0-14-amd64 x86_64
- postgres_exporter version:
Running as docker container : prometheuscommunity/postgres-exporter:v0.10.1
postgres_exporter, version 0.10.1 (branch: HEAD, revision: 6cff384d7433bcb1104efe3b496cd27c0658eb09)
build user: root@eb21848025d7
build date: 20220114-17:20:30
go version: go1.17.6
platform: linux/amd64
- postgres_exporter flags:
No flag used but the following env vars :
DATA_SOURCE_NAME=postgres://admin:PASSWORD_REMOVED@xxxxxxxx:21699/defaultdb?sslmode=require
PG_EXPORTER_AUTO_DISCOVER_DATABASES=true
PG_EXPORTER_EXTEND_QUERY_PATH=/mnt/queries.yaml
- PostgreSQL version:
PostgreSQL 14.4 on x86_64-pc-linux-gnu, compiled by gcc, a cc67244dc0 p 47d487d188, 64-bit
- Logs:
ts=2022-06-27T09:04:58.736Z caller=main.go:123 level=info msg="Listening on address" address=:9187
ts=2022-06-27T09:04:58.737Z caller=tls_config.go:195 level=info msg="TLS is disabled." http2=false
ts=2022-06-27T09:09:00.384Z caller=datasource.go:49 level=error msg="Unable to parse DSN as either URI or connstring" dsn="postgres://admin:PASSWORD_REMOVED@xxxxxxxx:21699/defaultdb?sslmode=require"
I see where this is a problem here: https://github.com/prometheus-community/postgres_exporter/blob/master/cmd/postgres_exporter/datasource.go#L39
I think the best course of action would be for us to implement a new DSN type to encapsulate most of the DSN logic. It could implement the String()
function and that would allow us to remove the need for the loggableDSN()
function while maintaining the redacting of sensitive data.