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(filter): Wildcard trigger compatibility with graphite-clickhouse #896

Closed

Conversation

lordvidex
Copy link

  • there is no need for the variable allowMatchEmpty because it breaks compatibility with graphite-clickhouse

Additional information
BEFORE: Triggers that contained tags like tag1=~* with wildcard matching was matching for triggers that didn't have tag1 at all
NOW: When wildcard is used, at least the tag1 key must be present in the trigger before it can be a valid match.

View changes in tests to confirm new behaviour of matching tag patterns

- there is a need to discuss the importance of the variable `allowMatchEmpty` because it makes the tests pass but breaks compatibility with graphite-clickhouse
@lordvidex lordvidex requested a review from a team as a code owner August 17, 2023 10:21
@lordvidex lordvidex changed the title "fix(filter): Wildcard trigger compatibility with graphite-clickhouse" fix(filter): Wildcard trigger compatibility with graphite-clickhouse Aug 18, 2023
- when operators `=~` and `!=~` are used, both sides of the expression
  are matched LIKE in graphite.
@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2023

Codecov Report

Merging #896 (f3126ab) into master (0dc273e) will decrease coverage by 0.72%.
Report is 8 commits behind head on master.
The diff coverage is 53.24%.

❗ Current head f3126ab differs from pull request most recent head a45bc02. Consider uploading reports for the commit a45bc02 to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master     #896      +/-   ##
==========================================
- Coverage   69.65%   68.93%   -0.72%     
==========================================
  Files         191      195       +4     
  Lines       10561    10884     +323     
==========================================
+ Hits         7356     7503     +147     
- Misses       2779     2937     +158     
- Partials      426      444      +18     
Files Changed Coverage Δ
api/dto/contact.go 0.00% <ø> (ø)
api/dto/event_history_item.go 0.00% <ø> (ø)
api/dto/events.go 0.00% <ø> (ø)
api/dto/health.go 0.00% <ø> (ø)
api/dto/notification.go 0.00% <ø> (ø)
api/dto/pattern.go 0.00% <ø> (ø)
api/dto/tag.go 0.00% <ø> (ø)
api/dto/team.go 0.00% <ø> (ø)
api/dto/user.go 0.00% <ø> (ø)
api/handler/config.go 0.00% <ø> (ø)
... and 47 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

filter/series_by_tag.go Outdated Show resolved Hide resolved
matchingHandlerCondition = func(value string) bool {
return matchRegex.MatchString(value)
}
case NotMatchOperator:
matchRegex := regexp.MustCompile("^" + spec.Value)
value := cleanAsterisks(spec.Value)
Copy link
Member

Choose a reason for hiding this comment

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

Why is needed ? Replace * to .* needed only if full string is *. Also may be add more tests for *

Copy link
Author

Choose a reason for hiding this comment

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

I replaced * with .* because in graphite-clickhouse, there is a greedy match. The SQL equivalent was something like %<string>% which basically means that both sides of the expressions are greedily matched.

Also, what we want when we query for cpu.machine*.loaded is not "zero or more characters of e" but any amount of characters after e. That is why it is needed for * to be changed to .* for this to work in regexp.

In the graphite-clickhouse source code, there is something like this too. Check https://github.com/go-graphite/graphite-clickhouse/blob/1db4b3d740c0f3e72ed8a3449603f4a016b5dda8/pkg/where/where.go#L64

Copy link
Author

Choose a reason for hiding this comment

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

@msaf1980 I don't know if i missed any tests, I have tried the following special cases here: https://github.com/moira-alert/moira/pull/896/files#diff-4e74ec0972e1312934727b9a6b03635e81344c8d854205ea594290ad604bedc7

  • empty
  • single asterisks
  • asterisk after an asterisk
  • properly written asterisk should remain i.e.
    • .* => ..*
    • .* => .*
  • when regexp has been anchored with ^ and $
  • prefix and suffix asterisks
  • mixed (correct and incorrectly written) asterisks

Copy link
Member

@msaf1980 msaf1980 Aug 23, 2023

Choose a reason for hiding this comment

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

In graphite-clickhouse seriesByTags * replaced to .* only in wildcards (it's not regular expression, but translated to regexp for check). Only one case whan * translated to .* in regexp, is a bad regexp *.

Copy link
Member

Choose a reason for hiding this comment

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

Also, add tests for regexp like a*b and a.*b for check why replacement * to .* is a bad thing.

Copy link
Author

Choose a reason for hiding this comment

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

Done

- changing `*` to `.*` will result in unexpected behaviour when used
  with matchOperator.
- matchOperator should contain valid regexp by default.
- matchOperator when invalid should not panic but always return a
  non-matching callback
@lordvidex lordvidex force-pushed the fix/wildcard-in-tagged-patterns branch from df0c8be to ee3b5f1 Compare August 23, 2023 12:07
@kissken
Copy link
Member

kissken commented Aug 30, 2023

/build

@@ -179,14 +214,14 @@ func createMatchingHandlerForOneTag(spec TagSpec) MatchingHandler {
}
}

matchEmpty := matchingHandlerCondition("")
// matchEmpty := matchingHandlerCondition("")
Copy link
Member

Choose a reason for hiding this comment

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

is it ok?

Copy link
Author

Choose a reason for hiding this comment

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

I want to remove it, but I need @msaf1980 to check graphite-clickhouse and give a review about some errors that might depend on this.

@github-actions
Copy link

Build and push Docker images with tag: fix-wildcard-in-tagged-patterns.2023-08-30.a45bc02

@Tetrergeru
Copy link
Member

We had to split this PR into two parts, to deploy them seprately: #924 and #923, so I am going to close this PR

@lordvidex, I mentioned you in these PR descriptions, thank you very much for your contribution!

@Tetrergeru Tetrergeru closed this Oct 13, 2023
@lordvidex
Copy link
Author

You're welcome!

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.

6 participants