prometheus-community / prometheus-community/postgres_exporter

multi target DATA_SOURCE_NAME has issues on a port != 5432

Open
#609 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
3.6k
Forks
835
Avg merge
2d 4h
Merged PRs (30d)
10

Description

I consistently have problems using DATA_SOURCE_NAME with more than one URI if the ports are not standard.

I understand from this sentences:

Also, you can set a list of sources to scrape different instances from the one exporter setup. Just define a comma separated string.

sudo -u postgres DATA_SOURCE_NAME="port=5432,port=6432" postgres_exporter

What I did is to set this variable:

DATA_SOURCE_NAME="postgresql://postgres:xxx@10.1.201.11:5434/postgres?sslmode=disable,postgresql://postgres:xxx@10.1.201.11:5432/postgres?sslmode=disable"

just for readability I'll write it this way:

DB1=10.1.201.11:5434
DB2=10.1.201.11:5432
OPTS=postgres?sslmode=disable
DATA_SOURCE_NAME="postgresql://postgres:xxx@$DB1$OPTS,postgresql://postgres:xxx@$DB1$OPTS"

What did you do?

I tested each database alone, and it worked.

As long as DB1 and DB2 use port 5432 the exporter works and I get rows for each target (clearly on different servers). If I use other ports (5434, 5435...) I get an error:

# wget -O - localhost:9187/metrics
--2022-01-26 23:47:17--  http://localhost:9187/metrics
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:9187... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2022-01-26 23:47:17 ERROR 500: Internal Server Error.

What did you expect to see?
I expect it to work correctly on any port...

Environment

I did the tests with PostgreSQL 14 on Ubuntu 20.04 using binary 0.10.0

# uname -srm
Linux 5.4.0-80-generic x86_64

# postgres_exporter --version
postgres_exporter, version 0.10.0 (branch: HEAD, revision: 57719ba53cac428769aaf3c4c0bb742df3cfca98)
  build user:       root@4dcb2c7f1315
  build date:       20210709-11:49:20
  go version:       go1.16.5
  platform:         linux/amd64
  • postgres_exporter flags:
not using any flags

I initially verified the same behaviour working in kubernetes.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue in postgres_exporter with DATA_SOURCE_NAME containing multiple PostgreSQL URIs that use both standard and nonstandard ports, then request localhost:9187/metrics. Trace the multi-target parsing and connection path to identify why nonstandard ports produce HTTP 500; done means metrics work for every configured port.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases, observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.