Support metrics with special characters in query builder
As mentioned in #128, the query builder generates invalid code when the metric name contains special characters, such as slash (/) or dash (-), and quite possibly others.
When picking a metric with special characters (e.g. foo/bar) from the drop-down, the builder should write the query as {__name__="foo/bar"} instead of just foo/bar. When switching back from Code to Builder, the label filter __name__= should also be translated to the Metric drop-down.
I suppose the distinction for the metric names could be done by a regex. Prometheus docs state that a valid metric name should match [a-zA-Z_:][a-zA-Z0-9_:]*. The expression for compatible metric names could be a bit broader than that, like [a-z-A-Z0-9_:.] or something like that. Anything not matching this expression would be written as a label filter.
(Beware of quotes in metric names - if anyone should be crazy enough to have them.)
Sorry guys ... I got it all wrong in #128 :D
Actually how it should be is to just escape the names from query builder:
Like for our case:
bts\-erp.sys_metrics_heap\-used
vs
{__name__="bts-erp.sys_metrics_heap-used"}
So just escape the names and take them into account when parsing or selecting the metrics from dropdown.
(based on idea from: https://stackoverflow.com/questions/52537029/escape-special-characters-in-prometheus-metric-names)
I tried this in grafana too.
Entering the metrics without builder:
But when trying to switch to builder:
After accepting the risk and continue:
Support metrics with special characters has been added at datasource starting from v0.6.0. Closing the feature request as done.
Looks great, thank you!
@Loori-R I tried and it's actually a lot better. However for such metrics we are unable to select label filters in dropdown.
Raw query works (and we have 4 labels (color, host, ...):
bts\-erp.heartbeat_metrics_value{color="blue"}
When changing from raw query to builder it populates the fields correctly. Just dropdown does not resolve all the possible labels.
Like when filtering labels or fetching them it does not take \ into account ?
Hey @matejsp, thanks for pointing this out! You're right about the dropdown issue with the special characters. We've just opened Issue #140 to tackle this.
hi @Loori-R , I found that the query builder doesn't support label names containing dot. In the following example, k8s.cluster.name is converted to k8s in builder
Hello, @chenlujjj! Thanks for your message. It looks like we missed handling special characters in labels. I've reopened it.
Hello @Loori-R , @hagen1778 , Thanks for your work, seems you have fixed it, cool!
May I know when the fix will be released so that we can install it into our Grafana ?
Does it also fix the auto-completion and syntax highlighting when the label names contain dots?
Hi @chenlujjj ! Can you try to install the latest release? It contains the bug fix which should solve your issue.
Hello @dmitryk-dk , @Loori-R , the new release do fix the issue of query builder, thanks.
However, there are still problems with auto-completion and syntax highlighting:
- auto-completion After I typed the metric name, the braces and the prefix of label name, it cannot auto complete the remaining part of the label name.
NOTE: for the first time it can auto complete, but when I deleted the labels in braces and tried to input label names, it cannot auto complete.
- syntax highlighting
I think the
k8s.cluster.namelabel should be of green color, but now only thenamepart is green.
@chenlujjj thank you! We will take a look into this issue
hi @dmitryk-dk wondering what's the progress of this issue ?
hi @dmitryk-dk wondering what's the progress of this issue ?
Hi! Sorry for the delay. We will take a look as soon as possible, maybe by the end of next week.
(grafana v10.4.14) (victoriametrics-datasource v0.10.3)
suffering from the same problem, any metric name with unicode characters is not properly handled by query builder
Query generated by query builder (not working):
µg\/m³_value{entity_id="ikea_of_sweden_vindstyrka_particulate_matter"}
This is working, but it's quite annoying since it requires switching to manual mode and escaping by hand every time
\µg\/m\³_value{entity_id="ikea_of_sweden_vindstyrka_particulate_matter"}
(grafana v10.4.14) (victoriametrics-datasource v0.10.3)
suffering from the same problem, any metric name with unicode characters is not properly handled by query builder
Query generated by query builder (not working):
µg\/m³_value{entity_id="ikea_of_sweden_vindstyrka_particulate_matter"}This is working, but it's quite annoying since it requires switching to manual mode and escaping by hand every time
\µg\/m\³_value{entity_id="ikea_of_sweden_vindstyrka_particulate_matter"}
Hi @Loori-R ! Could you take a look ?
Hey @Loori-R @dmitryk-dk , any updates on it?
No updates at this time; scheduled for this month.


