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(query) Regex equals .* must ignore the label and match series even without the label #1639

Merged
merged 5 commits into from
Jul 28, 2023

Conversation

amolnayak311
Copy link
Contributor

Pull Request checklist

  • The commit(s) message(s) follows the contribution guidelines ?
  • Tests for the changes have been added (for bug fixes / features) ?
  • Docs have been added / updated (for bug fixes / features) ?

Current behavior :

Queries like foo{dummy=~".*"} are expected to match all timeseries with metric name foo even without the label dummy, in short, the filter should have same behavior as not having the filter. However, currently the matches are only made for series with the label present

New behavior :
The above behavior is fixed and now the label is not considered in matching if it matches an empty string ""

yu-shipit
yu-shipit previously approved these changes Jul 25, 2023
alextheimer
alextheimer previously approved these changes Jul 26, 2023
Copy link
Contributor

@alextheimer alextheimer left a comment

Choose a reason for hiding this comment

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

All looks good (and thanks for the tests btw) 👍

private def leafFilter(column: String, filter: Filter): Query = {
filter match {
case EqualsRegex(value) =>
val regex = removeRegexAnchors(value.toString)
if (regex.nonEmpty) new RegexpQuery(new Term(column, regex), RegExp.NONE)
else leafFilter(column, NotEqualsRegex(".+")) // value="" means the label is absent or has an empty value.
if(regex.r.unapplySeq("").isDefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: does matches work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly what I was looking for, but its available in Scala 2.13

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, I can do this regex.r.pattern.matcher("").matches() since regex does not provide the matches method

// Check if the given regex matches the empty string, if yes, then do not consider this label
val booleanQuery = new BooleanQuery.Builder
val allDocs = new MatchAllDocsQuery
booleanQuery.add(allDocs, Occur.FILTER).build()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just return a MatchAllDocsQuery directly (it implements Query, at least.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, done

alextheimer
alextheimer previously approved these changes Jul 27, 2023
@amolnayak311 amolnayak311 merged commit 955814e into filodb:develop Jul 28, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants