Sending raw SQL queries to generic webservice in Grafana


We are using open source version of Grafana (v 6.3.4) for data visualization of some important performance indicator metrics for our product. We are using MySQL as the data source.

Now there is a requirement to add database caching layer to our back-end database which is MySQL wire compliant. In order to support this, we are planning to write a web-service which wraps the caching layer and database connection logic.

Now the challenge is how to support the caching logic from grafana queries? We want to pass the raw sql queries to the web service query end point instead of the database directly. The query end point will take care of the caching logic.

I looked at the Simple JSON generic data source supported by Grafana. It means that we have to implement certain endpoints like /query, /search. /annotations etc in our back-end webservice.

The challenge that I faced is, the input JSON supported by simple JSON data source does not seem to support raw sql. In our case, the SQL queries are complex, they involve sub-select queries, JOIN, GROUP BY in addition to simple filtering logic.

So basically what I need is Grafana to support the same queries, but not to MYSQL datasource but to the new webservice that I am going to implement.

Please let me know how I can proceed. Also if there is any suitable alternative data source for my use case.


Any help on the specific need here?

I am assuming it would be a common need for database with external caching layer. Can I send complex raw SQL queries to a webservice instead of the database?

Any help would be appreciated!

I think that this approach isn’t correct with grafana, it maybe easier make a fork of mysql datasource with this feature.