I have built a backend datasource plugin for grafana to interface grafana with a custom datasource used in my collaboration and everything works great so far!
However, every once in a while, the database we are using gets written to a new file with a new name and to deal with this we point our datasource at a symlink. Since the datasource opens the database only when it is instantiated it does not notice that the symlink has changed when a new database file is created.
In the past all our tools have had a reload button which effectively just forced the database to be closed-opened again to fix this. I am looking for something similar in grafana… Perhaps a second refresh button in the task bar which can send a POST request on a specific endpoint. I understand that I can just add a button in the query which would do this but this is not ideal for UX as then users would have to click edit on an arbitrary plot to send this refresh command. I am really looking for a solution that is “dashboard-level”.
Extending the task bar as you suggests is not currently supported. You could possibly develop a custom panel plugin with a button.
Can’t you change how your datasource backend function to keep track of/understand when the file has been written to a new file? I suppose you want to use connection pooling if this is a proper database to optimize performance - otherwise open/close the connection on each request? What database are this, sounds like sqlite or similar?
Another alternative, when the new database file are written have some additional job that updates the configured Grafana datasource via the Grafana HTTP API - then on next request to that datasource the instance will be disposed and re-created.
This is a backend plugin to support a fairly obscure ~old~ reference implementation of the Dirfile standard. The major use case for us is live data streaming which is being written to the dirfile via another process which is “grafana-agnostic”.
Creating a panel plugin which is just a button is what I have been leaning towards. I can add a resource which, when called, would close and open the dirfile however I am not sure I understand if it is possible to integrate a separate plugin to call another plugin’s resources.
Effectively the resource endpoint ends up being something like .../datasourceUID/resources/yourcustompath which is automatically generated when calling postResource() from DataSourceWithBackend provided by grafana/runtime. My question becomes how can a distinct panel plugin access the postResource() method from my data-source plugin?
Finally as a general design statement. It might be convenient to distinguish between soft and hard reloads in grafana. For example if you shift click on the refresh button this should send a different query flag to data-sources such that they can do a more thorough reload similarly to how most browsers force fetch all assets when you do the same.