From db8957ebbec0f5c47a72e0ce14447366aeed4705 Mon Sep 17 00:00:00 2001 From: Amol Nayak Date: Tue, 1 Feb 2022 15:55:17 -0800 Subject: [PATCH 1/2] Metric name should not be set twice --- .../src/main/scala/filodb/prometheus/ast/Vectors.scala | 9 +++++---- .../test/scala/filodb/prometheus/parse/ParserSpec.scala | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) 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..69d03ab31d 100644 --- a/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala +++ b/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala @@ -185,6 +185,9 @@ class ParserSpec extends AnyFunSpec with Matchers { 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") From 85131ef00049bdec2ee4ec79f922c87aa73dd6e6 Mon Sep 17 00:00:00 2001 From: Amol Nayak Date: Tue, 1 Feb 2022 16:36:02 -0800 Subject: [PATCH 2/2] Added more tests --- .../src/test/scala/filodb/prometheus/parse/ParserSpec.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala b/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala index 69d03ab31d..305f6fb3f5 100644 --- a/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala +++ b/prometheus/src/test/scala/filodb/prometheus/parse/ParserSpec.scala @@ -181,6 +181,8 @@ 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("{}") @@ -731,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")), )