grafana-datasource icon indicating copy to clipboard operation
grafana-datasource copied to clipboard

Support metrics with special characters in query builder

Open rul-hydro opened this issue 1 year ago • 14 comments

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.)

rul-hydro avatar Jan 11 '24 16:01 rul-hydro