Skip to content

Commit

Permalink
Do not use FastRegexMatcher
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci committed Jan 3, 2025
1 parent c2b6130 commit 69cced8
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions model/labels/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package labels
import (
"bytes"
"strconv"

"github.com/grafana/regexp"
)

// MatchType is an enum for label matching types.
Expand Down Expand Up @@ -49,7 +51,7 @@ type Matcher struct {
Name string
Value string

re *FastRegexMatcher
re *regexp.Regexp
}

// NewMatcher returns a matcher object.
Expand All @@ -60,7 +62,8 @@ func NewMatcher(t MatchType, n, v string) (*Matcher, error) {
Value: v,
}
if t == MatchRegexp || t == MatchNotRegexp {
re, err := NewFastRegexMatcher(v)
// re, err := NewFastRegexMatcher(v)
re, err := regexp.Compile("^(?:" + v + ")$")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -136,35 +139,35 @@ func (m *Matcher) Inverse() (*Matcher, error) {

// GetRegexString returns the regex string.
func (m *Matcher) GetRegexString() string {
if m.re == nil {
return ""
}
return m.re.GetRegexString()
//if m.re == nil {

Check failure on line 142 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
return ""
//}

Check failure on line 144 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

comment-spacings: no space between comment delimiter and comment text (revive)
//return m.re.GetRegexString()

Check failure on line 145 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
}

// SetMatches returns a set of equality matchers for the current regex matchers if possible.
// For examples the regexp `a(b|f)` will returns "ab" and "af".
// Returns nil if we can't replace the regexp by only equality matchers.
func (m *Matcher) SetMatches() []string {
if m.re == nil {
return nil
}
return m.re.SetMatches()
//if m.re == nil {

Check failure on line 152 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
return nil
//}

Check failure on line 154 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

comment-spacings: no space between comment delimiter and comment text (revive)
//return m.re.SetMatches()

Check failure on line 155 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
}

// Prefix returns the required prefix of the value to match, if possible.
// It will be empty if it's an equality matcher or if the prefix can't be determined.
func (m *Matcher) Prefix() string {
if m.re == nil {
return ""
}
return m.re.prefix
//if m.re == nil {

Check failure on line 161 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
return ""
//}

Check failure on line 163 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

comment-spacings: no space between comment delimiter and comment text (revive)
//return m.re.prefix

Check failure on line 164 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
}

// IsRegexOptimized returns whether regex is optimized.
func (m *Matcher) IsRegexOptimized() bool {
if m.re == nil {
return false
}
return m.re.IsOptimized()
//if m.re == nil {

Check failure on line 169 in model/labels/matcher.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
return false
//}
//return m.re.IsOptimized()
}

0 comments on commit 69cced8

Please sign in to comment.