grafana icon indicating copy to clipboard operation
grafana copied to clipboard

Connection to InfluxDB 2.1.1 with Flux

Open Teuse opened this issue 3 years ago • 7 comments

Hi,

I'm trying to add InfluxDB using Flux as a datasource to Grafana. Unfortunately, I'm not able to get a connection. It works perfectly with InfluxQL, though. Grafana, InfluxDB and Telegraf is running in Docker containers... all containers are started with docker-compose (link below).

Grafana Version: v8.3.6 (no plugins) InfluxDB Version: 2.1.1 OS: MacOS 12.2 Browsers: Safai/Chrome

Datasource Config: https://github.com/Teuse/rpi-monitoring/blob/main/etc/grafana-provisioning/datasources/datasource.yml Docker-Compose: https://github.com/Teuse/rpi-monitoring/blob/main/docker-compose.yml

I googled quite. I found some suggestions with custom headers... nothing worked:

  1. Authorization: Token
  2. token: Token
  3. token:

How to reproduce it (as minimally and precisely as possible):

  1. To reproduce, start InfluxDB 2.1.1 and Grafana v8.3.6 with the mentioned datasource config.
  2. In Grafana go to the datasource Settings and click "Test". -> See "InfluxDB Error: Bad Request"

The logs in InfluxDB and Grafana are:

rpi-monitoring-influxdb-1  | ts=2022-02-13T10:01:29.763989Z lvl=info msg=Unauthorized log_id=0Zdc8CkW000 error="token required"

rpi-monitoring-grafana-1   | t=2022-02-13T10:01:29+0000 lvl=warn msg="Flux query failed" logger=tsdb.influx_flux err="unauthorized: unauthorized access" query=buckets()

rpi-monitoring-grafana-1   | t=2022-02-13T10:01:29+0000 lvl=info msg="Request Completed" logger=context userId=1 orgId=1 uname=teuse method=POST path=/api/ds/query status=400 remote_addr=192.168.144.1 time_ms=62 size=182 referer=http://localhost:3000/datasources/edit/P5697886F9CA74929

Teuse avatar Feb 13 '22 10:02 Teuse

I see the same thing. Looking at the wire it seems the Authorization header is missing. Even when adding it manually it is stil missing:

