This repository was archived by the owner on Oct 7, 2024. It is now read-only.
Added support for template variable queries #36
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is related to issue #30.
Presently Simple JSON Datasource does not work as a proper data source for template variables of type: Query. It only supports an argument object with a property "target". When template variables send their query to the data source, there is only one argument and it is a string, which is just the content of the query the user entered into the template variable text box.
Since
metricFindQuery
only expects a nested object as the argument, it effectively strips off the query value before sending it on to the data source whenoptions
is a string:We can support both use cases by providing some conditional logic to detect what type of argument has been passed from Grafana:
Also right now the
mapToTextValue
function only supports results that are of a single value. The returned value is used as the text, and the index in the list is used as the value:By adding some additional conditional logic to detect nested text/value objects, we can support both scenarios:
The nested
{ text: "label", value: "rawValue" }
is supported by query template variables. Grafana will use thetext
property as the label in the template variable drop down and thevalue
property as the actual value of the template variable. I believe this also might possibly address issue #27 as well.Using Simple JSON Datasource as a custom template variable aliasing solution is very desirable since Grafana currently does not support custom aliasing/look up for template variables. This happens when you have a raw value that is not very user-friendly to display that you want to use as a template variable. This setup provides a solution where you can use Simple JSON Datasource to alias template variables and provide a user-friendly label on the dashboard, but preserve the raw value for driving queries using your own HTTP endpoint to drive aliasing.