I’m trying to construct my own datasource plugin based on example app and simple json datasource. When I try do add my datasource in grafana I receive the “Plugin module is missing Datasource constructor” error. My datasource.js code is:
export default class ExampleAppDatasource {
constructor(instanceSettings, $q, backendSrv, templateSrv) {
this.type = instanceSettings.type;
this.url = instanceSettings.url;
this.name = instanceSettings.name;
this.q = $q;
this.backendSrv = backendSrv;
this.templateSrv = templateSrv;
this.withCredentials = instanceSettings.withCredentials;
this.headers = {'Content-Type': 'application/json'};
if (typeof instanceSettings.basicAuth === 'string' && instanceSettings.basicAuth.length > 0) {
this.headers['Authorization'] = instanceSettings.basicAuth;
}
}
query(options) {
return this.q(function(resolve, reject) {
var result = {
data : [
{
"target":"upper_75",
"datapoints":[
[622.0, 1450754160], [365.0, 1450754220], [42.0, 1450754280], [240.0, 1450754340], [401.0, 1450754400], [364.0, 1450754460], [325.0, 1450754520], [6.0, 1450754580], [267.0, 1450754640]
]
}
]
}
resolve(result)
});
}
testDatasource() {
return { status: "success", message: "Data source is working", title: "Success" };
}
}