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
Variables: Adds support for key/value mapping in Custom variable #27829
Conversation
@sartaj10 thanks for making this contribution, I don't think we need a new Variable Type for this. This behavior belongs to the custom variable type. WDTH? |
@sartaj10 not sure what the best separator char would be for this, maybe |
yea, this feels like an extension of the custom variable |
@hugohaggmark @torkelo Regarding the separator, the semicolon seems more intuitive (similar to a hashmap). In the code, the user can escape the semicolon if it's being used as either a key or value using |
Updated the PR. It is now possible to include key/value pairs within the custom variable type and it takes care of the splitting whenever that is present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work on this @sartaj10 and thank you for contributing ⭐ I left a small comment and you also need to update the docs here:
https://github.com/grafana/grafana/blob/master/docs/sources/variables/variable-types/add-custom-variable.md
@sartaj10 I'm going to change this Draft PR into Ready for Review, ok? |
@hugohaggmark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Before we merge this I'd like for the technical writers to approve as well.
Perfect, thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor edit, then good to go!
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
Thanks, Done 👍 |
would be possible to access also a key as value? and sometimes I want in query |
Hi, I have updated my Grafana to the latest version and tried the key/value mapping, which is working fine. I also tried working with the variable data in my panels but seem to do something wrong, as it doesn't do what i want it to do. Example: Constellation: srv-a is the grafana machine with Prometheus installed - srv-b and srv-c are the node_exporters, sending the data to srv-a Prometheus has the IP addresses of srv-b and srv-c setup as targets In my Dashboard on Grafana I setup a variable with the new mapping feature such as: Variable name: host How can I query the IP (value) of the variable host in my panels? If I just put $host, it just returns the name (key)....I'm pretty sure I need to add something to $host but am just not sure what :( |
This breaks all existing dashboards using custom variabes with values that include a colon |
) * Initial work on adding new mapping variable type * Remove add button * Update custom variable type to include key/value mapping * Update custom variable docs * Try to fix failing build * Update reducer.ts * Fix failing build * Remove expansion of the colon * Update docs Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
@mareksimunek I came here looking for this exact same behaviour, did you manage to get this? |
Well, answering myself and @mareksimunek , if you do |
How can I query the value of the variable in my panels? If I put $variable_name, it just returns the name (key) but I can't seem to find a way, to get the value to use it in queries. Any help would be appreciated. |
How about do not introduce a separator at all, and still use commas: '100MB, 800000000', |
@mingmamma did you find a solution for this? I just bumped into the same issue. |
@mingmamma & @offbyone we use GitHub for issues and feature requests. For questions we kindly request that you ask your question at the community site or in our external Slack here Regarding your question the All the best |
@hugohaggmark I understand not wanting to use github issues for support, that's fine. Given that, would someone from the Grafana dev crew mind having a look at the support question for this topic? |
I just installed the latest version 7.4.2 and not seeing this feature. EDIT: Ok, it needs to have a space after the key and after colon. e.g. |
Is it possible to make the selected one based on key rather than value? |
What this PR does / why we need it:
This PR adds a new variable type where the user can enter key-value pairs as comma separated values where the key-value pairs are separated by colon (:). This would be useful where the user wants the dropdown values to be user-friendly while the query expects them in a different format. Eg : The user-friendly dropdown value could be 100 MB while the query expects it to be in bits (800000000)
Which issue(s) this PR fixes:
Fixes #1988
Fixes #1032
Special notes for your reviewer:
@hugohaggmark
Some screenshots are attached below