Working Backend Plugin Example

Howdy,

I am exploring the possibility of creating a backend datasource plugin to interface to an API I am building. I have a client implementation written in go and this appears to be a neat way to proceed. I have been through the documentation (https://grafana.com/docs/grafana/latest/plugins/developing/backend-plugins-guide/) and understand the intention to put more effort into documentation by example, however, the current state of the recommended example appears to be broken (https://github.com/grafana/simple-json-backend-datasource/issues/3). Both the frontend and backend builds do not work out of the box. It is a little concerning that issues have been raised on this example more than 6 months ago and the author nor any other contributor have responded.

I’ve only managed to get the backend building and I’d be more than happy to submit some changes but I sure could do with some pointers on building the frontend component of the simple-json-backend-datasource repo.

Thanks in advance.
matb

1 Like

We’re currently working on a Go SDK for backend plugins, but it’s still in heavy development:

I wrote a sample plugin a while ago, along with some documentation, that might help you in the meantime:

It’s very much in an experimental state, but please submit an issue on the repository if you run into any issues, and I’ll try to update it.

2 Likes

Thanks for the pointer @marcusolsson, i’ve yet to compile and test your csv backend data source but it looks like it is exactly what I have been searching for.

1 Like

Hi @marcusolsson,

I have run into a few issues with the aforementioned example repo. Initially I encountered some build issues which I believe I have overcome. I appear to be able to load the plugin up successfully from grafana (which I am running from within a the official 6.4.5 docker container) I am now faced with a failing data source when I attempt to save and test. It would appear the issue is in the backend but I am unable to get any logs from the backend component of the plugin. stderr appears to be getting swallowed up and not surfaced through the regular logging stream. Any thoughts or pointers on the subject would be greatly appreciated.

Edit: embarrassingly, simply increasing the verbosity of Grafana logging via GF_LOG_LEVEL=debug sees the plugin debug surfaced. This uncovered the fact that data source test function was failing because the backend code is written such that it requires at least 2 fields configured and if not provided the QueryResult is not added to the slice before returning.

1 Like

Oh, yes. Sorry about that :sweat_smile:

I’m glad you got it to work in the end!