Open baznikin opened 1 year ago
There is a lot of issues about "was collected before with the same name and label values" error and i found a way to reproduce it.
I faced this error after adding the following block to my queries.yaml:
pg_invalid_indexes:
query: "SELECT current_database() datname, count (*) FROM pg_catalog.pg_index i LEFT JOIN pg_catalog.pg_locks l ON (i.indexrelid = l.relation) WHERE NOT (i.indisvalid AND i.indisready) AND l.relation IS NULL"
metrics:
- datname:
usage: "LABEL"
description: "Name of current database"
- count:
usage: "GAUGE"
description: "Count of invalid indexes"
I have 3 databases that is not a template in test environment: postgres, mydb1 and mydb2. When i try to query the exporter i got the following error:
curl -s 'localhost:9187/metrics'|egrep "pg_invalid_indexes_count"
collected metric "pg_invalid_indexes_count" { label:<name:"datname" value:"postgres" > label:<name:"server" value:"127.0.0.1:5432" > gauge:<value:0 > } was collected before with the same name and label values
This query counts invalid indexes in a db and it has to be run in every database, so my exporter is running with --auto-discover-databases flag. I know that this query always returns exacly one row, so there should be no duplicates.
To figure out what's happening i added a random() value, like this:
pg_invalid_indexes:
query: "SELECT random(), current_database() datname, count (*) FROM pg_catalog.pg_index i LEFT JOIN pg_catalog.pg_locks l ON (i.indexrelid = l.relation) WHERE NOT (i.indisvalid AND i.indisready) AND l.relation IS NULL"
metrics:
- random:
usage: "LABEL"
description: "test"
- datname:
usage: "LABEL"
description: "Name of current database"
- count:
usage: "GAUGE"
description: "Count of invalid indexes"
And got this. The output could change after every restart of postgres exporter:
curl -s 'localhost:9187/metrics'|egrep "pg_invalid_indexes_count"
pg_invalid_indexes_count{datname="postgres",random="0.4343765986839898",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="postgres",random="0.8933916408300497",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="postgres",random="0.9730973867622801",server="127.0.0.1:5432"} 0
restarting exporter
curl -s 'localhost:9187/metrics'|egrep "pg_invalid_indexes_count"
pg_invalid_indexes_count{datname="mydb1",random="0.3768252689858862",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="postgres",random="0.09343378715585615",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="postgres",random="0.14668469182350918",server="127.0.0.1:5432"} 0
restarting exporter
curl -s 'localhost:9187/metrics'|egrep "pg_invalid_indexes_count"
pg_invalid_indexes_count{datname="mydb2",random="0.7216720910762717",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="postgres",random="0.3559019246896078",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="postgres",random="0.5074779531582507",server="127.0.0.1:5432"} 0
If i keep restarting the exporter, eventually everything is working fine:
curl -s 'localhost:9187/metrics'|egrep "pg_invalid_indexes_count"
pg_invalid_indexes_count{datname="mydb1",random="0.4005597441722699",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="mydb2",random="0.35699799578830493",server="127.0.0.1:5432"} 0
pg_invalid_indexes_count{datname="postgres",random="0.24877513869852663",server="127.0.0.1:5432"} 0
As you can see, exporter queries same database multiple times. Hope this helps to finally fix this issue. Tested on 0.11.1 and 0.12.0-rc.0
The problem seems to be with the connstring syntax in the DSN, that was added in https://github.com/prometheus-community/postgres_exporter/pull/473.
When i change DSN to URIs (postgresql://user:pass@host/dbname
) everything works just fine.
Connstring that led to accidental duplicate metrics error looks like this:
DATA_SOURCE_NAME=user=usename password=pass database=postgres host=hostfqdn port=5432 sslmode=disable
the issue is that if you add external queries to your yaml file, you have to specify "master: true" to have it executed only once (on one table only)
See https://github.com/prometheus-community/postgres_exporter/issues/786
Copied from prometheus-community/helm-charts
This issue originally was opened here but was unattended. Copied here as is. I experience this issue with postgres_exporter 0.10.1 and latest 0.11.1 as well
Describe the bug a clear and concise description of what the bug is.
With
config.autoDiscoverDatabases: true
I got error 500 on /metrics endpoint:According to https://github.com/prometheus-community/postgres_exporter/issues/429#issuecomment-850865088 I manually added key
master: true
to querypg_stat_activity_idle
and it fixes errorWhat's your helm version?
version.BuildInfo{Version:"v3.7.1", GitCommit:"1d11fcb5d3f3bf00dbe6fe31b8412839a96b3dc4", GitTreeState:"clean", GoVersion:"go1.16.9"}
What's your kubectl version?
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.5", GitCommit:"6b1d87acf3c8253c123756b9e61dac642678305f", GitTreeState:"clean", BuildDate:"2021-03-18T01:10:43Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
Which chart?
prometheus-postgres-exporter
What's the chart version?
3.0.3
What happened?
No response
What you expected to happen?
No response
How to reproduce it?
No response
Enter the changed values of values.yaml?
serviceMonitor: enabled: true config: datasource: host: develop-postgresql user: develop_admin password: passwordSecret: name: develop-admin.develop-postgresql.credentials.postgresql.acid.zalan.do key: password database: 'template1' logLevel: info autoDiscoverDatabases: true
Enter the command that you execute and failing/misfunctioning.
helm install postgres-exporter prometheus-community/prometheus-postgres-exporter --namespace db -f ./postrges_exporter.yaml
Anything else we need to know?
No response