diff --git a/featurecontrol/featurecontrol.go b/featurecontrol/featurecontrol.go index 0108a680e7..d48af09ad5 100644 --- a/featurecontrol/featurecontrol.go +++ b/featurecontrol/featurecontrol.go @@ -23,40 +23,40 @@ import ( ) const ( - fcReceiverNameInMetrics = "receiver-name-in-metrics" - fcClassicMatchersParsing = "classic-matchers-parsing" - fcUTF8MatchersParsing = "utf8-matchers-parsing" + FeatureReceiverNameInMetrics = "receiver-name-in-metrics" + FeatureClassicMode = "classic-mode" + FeatureUTF8Mode = "utf8-mode" ) var AllowedFlags = []string{ - fcReceiverNameInMetrics, - fcClassicMatchersParsing, - fcUTF8MatchersParsing, + FeatureReceiverNameInMetrics, + FeatureClassicMode, + FeatureUTF8Mode, } type Flagger interface { EnableReceiverNamesInMetrics() bool - ClassicMatchersParsing() bool - UTF8MatchersParsing() bool + ClassicMode() bool + UTF8Mode() bool } type Flags struct { logger log.Logger enableReceiverNamesInMetrics bool - classicMatchersParsing bool - utf8MatchersParsing bool + classicMode bool + utf8Mode bool } func (f *Flags) EnableReceiverNamesInMetrics() bool { return f.enableReceiverNamesInMetrics } -func (f *Flags) ClassicMatchersParsing() bool { - return f.classicMatchersParsing +func (f *Flags) ClassicMode() bool { + return f.classicMode } -func (f *Flags) UTF8MatchersParsing() bool { - return f.utf8MatchersParsing +func (f *Flags) UTF8Mode() bool { + return f.utf8Mode } type flagOption func(flags *Flags) @@ -67,15 +67,15 @@ func enableReceiverNameInMetrics() flagOption { } } -func enableClassicMatchersParsing() flagOption { +func enableClassicMode() flagOption { return func(configs *Flags) { - configs.classicMatchersParsing = true + configs.classicMode = true } } -func enableUTF8MatchersParsing() flagOption { +func enableUTF8Mode() flagOption { return func(configs *Flags) { - configs.utf8MatchersParsing = true + configs.utf8Mode = true } } @@ -89,15 +89,15 @@ func NewFlags(logger log.Logger, features string) (Flagger, error) { for _, feature := range strings.Split(features, ",") { switch feature { - case fcReceiverNameInMetrics: + case FeatureReceiverNameInMetrics: opts = append(opts, enableReceiverNameInMetrics()) level.Warn(logger).Log("msg", "Experimental receiver name in metrics 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") + case FeatureClassicMode: + opts = append(opts, enableClassicMode()) + level.Warn(logger).Log("msg", "Classic mode enabled") + case FeatureUTF8Mode: + opts = append(opts, enableUTF8Mode()) + level.Warn(logger).Log("msg", "UTF-8 mode enabled") default: return nil, fmt.Errorf("Unknown option '%s' for --enable-feature", feature) } @@ -107,8 +107,8 @@ func NewFlags(logger log.Logger, features string) (Flagger, error) { opt(fc) } - 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") + if fc.classicMode && fc.utf8Mode { + return nil, errors.New("cannot have both classic and UTF-8 modes enabled") } return fc, nil @@ -118,6 +118,6 @@ type NoopFlags struct{} func (n NoopFlags) EnableReceiverNamesInMetrics() bool { return false } -func (n NoopFlags) ClassicMatchersParsing() bool { return false } +func (n NoopFlags) ClassicMode() bool { return false } -func (n NoopFlags) UTF8MatchersParsing() bool { return false } +func (n NoopFlags) UTF8Mode() bool { return false } diff --git a/featurecontrol/featurecontrol_test.go b/featurecontrol/featurecontrol_test.go index 1008ac8808..913cc3851b 100644 --- a/featurecontrol/featurecontrol_test.go +++ b/featurecontrol/featurecontrol_test.go @@ -30,7 +30,7 @@ func TestFlags(t *testing.T) { }{ { name: "with only valid feature flags", - featureFlags: fcReceiverNameInMetrics, + featureFlags: FeatureReceiverNameInMetrics, }, { name: "with only invalid feature flags", @@ -39,7 +39,7 @@ func TestFlags(t *testing.T) { }, { name: "with both, valid and invalid feature flags", - featureFlags: strings.Join([]string{fcReceiverNameInMetrics, "somethingbad"}, ","), + featureFlags: strings.Join([]string{FeatureReceiverNameInMetrics, "somethingbad"}, ","), err: errors.New("Unknown option 'somethingbad' for --enable-feature"), }, } diff --git a/matchers/compat/parse.go b/matchers/compat/parse.go index 1e8758b1ce..fc606dcae2 100644 --- a/matchers/compat/parse.go +++ b/matchers/compat/parse.go @@ -48,10 +48,10 @@ 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.ClassicMatchersParsing() { + if f.ClassicMode() { parseMatcher = classicMatcherParser(l) parseMatchers = classicMatchersParser(l) - } else if f.UTF8MatchersParsing() { + } else if f.UTF8Mode() { parseMatcher = utf8MatcherParser(l) parseMatchers = utf8MatchersParser(l) } else {