grafana / grafana-plugin-examples

189 stars 53 forks source link

Example: Datasource-Basic: Demonstrate how to use status code in QueryDataResponse #111

Closed xnyo closed 2 years ago

xnyo commented 2 years ago

This PR changes the datasource-basic example to demonstrate how to return a custom status code from a QueryData request. In order to use this feature, github.com/grafana/grafana-plugin-sdk-go has to be updated to at least v0.142.0 in the plugin. The status code is not currently being displayed anywhere in the Grafana UI, so the only way to test this is through the inspect panel.

If using this plugin with an old version of Grafana that does not support 207 status code (e.g.: v9.2.4), the status code won't be present in the response. The error message however will be present as always.

Fixes #108.

xnyo commented 2 years ago

Aftertought: The current code changes are only for the datasource-basic example. We have another backend-based example (datasource-http-backend). Shall we update that one as well to demonstrate how to use the status field? If not, I think we should at least bump grafana-plugin-sdk-go in that example. What do you think?

wbrowne commented 2 years ago

Aftertought: The current code changes are only for the datasource-basic example. We have another backend-based example (datasource-http-backend). Shall we update that one as well to demonstrate how to use the status field? If not, I think we should at least bump grafana-plugin-sdk-go in that example. What do you think?

🥇 I think that's a good idea!