I’m trying to write a custom datasource plugin for Grafana that would request Azure AD authentication tokens and send them along with the queries to my database which will accept the token and return the response to the query.
I’ve noticed that the Azure Monitor Plugin for Grafana does the same by asking the user to enter their client id, client secret and tenant id and using it via the routes{} part of their plugin.json file.
I have followed this method but I get a 502 bad gateway error.
My files are hosted here
The essential part of my datasource.js that makes the HTTP call is
query(options) {
const csl = document.getElementById("csl").value;
var queries = _.filter(options.targets, item => {
return item.hide !== true;
}).map(item => {
return {
refId: item.refId,
intervalMs: options.intervalMs,
maxDataPoints: options.maxDataPoints,
format: item.format,
};
});
if (queries.length <= 0) {
return this.$q.when({data: []});
}
return this.backendSrv.datasourceRequest({
url: `api/datasources/proxy/${this.id}/kusto/query`,
method: 'POST',
headers: this.headers,
data: {
db: this.database,
csl: csl,
from: options.range.from,
to: options.range.to,
queries: queries,
}
});
}
Where kusto is the routes path defined in my plugin.json.
What is causing this error? Is there a mistake in my datasource.js or my plugin.json? Is the error happening client side or server side?