Hi,
I wonder if I can ask for help as I’m trying to use Grafana Data Proxy to make some authenticated calls, but failing miserable to do so.
I can provide the whole source code, but generally, I’m following a new Grafana 7 data source tutorial.
I’ve created a new plugin using:
npx @grafana/toolkit plugin:create my-plugin
My plugin.json:
...
"routes": [
{
"path": "testdatasourcecall",
"method": "GET",
"url": "https://jsonplaceholder.typicode.com"
}
],
...
My intention is to call https://jsonplaceholder.typicode.com/todos/1
just to confirm that it’s working.
In my DataSource.ts
:
import { getBackendSrv } from '@grafana/runtime';
export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
// ...
async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
// ...
const res = await getBackendSrv().datasourceRequest({
url: "testdatasourcecall/todos/1",
method: "GET",
});
console.log(res)
}
// ...
}
Now what I’m getting is HTLM response with:
config:
headers: {X-Grafana-Org-Id: 1}
method: "GET"
retry: 0
url: "testdatasourcecall/todos/1"
__proto__: Object
data: {HTLM BODY, pasted below}
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
url: "http://grafana.staged-by-discourse.com/testdatasourcecall/todos/1"
Data:
<div class="preloader__text preloader__text--fail">
<p>
<strong>If you're seeing this Grafana has failed to load its application files</strong>
<br />
<br />
</p>
<p>
1. This could be caused by your reverse proxy settings.<br /><br />
2. If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath<br />
<br />
3. If you have a local dev build make sure you build frontend using: yarn start, yarn start:hot, or yarn
build<br />
<br />
4. Sometimes restarting grafana-server can help<br />
</p>
</div>
I’m running grafana locally:
docker run -d -p 3000:3000 -e GF_DATAPROXY_LOGGING=true -e GF_LOG_LEVEL=debug -v C:\DevOps\grafana\grafana-plugins:/var/lib/grafana/plugins --name=grafana grafana/grafana:7.0.2
I’ve been trying to read source code for SDK and grafana, but can’t figure out what’s wrong.
My questions:
- does this feature work locally? maybe I need to set some additional config?
- am I using the code correctly?
- is there any way to debug this issue better? I’ve tried GF_DATAPROXY_LOGGING but I can’t see any useful logs to be honest…
I’ll really appreciate some help, can provide more code if needed. If you have some working examples I’d be also grateful! Thanks