Grafana datasource proxy request not working

Hey everyone,
we are having the following problem:

We are trying to proxy a datasource request through grafana backend as described in
Add authentication for data source plugins | Grafana documentation . But unfortunately calling

const routePath = '/example';

getBackendSrv()
  .datasourceRequest({
    url: this.url + routePath + '/foo/bar',
    method: 'GET',
  });

does not make a request to https://api.example.com/foo/bar but to
api/datasources/proxy/7/example/foo/bar, which obviously creates a 502 error, since this is not a valid URL

From our understanding the routePath = “example” command should read the route “example” defined in plugin.json but that does not work.
Plugin.json:
image

t=2021-08-23T14:10:50+0000 lvl=info msg="Proxying incoming request" logger=data-proxy-log userid=2 orgid=1 username=XX.YY@domain.com datasource= en-auth uri=/grafana/api/datasources/proxy/7/example/foo/bar method=GET body=
According to the upper grafana logs, the request is proxied to the backend, so i think we are missing some configuration that fetches the correct route from plugin.json to proxy the request.
Unfortunately the grafana documentation does not give more information on this.

Does anyone have an idea how to proceed here?

Thanks in advance :wink:

1 Like

When you use a proxy route, it means that the request to https://api.example.com will be made from the Grafana server rather than from your browser.

The server then automatically creates a route that looks something like /grafana/api/datasources/proxy/7/. The browser can then make the request to the proxy endpoint which then is translated to the actual request on the server.

The Grafana proxy returns a 502 when it can’t access the proxied URL.

In your example, /grafana/api/datasources/proxy/7/example/foo/bar should be replaced with https://api.example.com/foo/bar.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.