Internet Protocol Version 6, Src: ::1, Dst: ::1
Transmission Control Protocol, Src Port: 36514, Dst Port: 8086, Seq: 1, Ack: 1, Len: 317
Hypertext Transfer Protocol
    POST /api/v2/query?org=private HTTP/1.1\r\n
        [Expert Info (Chat/Sequence): POST /api/v2/query?org=private HTTP/1.1\r\n]
            [POST /api/v2/query?org=private HTTP/1.1\r\n]
            [Severity level: Chat]
            [Group: Sequence]
        Request Method: POST
        Request URI: /api/v2/query?org=private
            Request URI Path: /api/v2/query
            Request URI Query: org=private
                Request URI Query Parameter: org=private
        Request Version: HTTP/1.1
    Host: localhost:8086\r\n
    User-Agent: influxdb-client-go/2.6.0  (linux; amd64)\r\n
    Content-Length: 122\r\n
        [Content length: 122]
    Accept-Encoding: gzip\r\n
    Content-Type: application/json\r\n
    \r\n
    [Full request URI: http://localhost:8086/api/v2/query?org=private]
    [HTTP request 1/1]
    File Data: 122 bytes
JavaScript Object Notation: application/json

aperum avatar Feb 14 '22 21:02 aperum

This has been solved for me with 8.4.0

aperum avatar Feb 18 '22 21:02 aperum

This has been solved for me with 8.4.0

Unfortunately, it's still not working for me... same error: msg="Flux query failed" err="unauthorized: unauthorized access" query=buckets(). I used the docker image grafana/grafana-oss:8.4.0.

Teuse avatar Feb 19 '22 07:02 Teuse

Could be related to issues we had with propagating headers #43812. Probably something similar is needed for influx.

aocenas avatar Mar 10 '22 14:03 aocenas

@Teuse apologies for not getting to this sooner. We're sweeping through unaddressed issues and wondering if you are still encountering this?

evandandrea avatar Aug 31 '22 14:08 evandandrea

Thanks for coming back to this issue. Unfortunately, I don't have time to check if the issue still exists.

Teuse avatar Sep 01 '22 05:09 Teuse

I'm gonna try and see if I can reproduce this locally

gtk-grafana avatar Sep 21 '22 18:09 gtk-grafana

I'm unable to reproduce any issues connecting flux 2.1.1/latest with Grafana 8.4.0/9.x.

gtk-grafana avatar Sep 21 '22 20:09 gtk-grafana

If it is working for you, than I'm might doing something wrong 😑 I was able to look into this issue again... It's still not working. Here is my code: https://github.com/Teuse/blackberry-monitor

  1. Just checkout the repository
  2. Add a .env file in project root with following content
INFLUXDB_USERNAME="whoever"
INFLUXDB_PASSWORD="password"
INFLUXDB_TOKEN="123456"
INFLUXDB_ORG="org0"
INFLUXDB_BUCKET="bucket0"
  1. run docker compose up
  2. Open grafana on localhost:3000 and navigate to settings -> data sources -> InfluxDB_v2_Flux
  3. Setup InfluxDB Details (it's not automatically setup, don't know why... I need to look into it) Organization: org0 Token: 123456 Defalut Bucket: bucket0
  4. -> Test

Expected Result The test should be successful

Actual Result Error unauthorized: unauthorized access error reading buckets

As menthoned above already, I also tried to add some Custom HTTP Headers e.g. Authorization: 123456 without success

Teuse avatar Oct 09 '22 06:10 Teuse

I also have this issue. The difference with my install is using the .deb for RaspberryPiOs. Clean installs everywhere.

Jonesy1080 avatar Jan 06 '23 00:01 Jonesy1080

I also have this issue. The difference with my install is using the .deb for RaspberryPiOs. Clean installs everywhere.

Turns out the "Copy to Clipboard" API key function doesn't work.

Jonesy1080 avatar Jan 11 '23 23:01 Jonesy1080

Turns out the "Copy to Clipboard" API key function doesn't work.

Do you have a workaround to get this working somehow?

Teuse avatar Jan 12 '23 14:01 Teuse

Turns out the "Copy to Clipboard" API key function doesn't work.

Do you have a workaround to get this working somehow?

Crtl + C, Crtl + V.

Jonesy1080 avatar Jan 12 '23 14:01 Jonesy1080

@Jonesy1080 Which "copy to clipboard" functionality are you talking about, is this something in Grafana?

gtk-grafana avatar Jan 12 '23 14:01 gtk-grafana

@Jonesy1080 Which "copy to clipboard" functionality are you talking about, is this something in Grafana?

When setting up a data source in Grafana from InfluxDB2, you need Organization, Token, and Bucket. I wouldn't want to type the Token, so I copy it from InfluxDB2.

In InfluxDB2, you create an API token. Upon creation, it gives you a button, "Copy to Clipboard". I pasted the expected API key into a text editor and it was not the API key.

Jonesy1080 avatar Jan 12 '23 14:01 Jonesy1080

@Jonesy1080 Thank you... what a stupid problem that I have been stuck on for weeks.

Arrgg avatar Jan 16 '23 03:01 Arrgg

Can't reproduce the issue. Copy to Clipboard works for me. Does the connection Grafana -> InfluxDB2 work for you, when you type the API key?

Teuse avatar Jan 16 '23 08:01 Teuse

Can't reproduce the issue. Copy to Clipboard works for me. Does the connection Grafana -> InfluxDB2 work for you, when you type the API key?

It works fine when I use the operating system copy/paste. Working from an iPad if that matters.

Arrgg avatar Jan 16 '23 21:01 Arrgg

Same Problem here. Firefox 110.0.1 on Windows 10. The function "Copy to clipboard" did not copy the API Key to the clipboard, despite the Popup Message on the website. Took me quite a while to figure out.

SevHub avatar Mar 15 '23 09:03 SevHub

Are we talking about the copy to clipboard functionality within the influxDB admin? image

gtk-grafana avatar Mar 15 '23 12:03 gtk-grafana

This one, in InfluxDB, seems to be the problem. It gives a successful toast message but nothing gets copied into the clipboard. image

OskarPersson avatar Mar 30 '23 16:03 OskarPersson

@Jonesy1080 Which "copy to clipboard" functionality are you talking about, is this something in Grafana?

When setting up a data source in Grafana from InfluxDB2, you need Organization, Token, and Bucket. I wouldn't want to type the Token, so I copy it from InfluxDB2.

In InfluxDB2, you create an API token. Upon creation, it gives you a button, "Copy to Clipboard". I pasted the expected API key into a text editor and it was not the API key.

at today still have the same issue

This one, in InfluxDB, seems to be the problem. It gives a successful toast message but nothing gets copied into the clipboard. image

confirmed, I have got the same bad behavior and still not working as today.

AlanCodega avatar May 25 '23 15:05 AlanCodega

Thanks @AlanCodega, this appears to be an issue with influx, and not Grafana. I found a related issue on their github: https://github.com/influxdata/influxdb/issues/24051, please feel free to reach out there.

gtk-grafana avatar May 25 '23 15:05 gtk-grafana