I am in the process of developing a Grafana datasource plugin that operates independently without relying on an external backend.
My plugin is based on the simple-json datasource plugin available at: https://github.com/grafana/simple-json-datasource
In attempting to modify the query function in the datasource.js file, I encountered the following differences:
The original code snippet:
query(options) {
var query = this.buildQueryParameters(options);
if (query.targets.length <= 0) {
return this.q.when([]);
}
return this.backendSrv.datasourceRequest({
url: this.url + '/query',
data: query,
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
My revised query function:
query(options) {
return [
{
"target":"upper_75",
"datapoints":[
[622,1450754160000],
[365,1450754220000]
]
},
{
"target":"upper_90",
"datapoints":[
[861,1450754160000],
[767,1450754220000]
]
}
];
}
Upon implementing my custom query function and trying to visualize the graph in the Grafana panel, I encountered the following error message:
"undefined is not an object (evaluating 'dataList.map')"
Despite experimenting with different data formats, it appears that Grafana expects a specific format as return value, which remains elusive to me.
I have closely studied the output of the original implementation and attempted to replicate it, but without success.
I suspect that
this.backendSrv.datasourceRequest({
url: this.url + '/query',
data: query,
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
is meant to provide a formatted HTTP response, leaving me wondering why I cannot manually return it.
Any assistance would be greatly appreciated. Thank you!