Backend Datasource : Request Object Null

Hi Grafana Developers: I had my datasource plugin partially working, where the backend was receiving the full Request Object with target and PanelId properly populated.
I had some strange issue, so I rebuilt the entire source, now I see the request object is empty - null.
I set a breakpoint in the backend ( index.js ), in the /query implementation, the request object is null.
I rebuilt my front end(based on simple-json ) and cant figure out why the request object now is null. I tried to look at module.js , plugin.json etc.
Also, I had changed my plugin name, but in the grafana-server logs, it still has a record of the old name - how can I clear it up, where is it stored ? I noticed there is sqlite and was wondering if that is where its stored, or is there config file somewhere ? in my data/plugins I checked all files and did not see the old name anywhere.
thanks

Backend data source?

Do you have code to share? Otherwise it’s hard to help with this type of question.

Regarding the name update not taking effect, you need restart grafana-server for plugin.json updates to take effect

Hi Torkel,
sure, here is the code: It is pretty much based on fake server.

I debugged the client browser and noticed the browser is not sending a proper POST, but an OPTIONS and null request object. Is this related to backend_srv keeping track of pending request ID and if it sees the same, it cancels ?

If yes, how to reset, since during development I am often crashing.

thanks
deepak

app.all(’/query’, function(req, res){
setCORSHeaders(res);
console.log(“deepak/query : function …”)
console.log(req.url);
console.log(req.body);
var slo_panelId = req.body.panelId;
var slo_target = [];

console.log("/query: REQUEST OBJECT PANEL ID = " + slo_panelId);
if (req.body.targets != null) {
slo_target = req.body.targets;
for (var i = 0; i < slo_target.length; i++) {
console.log("/query: REQUEST OBJECT TARGET :" + i + " >> " + slo_target[i].target);
console.log("/query: REQUEST OBJECT TYPE :" + i + " >> " + slo_target[i].type);
console.log("/query: REQUEST OBJECT REF ID :" + i + " >> " + slo_target[i].refId);
}
}

var tsResult = [];
_.each(req.body.targets, function(target) {
if (target.type === ‘table’) {
tsResult.push(table);
} else {
var k = _.filter(timeserie, function(t) {
return t.target === target.target;
});

  _.each(k, function(kk) {
    tsResult.push(kk)
  });
}

});

if (undefined !== slo_target[0]) {
console.log(" #1  app(/query) : syncQuery.then():  target = " + slo_target[0])

syncQuery(sqlQuery1).then(
    function (results) {
        console.log(" app(/query) : syncQuery.then():  result = " + results);
        console.log(" #2 app(/query) : syncQuery.then():  target = " + slo_target[0])

        timeserie = getdata(results, slo_target[0]);
        //printResult(bqResult.datapoints);
        printResult(timeserie.datapoints)
        res.json(timeserie);
        console.log(" app(/query) : syncQuery: timeserie = " + timeserie.datapoints)
        res.end();
    },
    function (error) {
    }
);

} else {
console.log(" #3 app(/query) : syncQuery.then(): target NULL = " + slo_target[0])

}

//res.json(tsResult);
// res.json(tsResult);
//res.end();
});

app.listen(3334);

console.log(“Server Deepak is listening to port 3334”);

Here is some more debugging info, hopefully this will be helpful:

In looking at browser side I see these network transactions:
search OPTIONS 200 OK xhr angular.js?bust=1491846844708:12410 Script 409 B
search POST 200 OK xhr Other 409 B
query OPTIONS (pending) xhr angular.js?bust=1491846844708:12410 Script 0 B

The search successfully populated my metrics on the dropdown, but then when it went to fetch the data by doing a query post it never populated the request object nor did it seem to remain in state = “pending”

You need to respond the OPTIONS request. This something browser do automatically when one domain is requesting data from another domain. It’s called Cross-Origin Resource Sharing (CORS) and is a security features in browser.

If you use “direct” access mode in Grafana the browser javascript is going to issue a ajax request to your http api, browser will first ask you http api if this is allowed by using the OPTIONS http method (and empty body). Your server needs to respond with an empty body and OK status code. Then the browser will issue the real POST request.

If you do not want to deal with this you can use Grafana’s proxy mode, in this mode the request will go through grafana-server and no CORS handling is required by your server.

Hi Torkel,

Thank you, this worked !
Very much appreciated !

Best Regards,

deepak