diff --git a/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala b/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala index e95fd1b7bb..e0fd105299 100644 --- a/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala +++ b/prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala @@ -8,9 +8,10 @@ import filodb.prometheus.parse.Parser import filodb.query._ object Vectors { - val PromMetricLabel = "__name__" - val TypeLabel = "_type_" - val BucketFilterLabel = "_bucket_" + val PromMetricLabel = "__name__" + val PromInternalMetricLabel = "_metric_" + val TypeLabel = "_type_" + val BucketFilterLabel = "_bucket_" } object WindowConstants { @@ -151,7 +152,7 @@ sealed trait Vector extends Expression { * (2) at least one label matcher exists. */ def applyPromqlConstraints(): Unit = { - val nameLabel = labelSelection.find(_.label == PromMetricLabel) + val nameLabel = labelSelection.find(lm => lm.label == PromMetricLabel || lm.label == PromInternalMetricLabel) if (metricName.nonEmpty) { if (nameLabel.nonEmpty) { throw new IllegalArgumentException( diff --git a/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala b/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala index 5b57e6a5bb..305f6fb3f5 100644 --- a/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala +++ b/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala @@ -181,10 +181,15 @@ class ParserSpec extends AnyFunSpec with Matchers { parseError("foo{a*\"b\"}") parseError("foo{a>=\"b\"}") + parseSuccessfully("{__name__=\"foo\"}") + parseSuccessfully("{_metric_=\"foo\"}") parseError("foo::b{gibberish}") parseError("foo{1}") parseError("{}") parseError("foo{__name__=\"bar\"}") + parseError("foo{__name__=\"foo\"}") + parseError("foo{_metric_=\"bar\"}") + parseError("foo{_metric_=\"foo\"}") parseSuccessfully("test{a=\"b\"}[5y] OFFSET 3d") parseSuccessfully("test{a=\"b\"}[5y] LIMIT 3") @@ -728,6 +733,7 @@ class ParserSpec extends AnyFunSpec with Matchers { ("""{__name__="foo"}""" -> Map("__name__" -> "foo")), ("""{__name__="foo", bar="baz"}""" -> Map("__name__" -> "foo", "bar" -> "baz")), ("""{bar="baz"}""" -> Map("bar" -> "baz")), + """{_metric_="foo"}""" -> Map("_metric_" -> "foo"), // not same as """{__name__="foo"}""" ("""foo{bar="baz", bog="bah"}""" -> Map("__name__" -> "foo", "bar" -> "baz", "bog" -> "bah")), )