Trouble Adding InfluxDB 2.0 as DataSource

I’m having (more or less) the same problem. I’ve installed Grafana and Influx in a kubernetes cluster in the same namespace via helm charts

Grafana

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

grafana-values.yaml

persistence:
  enabled: true
  storageClassName: grafana
  extraVolumeMounts:
    - name: plugins
      mountPath: /var/lib/grafana/plugins
      subPath: configs/grafana/plugins
      existingClaim: grafana-extra
      readOnly: false
    - name: dashboards
      mountPath: /var/lib/grafana/dashboards
      subPath: configs/grafana/dashboards
      existingClaim: grafana-extra
      readOnly: false

install command

helm upgrade --install grafana grafana/grafana --namespace monitoring --values grafana-values.yaml

Influx

helm repo add influxdata https://helm.influxdata.com/
helm repo update

influx-values.yaml

persistence:
  storageClass: "influx"

service:
  port: 8086

install command

helm upgrade --install influx --namespace monitoring influxdata/influxdb2 --values influx-values.yaml

Configure Datasource

I’ve exported the admin token by using this command:

kubectl get secret influx-influxdb2-auth -o "jsonpath={.data['admin-token']}" --namespace monitoring | base64 --decode ; echo

The Grafana instance logs this error

t=2021-05-16T12:11:52+0000 lvl=warn msg="Flux query failed" logger=tsdb.influx_flux err="unauthorized: unauthorized access" query=buckets()
t=2021-05-16T12:11:52+0000 lvl=info msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=POST path=/api/ds/query status=400 remote_addr=10.42.0.1 time_ms=45 size=798 referer=https://grafana.sample.domain/datasources/edit/4/

While Influx logs this:

ts=2021-05-16T12:11:52.982455Z lvl=info msg=Unauthorized log_id=0U2QEkrl000 error="authorization not found"

I’ve checked it by an php app using “influxdata/influxdb-client-php” to connect to the influx instance using the same credentials:

object(InfluxDB2\Model\HealthCheck)#33 (1) {
  ["container":protected]=>
  array(6) {
    ["name"]=>
    string(8) "influxdb"
    ["message"]=>
    string(28) "ready for queries and writes"
    ["checks"]=>
    array(0) {
    }
    ["status"]=>
    string(4) "pass"
    ["version"]=>
    string(5) "2.0.6"
    ["commit"]=>
    string(10) "4db98b4c9a"
  }
}

So i’m out of ideas what’s wrong.

After several attempts, and investigating the request that the grafana sends, I saw that in the standard authentication model he was giving a bad request and receiving a timeout.

So putting together some tips from this thread, it worked that way.

Query Language: Flux

URL : http://localhost:8086/
Access : Server (Default)

Do not select any Auth items

Custom HTTP Headers:

Authorization : Token + (Token) “obtained on date> Tokens> token”

InfluxDB Details

Organization : (organizationId)
Token : (Token) “obtained on date> Tokens> token”
Default Bucket : your default bucket
min Time: Default
max time: Default

1 Like

Dear,

I followed the config as described by you, but still get “Error reading InfluxDB”
Regarding the token, is it Token"+"Obtained tocken or TokenObtained tocken?
Thanks for your support.

I now debugged the requests coming from Grafana and my PHP application (some self-promotion: my request-handler helped a lot).
After I made sure that both requests are almost the same (by the way, the authorization is Token ${Token} - with a space), the request also failed in the PHP application with the message unauthorized. So the /health request does not require authentication (good to know), but the request api/v2/query does.
Now yes, there had to be a reason why the token from Kubernetes didn’t work and I found it. I took a look at /var/lib/influxdbv2/influxd.bolt which contains the admin token in plain text and it is different from the token in the Helm deployment. Probably I had not cleared the persistent storage after the first test deployment, so there was an old password/token. So I deleted the deployment and storage (since they were empty anyway) and set it up with a fixed, non-generated password and token. It worked immediately.

1 Like

Hi,

I’m sorry, I didn’t understand the part with HTTP Headers.
On my GUI I have “Header” and “value”.

(my English isn’t perfect, please excuse me)

Hello Nomade, I’m sorry for answering so late

You need to put the header exactly like this
Parameter is Authorization : Write the word Token + your token you get from your settings

1 Like

Hi Igki, that’s exactly that, in header you fill in the authorization parameter and in the value Token + yourToken.

1 Like

Okay i found two solution. First one this:
https://localhost:3000/t/trouble-adding-influxdb-2-0-as-datasource/36490/12?u=lgki

You can use it if you keep using InfluxQL

If you want to use Flux here is my configuration

Query Language: Flux
URL: http://localhost:8086
Acces: Server (default)
Whitelisted coockies: (don't touch)

Auth
(don't touch)

Custom HTTP Headers
Header: Authorization
Value: Token aaabbbcccc
(the aaabbbccc is the token you find in Data > Tokens admin's Token, I think it is possible to create another member to secure the acces)

Organization: the_name OR the_id (it doesn't really matter)
Token: (same token who was given in value without the word Token in front)
Default Bucket doesn't matter

If you want to find you the error you have. Press F12 check console.
Normally you will have something like

Failed to load ressource:... 400 (Bad Request)
Influx error > {data ...}

you can clic on data, then error to see the error reason that influxdb is returning you.

Then, to find out which value is wrong you can use influx CLI:

I use it to try and find out my mistake.

Good luck and have a nice day !
(sorry for the english mistakes)

3 Likes

Hi bbortolato, I have tried it but still getting this error message “Error reading InfluxDB”, I have even created a full access read/write token, but still not working. From Influxdb2 docker side I have following error message: ts=2021-06-09T16:55:56.005205Z lvl=error msg=“Unable to gather” log_id=0UaAcyRl000 error="Get “http://10.0.1.2:8086/metrics”: dial tcp 10.0.1.2:8086: i/o timeout. Can it be linked to the fact that my docker is running on synology nas? Br.

I tried it without the Header and it also work!

For anyone else running into this issue:

Be sure your InfluxData Token has READ permissions. By default, InfluxData generates tokens for Telegraf with WRITE permissions only. Reading your InfluxDB from Grafana Cloud requires READ permissions of course.

1 Like

Still the same error, tried every single offered solution…


if one use influxdb cloud 2.x, you have to enter your choosen Cluster URL (for example: us-central1-1) from influxdb in the HTTP URL =)