thanos icon indicating copy to clipboard operation
thanos copied to clipboard

Incorrect regex label match when using `|` with an empty option

Open risinger opened this issue 3 years ago • 11 comments

Thanos, Prometheus and Golang version used: Thanos: v0.22.0 Prometheus: v2.28.1

Object Storage Provider: S3

What happened: Using a Thanos Store Gateway as the data source, prometheus_build_info{doesnotexist=~"whocares|"} (note the tailing | on that regex) returns no series.

What you expected to happen: I expected the Store Gateway to return the same series as prometheus_build_info{doesnotexist=""}, which is what a Prometheus data source does.

How to reproduce it (as minimally and precisely as possible): Write a query with label=~"value|" on a metric without a series with label="value". Use Store Filtering in the Query UI to select either a Prometheus instance or a Store Gateway. Example query: prometheus_build_info{doesnotexist=~"whocares|"}

Full logs to relevant components: Not applicable, I don't think.

Anything else we need to know: Basically Prometheus appears to interpret {label=~"value|"} as either {label=value} or {label=""} (label does not exist). I expected Thanos to do the same.

Let me know if you need anymore info.

risinger avatar Sep 07 '21 17:09 risinger

I was able to reproduce this on 0.22.0. Interesting bug. Thanks for the report! Help welcome.

GiedriusS avatar Sep 08 '21 07:09 GiedriusS

The reason is that our optimization on regex is not exactly the same as Prometheus' one.

Our implementation: https://github.com/thanos-io/thanos/blob/4276b50564d745d28a9f6ce3e92d19d6fd50c46f/pkg/store/bucket.go#L1763.

Prometheus: https://github.com/prometheus/prometheus/blob/b1ed4a0a663d0c62526312311c7529471abbc565/tsdb/querier.go#L221

As {doesnotexist=~"whocares|"} matches the empty string "", Prometheus will go for an inverse posting match. However, Thanos doesn't check whether the empty string is matched or not so the logic is different.

yeya24 avatar Sep 08 '21 19:09 yeya24

I would like to work on this issue, could you please guide me about how should I proceed.

kunaljain0212 avatar Sep 19 '21 20:09 kunaljain0212

I suppose a good start would be to add failing tests. A suitable location seems to be the e2e tests: https://github.com/thanos-io/thanos/tree/main/test/e2e.

GiedriusS avatar Sep 20 '21 09:09 GiedriusS

I would like to take up this issue.

Himanshu2107 avatar Dec 31 '21 13:12 Himanshu2107

Hello 👋 Looks like there was no activity on this issue for the last two months. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 If there will be no activity in the next two weeks, this issue will be closed (we can always reopen an issue if we need!). Alternatively, use remind command if you wish to be reminded at some point in future.

stale[bot] avatar Mar 02 '22 15:03 stale[bot]

Hello 👋 Looks like there was no activity on this issue for the last two months. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 If there will be no activity in the next two weeks, this issue will be closed (we can always reopen an issue if we need!). Alternatively, use remind command if you wish to be reminded at some point in future.

stale[bot] avatar Jun 12 '22 17:06 stale[bot]

@Himanshu2107 are you working on this?

drstevens avatar Jun 14 '22 20:06 drstevens

@drstevens no, not right now.

Himanshu2107 avatar Jun 16 '22 16:06 Himanshu2107

Hello 👋 Looks like there was no activity on this issue for the last two months. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 If there will be no activity in the next two weeks, this issue will be closed (we can always reopen an issue if we need!). Alternatively, use remind command if you wish to be reminded at some point in future.

stale[bot] avatar Sep 21 '22 02:09 stale[bot]

Bump

drstevens avatar Sep 21 '22 02:09 drstevens

I think this might be fixed by #6692 !

MichaHoffmann avatar Sep 03 '23 07:09 MichaHoffmann

Thanks @MichaHoffmann 🍻

drstevens avatar Sep 05 '23 17:09 drstevens

Thanks @MichaHoffmann 🍻

:beers:

MichaHoffmann avatar Sep 05 '23 17:09 MichaHoffmann

🏅 @MichaHoffmann

GiedriusS avatar Sep 05 '23 17:09 GiedriusS