-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[grafana] Improve dashboard variable substitution #3120
base: main
Are you sure you want to change the base?
Conversation
433f758
to
d7eaea2
Compare
I am happy to update this once more, but I'd really appreciate if this time I could have a 2nd review. Many thanks @zanhsieh for already looking into this. |
@zalegrala Can you review this plz? |
Have you had a chance to test this? It seems like we should be matching the closing brace also. |
The matches were modified to match braces as optional. Hence, the closing brace will match if it is there, e.g |
Looking at the old regex, I can test from the CLI with the following. ❯ echo '$variable' | sed '/-- .* --/! s/${{"{"}}{{ .name }}}/{{ .value }}/g'
$variable With the new regex and the ❯ echo '$variable' | sed -E '/-- .* --/! s/\$\{{"{"}}?{{ .name }}\}?/{{ .value }}/g'
sed: -e expression #1, char 54: Invalid content of \{\} How can we validate this before merge? |
Please be aware that this is a helm chart and hence first processed by helm. Thus *) in the new regex this could be omitted since there are no longer 3 |
The Grafana dashboard variable syntax allows varnames without curly braces ($datasource and ${datasource}). A substitution can only be applied for the latter. This enables extended regular expressions for sed to allow both substitutions to take place to include dashboards that are written in either form. Signed-off-by: Tobias Jungel <[email protected]>
Signed-off-by: Tobias Jungel <[email protected]>
Hi @zalegrala, |
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.
My question is, would that sed also work on an alpine environment? It is not known to me, if sed E is a gnu extension?
If not, 2 simple sed commands are needed.
Yes, this works on Alpine which eventually uses busybox sed. The latter has extended regex expressions (ERE) implemented. Thus, Though, thinking about the split of the regex made me think regarding the variable naming. One issue that might be related to this having a datasource variable name that is the prefix of another datasource variable, e.g. ds and ds_something. This could be mitigated by having to sed commands. The first as it was so far and the second without the curly braces but including the quotes. What do you think? |
I'm more a fan of practical solution over cool solutions. If there is already an potential use case, that could break and it can be avoided, then we go of this. Pretty sure there is a 1 in 100 that a dashboard using ds as prefix for something. |
The Grafana dashboard variable syntax allows varnames without curly braces (
$datasource and ${datasource}
). A substitution can only be applied for the latter. This enables extended regular expressions for sed to allow both substitutions to take place to include dashboards that are written in either form.