Skip to content
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

fix(prometheus) Metric name should not be set twice #1330

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions prometheus/src/main/scala/filodb/prometheus/ast/Vectors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}")
Comment on lines +190 to +192
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does something like {_metric_="foo"} still parse successfully? I'm not 100% sure if metricName accounts for both foo{~} and {_metric_="foo"}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add tests for those too but yes it parses. I'm not sure is {_metric_="foo"} is equivalent to foo{~} as _metric_ is more internal to FiloDB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed more tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think should happen for {__name__="foo", _metric_="foo"} ? This is expected to fail?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, lgtm. Good point about _metric_-- I'm also not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishramachandran @tjackpaul @sherali42 Can you please share your view on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{__name__="foo", _metric_="foo"} should fail.


parseSuccessfully("test{a=\"b\"}[5y] OFFSET 3d")
parseSuccessfully("test{a=\"b\"}[5y] LIMIT 3")
Expand Down Expand Up @@ -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")),
)

Expand Down