prometheus-community / prometheus-community/postgres_exporter
PG_EXPORTER_AUTO_DISCOVER_DATABASES can not be used with unix socket host
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 3.6k
- Forks
- 835
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 10
Description
Hi.
My goal is to use /var/run/postgresql/ as DSN host with PG_EXPORTER_AUTO_DISCOVER_DATABASES enabled. But I can't figure out correct way to do this, seems a bug.
First attempt: DSN
Readme offers such DSN:
DATA_SOURCE_NAME="user=postgres host=/var/run/postgresql/ sslmode=disable"
But when I use it I get errors for non default databases:
Feb 5 13:28:59 ru-db-pg-shard-data-01 postgres_exporter[2437731]: time="2021-02-05T13:28:59+03:00" level=error msg="Error opening connection to database (benchmark_main): malformed dsn \"benchmark_main\"" source="postgres_exporter.go:1474"
Feb 5 13:29:05 ru-db-pg-shard-data-01 postgres_exporter[2437731]: time="2021-02-05T13:29:05+03:00" level=error msg="Error opening connection to database (carrot_shard_1): malformed dsn \"carrot_shard_1\"" source="postgres_exporter.go:1474"
Looks like databases found by auto discover are forming wrong dsn.
Second attempt: URI
Correct equal URI as recomended in PostgreSQL docs:
DATA_SOURCE_NAME="postgresql://postgres@/postgres?host=/var/run/postgresql&sslmode=disable"
But library ignores / symbol after @. It is important as it means I set database name, not host. URI from logs looks like:
"postgresql://postgres@carrot_shard_1?host=/var/run/postgresql&sslmode=disable"
Logs:
Feb 5 13:41:21 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:21+03:00" level=info msg="Established new database connection to \"/var/run/postgresql:5432\"." source="postgres_exporter.go:878"
Feb 5 13:41:21 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:21+03:00" level=info msg="Semantic Version Changed on \"/var/run/postgresql:5432\": 0.0.0 -> 9.6.18" source="postgres_exporter.go:1405"
Feb 5 13:41:21 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:21+03:00" level=info msg="Established new database connection to \"benchmark_main:5432\"." source="postgres_exporter.go:878"
Feb 5 13:41:22 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:22+03:00" level=info msg="Established new database connection to \"benchmark_main:5432\"." source="postgres_exporter.go:878"
Feb 5 13:41:24 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:24+03:00" level=info msg="Established new database connection to \"benchmark_main:5432\"." source="postgres_exporter.go:878"
Feb 5 13:41:27 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:27+03:00" level=error msg="Error opening connection to database (postgresql://postgres:PASSWORD_REMOVED@benchmark_main?host=/var/run/postgresql&sslmode=disable): dial tcp: lookup benchmark_main on 127.0.0.53:53: server misbehaving" source="postgres_exporter.go:1474"
Feb 5 13:41:27 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:27+03:00" level=info msg="Established new database connection to \"carrot_shard_1:5432\"." source="postgres_exporter.go:878"
Feb 5 13:41:28 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:28+03:00" level=info msg="Established new database connection to \"carrot_shard_1:5432\"." source="postgres_exporter.go:878"
Feb 5 13:41:30 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:30+03:00" level=info msg="Established new database connection to \"carrot_shard_1:5432\"." source="postgres_exporter.go:878"
Feb 5 13:41:33 ru-db-pg-shard-data-01 postgres_exporter[2452741]: time="2021-02-05T13:41:33+03:00" level=error msg="Error opening connection to database (postgresql://postgres:PASSWORD_REMOVED@carrot_shard_1?host=/var/run/postgresql&sslmode=disable): dial tcp: lookup carrot_shard_1 on 127.0.0.53:53: server misbehaving" source="postgres_exporter.go:1474"
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in postgres_exporter.go around the auto-discovery connection error at line 1474 and the connection setup around lines 878 and 1405. Reproduce auto-discovery with a Unix socket DSN, then trace how each discovered database is added to the DSN. Done means discovered databases preserve the socket host and connect without treating the database name as a hostname.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100