-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: select key, value pairs in variable queries #79
Comments
Hi, and thanks for the kind words! ❤️ I think it would make sense to be able to use a different field as a label for the values in a dashboard variable, and I'd like to add it. That being said, I'd like to explore different ways to configure this. Instead of using keywords like My initial thought is to have the user select the field to use for the value and for the label (text) using drop-downs. I believe this would make renaming redundant, since the field could have any name. Would that work for your use case? |
Thanks for the quick reply! That's a good suggestion, though after giving it a bit of a think, that approach might be a bit limiting, as well. With SQL queries, again as an example, I can write This would accommodate both the variable query and panel query scenarios, with the added benefit of no longer needing to use a transform in order to rename a field in a panel query. Also, it would accommodate the variable query scenario slightly better than using predefined dropdowns, as AFAIK, there are only those limited variables. This would allow for adding as many arbitrary fields as desired to those variable queries. And as variable queries don't have the ability to apply transformations, it would accommodate more scenarios than just those few predefined in the dropdown. |
I'm not sure I understand this. When would you want to add an arbitrary number of fields to a variable query? Could you give me an example? AFAIK there wouldn't be any use for anything else than a a value field, and an optional label field? Regarding renaming fields—Earlier versions of the plugin actually had support for aliasing fields, but I decided to remove the feature since it's now possible to do this in Grafana itself. Although I'll be the first one to admit that it's not as user-friendly, since it's a feature that all data source would benefit from I'd prefer to improve this upstream rather than reimplement it. That being said, if there are enough people who want to bring the alias feature back, I'll definitely consider it. However, I don't think(?) that aliases and explicitly configuring value/label fields for variable queries are dependent on each other? I think that we could implement the value/label field selection while we discuss whether to bring aliases back in a separate issue? My main reason for not wanting to use "magic keywords", like Hope I'm making sense here :) |
A fair question :). Forgive me if this still doesn't make sense, as I've only been using Grafana for about a week, but I'll take a stab at it. Additional / arbitrary fields would be helpful if the user wanted to reference them from within panel queries, such as in a SELECT or a WHERE clause. RESTful API's can return any number of data points, and in a given query they may prove effectual in helping to narrow a query further or define additional fields to extract, join on, or display. Re: " There's another reason why native aliases would be helpful: absent the ability to alias natively, field name collisions are possible. Take the following JSON structure:
If one wanted to extract both On your last point, a few possible ideas to address your concerns might be:
Cheers |
It sounds like you'd like to pass a multi-dimensional value within variable, essentially an object, to the panel query. AFAIK this isn't supported by Grafana. The API only allows plugins to send a single value (string or number) and an optional label for that value.
This is a very valid reason for why we should allow aliases in the queries. Name collisions shouldn't be a problem, as Grafana makes them unique by adding a sequence number to the field name. Either way, you make good points on why we should reintroduce aliases. Even if we would introduce aliases, I'd still like to explore other options to configure an optional text label for variable queries. Indeed aliases would be necessary if we were to go with the As for the configuration of variable labels, I'd like to experiment a little first. I'm thinking that this could set a precedent for how we implement #36 which would require similar |
Hi @marcusolsson , I could really benefit from this feature. Is there any timeline on when this feature would be available? |
I've just published v1.1.0 to the marketplace, which includes experimental support for this. Would you mind checking it out and letting me know whether it addresses your use case? |
Hi @marcusolsson sorry for the late reply. Thank you! I'll be giving it a go and will report back in a few days, hopefully. |
@marcusolsson I've given it a go but ran into an issue with #98 which is blocking me from testing further. |
Right, I worked through #98 but found that this isn't working for me thus far. It appears to only be picking up |
If you are using grafana 7.1.2+ you could use global variables $__from and
$__to for this. Details at
https://grafana.com/docs/grafana/latest/variables/variable-types/global-variables/
…On Thu, Apr 22, 2021, 6:57 AM Tim Underhay ***@***.***> wrote:
Right, I worked through #98
<#98> but
found that this isn't working for me thus far. It appears to only be
picking up __value but not __text.
[image: image]
<https://user-images.githubusercontent.com/15734900/115642047-45144200-a2e8-11eb-9eb1-8018eb558c70.png>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#79 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATUR2IW33GNM5RUSLZQTJIDTJ53PPANCNFSM4ZHFUQSA>
.
|
@sasha-blip time range isn't the issue here -- maybe you meant to comment in #98. It's the variable extraction or return that appears not to be working. |
Sorry, I wasn't using the feature properly -- was trying to set the field names using alias -- I found the settings under experimental tab. Seems to be working! |
First, thank you @marcusolsson for this fantastic plugin. Top notch!
I'd like to request a feature, namely the ability to select multiple values in dashboard variable queries, and give the ability to rename their values to __value and __text, so that the selection may be a key / value pair. Currently, only a single value is selectable in the variable query options, i.e. the + / - buttons are missing.
Scenario: My JSON query returns an array of key / value pairs, such as
[ { "mykey": "somekey", "myvalue": "somevalue"} ]
. I want my dashboard selector to show "somevalue", but when I select a value, I want __value to be set to "somekey". Grafana supports this for values named__value
and__text
.Which enters the second part: once I've defined my field, the ability to rename it is required, ideally to some arbitrary value of my choosing (similar to a
SELECT mykey as __value, myvalue as __text
).Please see this blog post for how this scenario is accomplished using mysql: https://grafana.com/blog/2019/07/17/ask-us-anything-how-to-alias-dashboard-variables-in-grafana-in-sql/
Thank you!
The text was updated successfully, but these errors were encountered: