Datasource won't work within the UI

  • What Grafana version and what operating system are you using?
    app.kubernetes<.io>/instance: kube-prometheus-stack
    app.kubernetes<.io>/managed-by: Helm
    app.kubernetes<.io>/name: grafana
    app.kubernetes<.io>/version: 10.4.0

(The angle brackets have been added only to disable the url detection)

  • What are you trying to achieve?

I would like to get my datasource, configured via yaml file, in a working state

  • How are you trying to achieve it?
    I configured a yaml file with the needed data like this:
---
apiVersion: 1
datasources:
  - name: grafana-postgresql-datasource
    type: postgres
    access: proxy
    orgId: 1
    uid: grafana-postgresql-datasource
    url: <ipaddress>:5432
    user: the_user
    secureJsonData:
      password: 'password'
    jsonData:
      database: <databasename>
      sslmode: disable # disable/require/verify-ca/verify-full
      maxOpenConns: 100 # Grafana v5.4+
      maxIdleConns: 100 # Grafana v5.4+
      maxIdleConnsAuto: true # Grafana v9.5.1+
      connMaxLifetime: 14400 # Grafana v5.4+
      postgresVersion: 1000 # 903=9.3, 904=9.4, 905=9.5, 906=9.6, 1000=10
      timescaledb: false
    version: 2
    editable: false

Within my Grafana pod I found the datasource as file configured under the path /etc/grafana/provisioning/datasources

  • What happened?
    Within the UI I click the button test at the end of my configured datasource. But I got the error the the password is wrong.

  • What did you expect to happen?

I expect that the configured datasource is working as expected because if I create a new datasource manually within the UI with the same data from the datasource file within the Grafana pod I got a connection and also the data for my dashboards.

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
logger=context userId=1 orgId=1 uname=admin t=2024-07-22T12:30:41.459917016Z level=error msg="Internal server error" error="[plugin.healthCheck] client: failed to check health: invalid port in host specifier \"//172.20.1.45:5432\": strconv.Atoi: parsing \"//172.20.1.45:5432\": invalid syntax" remote_addr=172.18.98.84 traceID=
logger=context userId=1 orgId=1 uname=admin t=2024-07-22T12:30:41.459964596Z level=error msg="Request Completed" method=GET path=/api/datasources/uid/grafana-postgresql-datasource/health status=500 remote_addr=172.18.98.84 time_ms=3 duration=3.029609ms size=103 referer=https://<fqdn>/grafana/connections/datasources/edit/grafana-postgresql-datasource handler=/api/datasources/uid/:uid/health status_source=downstream

The logs are from the pod. You can get it via the command:
kubectl logs <podname> -n <namespace>

  • Did you follow any online instructions? If so, what is the URL?

yes: PostgreSQL data source | Grafana documentation

Do anyone know how to decrypt the password from the internal SQlite database to see what is handed over from the config file into the database?

is it encrypted? I think it is plain text in the grafana ini file

It’s symmetric AES encryption by default, but it can be more complicated:

Yes within the internal database the password is encrypted.
Within grafana.ini is nothing to find that looks like my password.

Did anyone of you @yosiasz or @jangaraj knows or understand why the different datasources (configfile and manual) react so different related to the password?

Let me guess: because

  • ' is part of actual provisioned password
  • because password contains special characters, which need to be escaped properly

Use:

I have only this special char in the password ‘$’ all the rest are only numbers and letters.
Within this link you provided me is only written from this two special chars: ‘# and ;’ right?
Or should I remove also this single quotes around the password within the yaml config file?

Here you are:

If you have a literal $ in your value and want to avoid interpolation, $$ can be used.

Doc is your friend.

This little sentence I had overlooked … thx for the hint …

Summary now it is working as expected!!!

1 Like