Skip to content

Commit

Permalink
Rename stable to classic
Browse files Browse the repository at this point in the history
Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana committed Sep 23, 2023
1 parent f91d276 commit 86e2774
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
32 changes: 16 additions & 16 deletions featurecontrol/featurecontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,36 @@ import (
)

const (
fcReceiverNameInMetrics = "receiver-name-in-metrics"
fcStableMatchersParsing = "stable-matchers-parsing"
fcUTF8MatchersParsing = "utf8-matchers-parsing"
fcReceiverNameInMetrics = "receiver-name-in-metrics"
fcClassicMatchersParsing = "classic-matchers-parsing"
fcUTF8MatchersParsing = "utf8-matchers-parsing"
)

var AllowedFlags = []string{
fcReceiverNameInMetrics,
fcStableMatchersParsing,
fcClassicMatchersParsing,
fcUTF8MatchersParsing,
}

type Flagger interface {
EnableReceiverNamesInMetrics() bool
StableMatchersParsing() bool
ClassicMatchersParsing() bool
UTF8MatchersParsing() bool
}

type Flags struct {
logger log.Logger
enableReceiverNamesInMetrics bool
classicMatchersParsing bool
utf8MatchersParsing bool
stableMatchersParsing bool
}

func (f *Flags) EnableReceiverNamesInMetrics() bool {
return f.enableReceiverNamesInMetrics
}

func (f *Flags) StableMatchersParsing() bool {
return f.stableMatchersParsing
func (f *Flags) ClassicMatchersParsing() bool {
return f.classicMatchersParsing
}

func (f *Flags) UTF8MatchersParsing() bool {
Expand All @@ -67,9 +67,9 @@ func enableReceiverNameInMetrics() flagOption {
}
}

func enableStableMatchersParsing() flagOption {
func enableClassicMatchersParsing() flagOption {
return func(configs *Flags) {
configs.stableMatchersParsing = true
configs.classicMatchersParsing = true
}
}

Expand All @@ -92,9 +92,9 @@ func NewFlags(logger log.Logger, features string) (Flagger, error) {
case fcReceiverNameInMetrics:
opts = append(opts, enableReceiverNameInMetrics())
level.Warn(logger).Log("msg", "Experimental receiver name in metrics enabled")
case fcStableMatchersParsing:
opts = append(opts, enableStableMatchersParsing())
level.Warn(logger).Log("msg", "Stable matchers parsing enabled")
case fcClassicMatchersParsing:
opts = append(opts, enableClassicMatchersParsing())
level.Warn(logger).Log("msg", "Classic matchers parsing enabled")
case fcUTF8MatchersParsing:
opts = append(opts, enableUTF8MatchersParsing())
level.Warn(logger).Log("msg", "UTF-8 matchers parsing enabled")
Expand All @@ -107,8 +107,8 @@ func NewFlags(logger log.Logger, features string) (Flagger, error) {
opt(fc)
}

if fc.stableMatchersParsing && fc.utf8MatchersParsing {
return nil, errors.New("Both stable and UTF-8 matchers parsing is enabled, please choose one or remove the flag for both")
if fc.classicMatchersParsing && fc.utf8MatchersParsing {
return nil, errors.New("Both classic and UTF-8 matchers parsing is enabled, please choose one or remove the flag for both")
}

return fc, nil
Expand All @@ -118,6 +118,6 @@ type NoopFlags struct{}

func (n NoopFlags) EnableReceiverNamesInMetrics() bool { return false }

func (n NoopFlags) StableMatchersParsing() bool { return false }
func (n NoopFlags) ClassicMatchersParsing() bool { return false }

func (n NoopFlags) UTF8MatchersParsing() bool { return false }
26 changes: 13 additions & 13 deletions matchers/compat/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
)

var (
parseMatcher = stableMatcherParser(log.NewNopLogger())
parseMatchers = stableMatchersParser(log.NewNopLogger())
parseMatcher = classicMatcherParser(log.NewNopLogger())
parseMatchers = classicMatchersParser(log.NewNopLogger())
)

type matcherParser func(s string) (*labels.Matcher, error)
Expand All @@ -48,9 +48,9 @@ func Matchers(s string) (labels.Matchers, error) {

// InitFromFlags initializes the compat package from the flagger.
func InitFromFlags(l log.Logger, f featurecontrol.Flagger) {
if f.StableMatchersParsing() {
parseMatcher = stableMatcherParser(l)
parseMatchers = stableMatchersParser(l)
if f.ClassicMatchersParsing() {
parseMatcher = classicMatcherParser(l)
parseMatchers = classicMatchersParser(l)
} else if f.UTF8MatchersParsing() {
parseMatcher = utf8MatcherParser(l)
parseMatchers = utf8MatchersParser(l)
Expand All @@ -60,20 +60,20 @@ func InitFromFlags(l log.Logger, f featurecontrol.Flagger) {
}
}

// stableMatcherParser uses the old pkg/labels parser to parse the matcher in
// classicMatcherParser uses the old pkg/labels parser to parse the matcher in
// the input string.
func stableMatcherParser(l log.Logger) matcherParser {
func classicMatcherParser(l log.Logger) matcherParser {
return func(s string) (*labels.Matcher, error) {
level.Debug(l).Log("msg", "Parsing with stable matchers parser", "input", s)
level.Debug(l).Log("msg", "Parsing with classic matchers parser", "input", s)
return labels.ParseMatcher(s)
}
}

// stableMatchersParser uses the old pkg/labels parser to parse zero or more
// classicMatchersParser uses the old pkg/labels parser to parse zero or more
// matchers in the input string. It returns an error if the input is invalid.
func stableMatchersParser(l log.Logger) matchersParser {
func classicMatchersParser(l log.Logger) matchersParser {
return func(s string) (labels.Matchers, error) {
level.Debug(l).Log("msg", "Parsing with stable matchers parser", "input", s)
level.Debug(l).Log("msg", "Parsing with classic matchers parser", "input", s)
return labels.ParseMatchers(s)
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func fallbackMatcherParser(l log.Logger) matcherParser {
err error
invalidErr error
)
level.Debug(l).Log("msg", "Parsing with UTF-8 matchers parser, with fallback to stable matchers parser", "input", s)
level.Debug(l).Log("msg", "Parsing with UTF-8 matchers parser, with fallback to classic matchers parser", "input", s)
if strings.HasPrefix(s, "{") || strings.HasSuffix(s, "}") {
return nil, fmt.Errorf("unexpected open or close brace: %s", s)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func fallbackMatchersParser(l log.Logger) matchersParser {
err error
invalidErr error
)
level.Debug(l).Log("msg", "Parsing with UTF-8 matchers parser, with fallback to stable matchers parser", "input", s)
level.Debug(l).Log("msg", "Parsing with UTF-8 matchers parser, with fallback to classic matchers parser", "input", s)
m, err = parse.Matchers(s)
if err != nil {
m, invalidErr = labels.ParseMatchers(s)
Expand Down

0 comments on commit 86e2774

Please sign in to comment.