Backend-plugin resource handler strips out connection headers

Following this showcase How to add a resource handler for your data source - #3 by mefraimsson and App with backend plugin example grafana-plugin-examples/examples/app-with-backend at main · grafana/grafana-plugin-examples · GitHub
I encountered a problem with CallResource function receiving request object with stripped out Connection: ‘upgrade’ headers. And if I add these headers manually in the handler function it throws error that theres no http.hijacker.

I want to run my own simple webrtc signaling websocket server at one of the resource handlers urls, for example at /api/plugins/my-app/resources/ws .
I do succeed running separate goroutine with http.ListenAndServe at custom port with my websocket handler, but I guess it would better to use api resource handler for my app plugin.

Could someone please point me to a Grafana sourcecode where and why it strips connection headers for resource handlers and advice if it is technically possible to open custom websocket connections (other than grafana live) for my app plugin resource handlers?

I’m not sure you can use call resource to proxy a websocket connection/not supported due to not supported here grafana/pkg/plugins/manager/client/client.go at a103be2285710f8c1c2dac470595336f816da9ff · grafana/grafana · GitHub. Not sure we want to support it either given that there are multiple alternatives.

What you can do if you don’t want to use Grafana live streaming, is to use the datasource proxy. Then you’ll need to convert proxy url to ws:// scheme, examples

Then you can use that url to connect to websocket over Grafana’s datasource proxy.

We’re planning to improve documentation around this Docs: Document how to connect over websocket thru datasource proxy · Issue #46798 · grafana/grafana · GitHub

1 Like

Thanks a lot! Was hoping for your response on that

1 Like