Migrating variable query returning text and value pairs to release 0.4.0
fgeo opened this issue · 4 comments
Hi, I'm trying to migrate my query variable to version 0.4.0 of the extension (and Grafana 8.4.0), however without success.
I have full control over the REST API providing the data, so any change there is possible.
The release note mentions for variables that "They now call /query endpoint instead of /search.", however from my testing it calls now a /variable
endpoint.
Here is a netcat
capture of a request made to my API when in the dashboard's variable editor with query field set to systems
(not showing all headers here):
POST /variable HTTP/1.1
Host: localhost:5000
User-Agent: Grafana/8.4.0
Content-Length: 143
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
{"payload":{"target":"systems"},"range":{"from":"2022-02-14T08:09:32.164Z","to":"2022-02-21T08:09:32.164Z","raw":{"from":"now-7d","to":"now"}}}
So I tried implementing a new /variable
endpoint, which returns the same JSON that worked previously with /search
(not actual values in reality, but identical structure):
[{"text":"System1","value":"Value1"},{"text":"System2","value":"Value2"},{"text":"System3","value":"Value3"}]
However instead of ending up (as before) with 3 variable value pairs (what is display to user in drop down list, what is used as value in queries), the variable has 6 possible values: System1, System2, System3, Value1, Value2, Value3
.
I've try naming fields in response differently (e.g. label, target, etc.) or different structure (e.g. a map directly), but without success. Either all is "flatten" as a list, or none is recognized.
So two question:
- Is it supposed to call this new
/variable
endpoint? I've seen nothing in documentation or openapi.yaml. - How to again have variable values as label+value, is it still possible?
You're right about the /variable
, I'll fix release notes and doc.
Can you try Grafana's __value
and __text
keys?
That did it, thanks!
So for others doing same migration, the working response to new /variable
is in the form of:
[{"__text":"System1","__value":"Value1"},{"__text":"System2","__value":"Value2"},{"__text":"System3","__value":"Value3"}]
Documented and released as 0.4.1