Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prometheus-postgres-exporter] Error while connecting - pq: Could not detect default username #4486

Closed
lui3533 opened this issue Apr 24, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@lui3533
Copy link

lui3533 commented Apr 24, 2024

Describe the bug a clear and concise description of what the bug is.

Hi,

we are trying to set up the postgres-exporter for the first time and are facing the following issue

The pod is spinning up and starts correctly but the logs show the following error messages

│ ts=2024-04-24T11:35:35.638Z caller=proc.go:267 msg="Excluded databases" databases=[] │
│ ts=2024-04-24T11:35:35.643Z caller=tls_config.go:274 level=info msg="Listening on" address=:9187 │
│ ts=2024-04-24T11:35:35.643Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=:9187 │
│ ts=2024-04-24T11:35:52.398Z caller=server.go:74 level=info msg="Established new database connection" fingerprint=<XXXXXXXXXXXdb-connection-stringXXXXXXXXXXX>:5432│
│ ts=2024-04-24T11:35:55.754Z caller=probe.go:41 level=info msg="no auth_module specified, using default"│
│ ts=2024-04-24T11:35:55.754Z caller=server.go:74 level=info msg="Established new database connection" fingerprint=*:5432│
│ ts=2024-04-24T11:35:55.755Z caller=probe.go:81 level=error target=* msg="Error opening connection to database" err="error querying postgresql version: pq: Could not detect default username. Please provide one explicitly" │
│ ts=2024-04-24T11:35:56.755Z caller=postgres_exporter.go:682 level=error err="Error opening connection to database (postgresql://*): pq: Could not detect default username. Please provide one explicitly"

What's your helm version?

v3.14.3

What's your kubectl version?

v1.29.2

Which chart?

prometheus-postgres-exporter

What's the chart version?

6.0.0

What happened?

So the exporter is trying to establish a new connection to the postgres database. Now we are unsure about to aspects in the logs.

  1. no auth_module specified, using default - do we need the auth_module for one single db connection?
  2. Error opening connection to database (postgresql://*): pq: Could not detect default username. Please provide one explicitly

We connected to the pod and checked if the env variables DATA_SOURCE_URI, DATA_SOURCE_USER, DATA_SOURCE_PASS do contain the correct values - and they do. So from our point of view the connection should be possible.

What you expected to happen?

The connection to the postgres can be established with the provided data.

How to reproduce it?

use the datasourceSecret option and provide a single connectionstring (in format postgresql://login:password@hostname:port/dbname?sslmode=disable) as a secret

Enter the changed values of values.yaml?

config:
  ## The datasource properties on config are passed through helm tpl function.
  ## ref: https://helm.sh/docs/developing_charts/#using-the-tpl-function
  datasourceSecret:
    # Specifies if datasource should be sourced from secret value in format: postgresql://login:password@hostname:port/dbname?sslmode=disable
    # Multiple Postgres databases can be configured by comma separated postgres connection strings
    # Secret name
      name: postgres-secret
    # Connection string key inside secret
      key: connectionstring

  # possible values debug, info, warn, error, fatal
  logLevel: "debug"

Enter the command that you execute and failing/misfunctioning.

helm upgrade -i postgres-exporter prometheus-community/prometheus-postgres-exporter -f values.yaml

Anything else we need to know?

No response

@lui3533 lui3533 added the bug Something isn't working label Apr 24, 2024
@lui3533
Copy link
Author

lui3533 commented May 2, 2024

Hi, any updates on this one?

@zeritti
Copy link
Member

zeritti commented May 5, 2024

no auth_module specified, using default - do we need the auth_module for one single db connection?

No, you do not need an auth module.

Error opening connection to database (postgresql://*): pq: Could not detect default username. Please provide one explicitly

Any special characters in your password? The error can occur if using a password with special characters e.g. : / ? * @ = (see RFC 3986 reserved characters in URIs). If these are present in your password, they are probably causing the error.

Another means of specifying a connection string is with key-value pairs (ref. pq). Instead of using a connection URI

'postgresql://login:password@hostname:port/dbname?sslmode=disable'

you can set

user=login password=password host=hostname port=5432 dbname=dbname sslmode=disable

in your datasource secret.

@lui3533
Copy link
Author

lui3533 commented May 8, 2024

Hi,

thanks for your help!

We checked the PW for any special characters and we noticed that it contains "-" Characters. But no other special characters. Like "ab1-cd2-de4"

We already used the option to set the user, password and host in the key-value pairs. This leads to the same issue.

Are there any tips for debugging this issue?

Thanks in advance!

@lui3533
Copy link
Author

lui3533 commented May 8, 2024

Issue is related to other restrictions.Thank you for your help.

@lui3533 lui3533 closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants