Skip to content

Explore: Loki in live mode is not working since 6.6.0 #22905

@danieldabate

Description

@danieldabate

What happened:
Beginning from Grafana 6.6.0 we started seeing this issue where activating Loki in live mode explodes with a generic parsing error.

An unexpected error happened Details TypeError: Cannot read property 'slice' of null

Tracing the issue we found that Loki is throwing this message:
msg="Error in upgrading websocket" err="websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header"

What you expected to happen:
Grafana working correctly with Loki in live mode

How to reproduce it (as minimally and precisely as possible):
There's no particular way to reproduce the issue. Just using the Live mode for Loki with Grafana v6.6.0 or later.

Anything else we need to know?:
We are stuck in version 6.5.3 and have not found anything in our configuration that could fix this issue. We have an nginx correctly setup between Grafana and Loki and it has been working great until now.

Any help would be very appreciated.

Environment:

  • Grafana version: 6.6.0 - 6.7.0
  • Data source type & version: Loki 1.2.0
  • OS Grafana is installed on: K8S
  • User OS & Browser: Mac in all browsers
  • Grafana plugins: None
  • Others: None

Activity

aknuds1

aknuds1 commented on Mar 19, 2020

@aknuds1
Contributor

Do you mind rewriting the issue to abide by our standard issue template?

danieldabate

danieldabate commented on Mar 19, 2020

@danieldabate
Author

I used the issue template, I just deleted some of the parts that I don't think that apply to this issue. But I will add them. Thanks for the help.

quanterion

quanterion commented on Mar 24, 2020

@quanterion

Have the same error with Grafana 6.7.1 and Loki 1.3
Call stack is:

react-dom.production.min.js:196 TypeError: Cannot read property 'slice' of null
at t.n.rowsToRender (LiveLogs.tsx:132)
at t.value (LiveLogs.tsx:151)
at Ka (react-dom.production.min.js:181)
at Xa (react-dom.production.min.js:180)
at Ou (react-dom.production.min.js:261)
at vs (react-dom.production.min.js:230)
at ps (react-dom.production.min.js:229)
at os (react-dom.production.min.js:223)
at react-dom.production.min.js:121
at e.unstable_runWithPriority (scheduler.production.min.js:18)

cordula-grau

cordula-grau commented on Mar 25, 2020

@cordula-grau

Same issue here, grafana 6.7.1 and loki 1.3, logcli is running fine in tail mode

noahrotheray

noahrotheray commented on Mar 26, 2020

@noahrotheray

Same issue:
Grafana 6.6.2
Loki 1.3

jongyllen

jongyllen commented on Apr 3, 2020

@jongyllen
Contributor

Hi, when I try this with Grafana 6.7.2 the live logs for Loki works for me. Has this been resolved maybe?

danieldabate

danieldabate commented on Apr 3, 2020

@danieldabate
Author

I just tested 6.7.2 but the issue is still happening. From what I know it does not happen to everyone.

torkelo

torkelo commented on Apr 3, 2020

@torkelo
Contributor

Maybe you need to update Loki? What version of Loki are you using? Also try latest version of Grafana

torkelo

torkelo commented on Apr 3, 2020

@torkelo
Contributor

Maybe you have proxy in front of Grafana that does not support websockets?

danieldabate

danieldabate commented on Apr 3, 2020

@danieldabate
Author

Tried latest version of Grafana and Loki with no success.

I do have a proxy in front of Grafana and also a proxy between Grafana and Loki, but this setup is working great with Grafana 6.5.3, so proxies are not the problem. It breaks from Grafana 6.6.0. Maybe some change was introduced in that version that is not compatible with our setup.

Do you recall any changes introduced in this version that could be the source of the problem? Maybe endpoint changes or any other change? Not saying a bug, but maybe just a breaking change that we should be aware of.

danieldabate

danieldabate commented on Apr 3, 2020

@danieldabate
Author

I found the issue!! It was an endpoint change like I said in the previous message.

Now Grafana is requesting this Loki's endpoint:
/loki/api/v1/tail
instead of the older:
/api/prom/tail

So any setup in the proxies related to the older version, like a proxy_set_header Upgrade, would not be applied from Grafana 6.6.0

ivanahuckova

ivanahuckova commented on Apr 23, 2020

@ivanahuckova
Contributor

Hello @danieldabate! I am glad that you were able to solve the problem. 🚀 I am going to close this issue as in the next release we are are going to stop supporting legacy Loki endpoints (before v1). As it is a breaking change, it is going to be communicated in the release notes.

1 remaining item

chusiang

chusiang commented on Apr 28, 2020

@chusiang

Thanks @danieldabate, you saved my some time.

7olstoy

7olstoy commented on May 8, 2020

@7olstoy

@ivanahuckova 7.0.0-beta3 still this issue

nginx-proxy
loki 1.4.1

s5unty

s5unty commented on May 9, 2020

@s5unty

Live mode requires websocket.
If nginx is used, websocket support is required
https://www.nginx.com/blog/websocket-nginx/

7olstoy

7olstoy commented on May 9, 2020

@7olstoy

@s5unty
Thank you, your link helped

jslay88

jslay88 commented on May 14, 2020

@jslay88

Just to help those coming here from a fresh Grafana and Loki deployment via Helm, when you add Loki to your Data Sources, check your logs on the loki pod and you will likely see errors about the Connection or Upgrade headers. You need to add two custom headers in the config for the Loki Data Source in Grafana.

  • Connection: Upgrade
  • Upgrade: websocket
Binyamse

Binyamse commented on Oct 20, 2020

@Binyamse

I am having this issue no proxy in the middle (between grafan and loki) added the two custom headers the issue persists.

saikatharryc

saikatharryc commented on Apr 20, 2021

@saikatharryc

I'm using ambassador Mappings, doing this worked for me, which means. for those not working, try allowing WebSocket connection upgrade. to their controllers/servers.

gurre

gurre commented on Jan 19, 2022

@gurre

Custom headers didn't solve it for me but here is the config:

datasources:
  - name: Loki
    type: loki
    url: "http://loki.local:3100"
    access: proxy
    version: 1
    org_id: 1
    isDefault: false
    jsonData:
      timeInterval: 15s
      httpHeaderName1: Connection
      httpHeaderName2: Upgrade
    secureJsonData:
      httpHeaderValue1: Upgrade
      httpHeaderValue2: websocket

I'm getting parse error : syntax error: unexpected $end from GET /api/datasources/proxy/95/loki/api/v1/query_range and WebSocketSubject.js:96 WebSocket connection to 'wss://loki.local/api/datasources/proxy/95/loki/api/v1/tail?query=%7Bjob%3D%22systemd-journal%22%7D' failed:

oleksii-boiko-ua

oleksii-boiko-ua commented on Jun 9, 2023

@oleksii-boiko-ua

we are having exact same issues when X-Scope-OrgID header contains more than 1 tenant id.
Grafana v9.5.3
Loki v2.8.2

jslay88

jslay88 commented on Jun 29, 2023

@jslay88

Custom headers didn't solve it for me but here is the config:

datasources:
  - name: Loki
    type: loki
    url: "http://loki.local:3100"
    access: proxy
    version: 1
    org_id: 1
    isDefault: false
    jsonData:
      timeInterval: 15s
      httpHeaderName1: Connection
      httpHeaderName2: Upgrade
    secureJsonData:
      httpHeaderValue1: Upgrade
      httpHeaderValue2: websocket

I'm getting parse error : syntax error: unexpected $end from GET /api/datasources/proxy/95/loki/api/v1/query_range and WebSocketSubject.js:96 WebSocket connection to 'wss://loki.local/api/datasources/proxy/95/loki/api/v1/tail?query=%7Bjob%3D%22systemd-journal%22%7D' failed:

This is a completely different error than what the custom headers are supposed to solve.

Custom headers only solve the issue when the error states that it is a Connection or Upgrade header issue.

Jeremy-Boyle

Jeremy-Boyle commented on Jul 20, 2023

@Jeremy-Boyle

I was able to fix this by enabling WebSocket on the Grafana side along with the following

httpHeaderName1: Connection
httpHeaderName2: Upgrade
httpHeaderValue1: Upgrade
httpHeaderValue2: websocket

For what its worth, my grafana instance is behind HTTPProxy with Contour.

Here's for nginx (https://www.civo.com/learn/using-websockets-with-ingress-controller)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: web-socket
 annotations:
  kubernetes.io/ingress.class: nginx
  nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
  nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
  nginx.ingress.kubernetes.io/server-snippets: |
   location / {
    proxy_set_header Upgrade $http_upgrade;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header Connection "upgrade";
    proxy_cache_bypass $http_upgrade;
    }
...

My HTTPProxy is as follows.

apiVersion: projectcontour.io/v1
kind: HTTPProxy
metadata:
  name: grafana
  namespace: grafana
spec:
  virtualhost:
    fqdn: private.com
    tls:
      secretName: cert-tls
  routes:
  - services:
    - name: grafana-operator-grafana-service
      port: 3000
    enableWebsockets: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/exploredatasource/Lokineeds investigationfor unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @torkelo@s5unty@chusiang@aknuds1@jongyllen

        Issue actions

          Explore: Loki in live mode is not working since 6.6.0 · Issue #22905 · grafana/grafana