From 146188f66bc059aca479bb0d9c170a9b400cfb03 Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Thu, 8 May 2025 12:26:25 +0530 Subject: [PATCH 1/8] Added name validation scheme as a config field and flag as well Signed-off-by: Abhishek Anand --- docs/configuration/config-file-reference.md | 5 +++++ pkg/cortex/configinit/init.go | 8 +++---- pkg/cortex/cortex.go | 24 ++++++++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index 93293edf82b..815cd623665 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -68,6 +68,11 @@ Where default_value is the value to use if the environment variable is undefined # CLI flag: -http.prefix [http_prefix: | default = "/api/prom"] +# NameValidationScheme for prometheus +# Set to legacy as default +# CLI flag: -name.validation.scheme +[name_validation_scheme: | default = "legacy"] + # Comma-separated list of resources to monitor. Supported values are cpu and # heap, which tracks metrics from github.com/prometheus/procfs and # runtime/metrics that are close estimates. Empty string to disable. diff --git a/pkg/cortex/configinit/init.go b/pkg/cortex/configinit/init.go index 1c16f75eea1..c1b56e936e6 100644 --- a/pkg/cortex/configinit/init.go +++ b/pkg/cortex/configinit/init.go @@ -1,7 +1,7 @@ package configinit -import "github.com/prometheus/common/model" +// import "github.com/prometheus/common/model" -func init() { - model.NameValidationScheme = model.LegacyValidation -} +// func init() { +// model.NameValidationScheme = model.LegacyValidation +// } diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index 255c9c238a4..f2eb65c2498 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -14,6 +14,7 @@ import ( "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/common/model" "github.com/prometheus/prometheus/promql" prom_storage "github.com/prometheus/prometheus/storage" "github.com/weaveworks/common/server" @@ -90,11 +91,12 @@ var ( // Config is the root config for Cortex. type Config struct { - Target flagext.StringSliceCSV `yaml:"target"` - AuthEnabled bool `yaml:"auth_enabled"` - PrintConfig bool `yaml:"-"` - HTTPPrefix string `yaml:"http_prefix"` - MonitoredResources flagext.StringSliceCSV `yaml:"monitored_resources"` + Target flagext.StringSliceCSV `yaml:"target"` + AuthEnabled bool `yaml:"auth_enabled"` + PrintConfig bool `yaml:"-"` + HTTPPrefix string `yaml:"http_prefix"` + NameValidationScheme string `yaml:"name_validation_scheme"` + MonitoredResources flagext.StringSliceCSV `yaml:"monitored_resources"` ExternalQueryable prom_storage.Queryable `yaml:"-"` ExternalPusher ruler.Pusher `yaml:"-"` @@ -146,6 +148,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { f.BoolVar(&c.AuthEnabled, "auth.enabled", true, "Set to false to disable auth.") f.BoolVar(&c.PrintConfig, "print.config", false, "Print the config and exit.") f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.") + f.StringVar(&c.NameValidationScheme, "name.validation.scheme", "strict", "Used to set name validation scheme in prometheus common. legacy by default") c.MonitoredResources = []string{} f.Var(&c.MonitoredResources, "monitored.resources", "Comma-separated list of resources to monitor. "+ @@ -193,6 +196,10 @@ func (c *Config) Validate(log log.Logger) error { return errInvalidHTTPPrefix } + if c.NameValidationScheme != "" && c.NameValidationScheme != "legacy" && c.NameValidationScheme != "utf-8" { + return fmt.Errorf("invalid name validation scheme") + } + if err := c.API.Validate(); err != nil { return errors.Wrap(err, "invalid api config") } @@ -361,6 +368,13 @@ func New(cfg Config) (*Cortex, error) { os.Exit(0) } + // Sets the NameValidationScheme in prometheus/common + if cfg.NameValidationScheme != "legacy" { + model.NameValidationScheme = model.LegacyValidation + } else { + model.NameValidationScheme = model.UTF8Validation + } + // Swap out the default resolver to support multiple tenant IDs separated by a '|' if cfg.TenantFederation.Enabled { util_log.WarnExperimentalUse("tenant-federation") From 2d7737bdacc7b6f14b475540a29b751e84b738d8 Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Sat, 10 May 2025 19:18:36 +0530 Subject: [PATCH 2/8] Added tests for name validation scheme Signed-off-by: Abhishek Anand --- pkg/cortex/cortex_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/cortex/cortex_test.go b/pkg/cortex/cortex_test.go index 74bf0750a33..cde8c4dd20b 100644 --- a/pkg/cortex/cortex_test.go +++ b/pkg/cortex/cortex_test.go @@ -184,6 +184,42 @@ func TestConfigValidation(t *testing.T) { }, expectedError: nil, }, + // NameValidationScheme tests + { + name: "should not fail validation for empty name validation scheme", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + return configuration + }, + expectedError: nil, + }, + { + name: "should not fail validation for legacy name validation scheme", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + configuration.NameValidationScheme = "legacy" + return configuration + }, + expectedError: nil, + }, + { + name: "should not fail validation for utf-8 name validation scheme", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + configuration.NameValidationScheme = "utf-8" + return configuration + }, + expectedError: nil, + }, + { + name: "should fail validation for invalid(anything other than legacy and utf-8) name validation scheme", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + configuration.NameValidationScheme = "invalid" + return configuration + }, + expectedError: fmt.Errorf("invalid name validation scheme"), + }, } { t.Run(tc.name, func(t *testing.T) { err := tc.getTestConfig().Validate(nil) From 9e161d93835feabd6e0469c4b9a04dbfa364fd2d Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Sun, 11 May 2025 10:41:53 +0530 Subject: [PATCH 3/8] Removed configinit, replaces string with constants from prometheus, handled empty name validation scheme and related tests Signed-off-by: Abhishek Anand --- pkg/cortex/configinit/init.go | 7 ------- pkg/cortex/cortex.go | 13 ++++++++++--- pkg/cortex/cortex_test.go | 3 ++- pkg/distributor/distributor_test.go | 1 - pkg/util/validation/validate_test.go | 1 - 5 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 pkg/cortex/configinit/init.go diff --git a/pkg/cortex/configinit/init.go b/pkg/cortex/configinit/init.go deleted file mode 100644 index c1b56e936e6..00000000000 --- a/pkg/cortex/configinit/init.go +++ /dev/null @@ -1,7 +0,0 @@ -package configinit - -// import "github.com/prometheus/common/model" - -// func init() { -// model.NameValidationScheme = model.LegacyValidation -// } diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index f2eb65c2498..fa80f3d549b 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -17,6 +17,7 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/promql" prom_storage "github.com/prometheus/prometheus/storage" + prom_config "github.com/prometheus/prometheus/config" "github.com/weaveworks/common/server" "github.com/weaveworks/common/signals" "google.golang.org/grpc/health/grpc_health_v1" @@ -32,7 +33,6 @@ import ( "github.com/cortexproject/cortex/pkg/configs" configAPI "github.com/cortexproject/cortex/pkg/configs/api" "github.com/cortexproject/cortex/pkg/configs/db" - _ "github.com/cortexproject/cortex/pkg/cortex/configinit" "github.com/cortexproject/cortex/pkg/cortex/storage" "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/cortexproject/cortex/pkg/distributor" @@ -66,6 +66,7 @@ import ( "github.com/cortexproject/cortex/pkg/util/runtimeconfig" "github.com/cortexproject/cortex/pkg/util/services" "github.com/cortexproject/cortex/pkg/util/validation" + ) var ( @@ -148,7 +149,13 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { f.BoolVar(&c.AuthEnabled, "auth.enabled", true, "Set to false to disable auth.") f.BoolVar(&c.PrintConfig, "print.config", false, "Print the config and exit.") f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.") - f.StringVar(&c.NameValidationScheme, "name.validation.scheme", "strict", "Used to set name validation scheme in prometheus common. legacy by default") + f.StringVar(&c.NameValidationScheme, "name.validation_scheme", prom_config.LegacyValidationConfig, "Validation scheme for metric and label names. Set to utf8 to allow UTF-8 characters. legacy by default") + + + // Setting name validation scheme as legacy if provided with an empty string + if (c.NameValidationScheme == "") { + c.NameValidationScheme = prom_config.LegacyValidationConfig + } c.MonitoredResources = []string{} f.Var(&c.MonitoredResources, "monitored.resources", "Comma-separated list of resources to monitor. "+ @@ -196,7 +203,7 @@ func (c *Config) Validate(log log.Logger) error { return errInvalidHTTPPrefix } - if c.NameValidationScheme != "" && c.NameValidationScheme != "legacy" && c.NameValidationScheme != "utf-8" { + if c.NameValidationScheme != "" && c.NameValidationScheme != prom_config.LegacyValidationConfig && c.NameValidationScheme != prom_config.UTF8ValidationConfig { return fmt.Errorf("invalid name validation scheme") } diff --git a/pkg/cortex/cortex_test.go b/pkg/cortex/cortex_test.go index cde8c4dd20b..afb7a60a592 100644 --- a/pkg/cortex/cortex_test.go +++ b/pkg/cortex/cortex_test.go @@ -186,9 +186,10 @@ func TestConfigValidation(t *testing.T) { }, // NameValidationScheme tests { - name: "should not fail validation for empty name validation scheme", + name: "should not fail validation for empty name validation scheme (use legacy by default)", getTestConfig: func() *Config { configuration := newDefaultConfig() + configuration.NameValidationScheme = "" return configuration }, expectedError: nil, diff --git a/pkg/distributor/distributor_test.go b/pkg/distributor/distributor_test.go index 3618f285fee..42bfdb19eef 100644 --- a/pkg/distributor/distributor_test.go +++ b/pkg/distributor/distributor_test.go @@ -35,7 +35,6 @@ import ( "google.golang.org/grpc/status" promchunk "github.com/cortexproject/cortex/pkg/chunk/encoding" - _ "github.com/cortexproject/cortex/pkg/cortex/configinit" "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/cortexproject/cortex/pkg/ha" "github.com/cortexproject/cortex/pkg/ingester" diff --git a/pkg/util/validation/validate_test.go b/pkg/util/validation/validate_test.go index 6b3c15fca78..80eff186912 100644 --- a/pkg/util/validation/validate_test.go +++ b/pkg/util/validation/validate_test.go @@ -16,7 +16,6 @@ import ( "github.com/stretchr/testify/require" "github.com/weaveworks/common/httpgrpc" - _ "github.com/cortexproject/cortex/pkg/cortex/configinit" "github.com/cortexproject/cortex/pkg/cortexpb" util_log "github.com/cortexproject/cortex/pkg/util/log" ) From c5acc7783edee453fe9301aa1c6077d4c8fb4bee Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Sun, 11 May 2025 20:06:15 +0530 Subject: [PATCH 4/8] Added name validation scheme configuration for metric and label names in the config file and CLI flag, along with corresponding tests. Signed-off-by: Abhishek Anand --- CHANGELOG.md | 1 + docs/configuration/config-file-reference.md | 4 ++-- pkg/cortex/cortex.go | 13 +++++++------ pkg/cortex/cortex_test.go | 9 +++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bdc480d88d..8b65e68a85a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ * [BUGFIX] Querier: Fix panic when marshaling QueryResultRequest. #6601 * [BUGFIX] Ingester: Avoid resharding for query when restart readonly ingesters. #6642 * [BUGFIX] Query Frontend: Fix query frontend per `user` metrics clean up. #6698 +* [FEATURE] Config: Name validation scheme for metric and label names can be set using the config file (`name_validation_scheme`) as well as a CLI flag (`-name.validation_scheme`) ## 1.19.0 2025-02-27 diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index 815cd623665..85518287c8e 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -68,9 +68,9 @@ Where default_value is the value to use if the environment variable is undefined # CLI flag: -http.prefix [http_prefix: | default = "/api/prom"] -# NameValidationScheme for prometheus +# Validation scheme for metric and label names. Set to utf8 to allow UTF-8 characters. # Set to legacy as default -# CLI flag: -name.validation.scheme +# CLI flag: -name.validation_scheme [name_validation_scheme: | default = "legacy"] # Comma-separated list of resources to monitor. Supported values are cpu and diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index fa80f3d549b..c6e79e6364a 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -15,9 +15,9 @@ import ( "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" + prom_config "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/promql" prom_storage "github.com/prometheus/prometheus/storage" - prom_config "github.com/prometheus/prometheus/config" "github.com/weaveworks/common/server" "github.com/weaveworks/common/signals" "google.golang.org/grpc/health/grpc_health_v1" @@ -66,7 +66,6 @@ import ( "github.com/cortexproject/cortex/pkg/util/runtimeconfig" "github.com/cortexproject/cortex/pkg/util/services" "github.com/cortexproject/cortex/pkg/util/validation" - ) var ( @@ -151,9 +150,8 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.") f.StringVar(&c.NameValidationScheme, "name.validation_scheme", prom_config.LegacyValidationConfig, "Validation scheme for metric and label names. Set to utf8 to allow UTF-8 characters. legacy by default") - // Setting name validation scheme as legacy if provided with an empty string - if (c.NameValidationScheme == "") { + if c.NameValidationScheme == "" { c.NameValidationScheme = prom_config.LegacyValidationConfig } @@ -376,10 +374,13 @@ func New(cfg Config) (*Cortex, error) { } // Sets the NameValidationScheme in prometheus/common - if cfg.NameValidationScheme != "legacy" { + switch cfg.NameValidationScheme { + case "", prom_config.LegacyValidationConfig: model.NameValidationScheme = model.LegacyValidation - } else { + case prom_config.UTF8ValidationConfig: model.NameValidationScheme = model.UTF8Validation + default: + fmt.Errorf("invalid name validation scheme") } // Swap out the default resolver to support multiple tenant IDs separated by a '|' diff --git a/pkg/cortex/cortex_test.go b/pkg/cortex/cortex_test.go index afb7a60a592..16128b47771 100644 --- a/pkg/cortex/cortex_test.go +++ b/pkg/cortex/cortex_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" + prom_config "github.com/prometheus/prometheus/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/weaveworks/common/server" @@ -184,7 +185,7 @@ func TestConfigValidation(t *testing.T) { }, expectedError: nil, }, - // NameValidationScheme tests + // NameValidationScheme tests { name: "should not fail validation for empty name validation scheme (use legacy by default)", getTestConfig: func() *Config { @@ -198,7 +199,7 @@ func TestConfigValidation(t *testing.T) { name: "should not fail validation for legacy name validation scheme", getTestConfig: func() *Config { configuration := newDefaultConfig() - configuration.NameValidationScheme = "legacy" + configuration.NameValidationScheme = prom_config.LegacyValidationConfig return configuration }, expectedError: nil, @@ -207,13 +208,13 @@ func TestConfigValidation(t *testing.T) { name: "should not fail validation for utf-8 name validation scheme", getTestConfig: func() *Config { configuration := newDefaultConfig() - configuration.NameValidationScheme = "utf-8" + configuration.NameValidationScheme = prom_config.UTF8ValidationConfig return configuration }, expectedError: nil, }, { - name: "should fail validation for invalid(anything other than legacy and utf-8) name validation scheme", + name: "should fail validation for invalid name validation scheme", getTestConfig: func() *Config { configuration := newDefaultConfig() configuration.NameValidationScheme = "invalid" From 196306c83a00964101df4d75aff24c5af6ab1b0b Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Mon, 12 May 2025 10:53:33 +0530 Subject: [PATCH 5/8] Fixed changelog and remove redundant code Signed-off-by: Abhishek Anand --- CHANGELOG.md | 3 ++- pkg/cortex/cortex.go | 8 -------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b65e68a85a..5cae298ab77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [FEATURE] Ruler: Add support for percentage based sharding for rulers. #6680 * [FEATURE] Ruler: Add support for group labels. #6665 * [FEATURE] Support Parquet format: Implement parquet converter service to convert a TSDB block into Parquet. #6716 +* [FEATURE] Config: Name validation scheme for metric and label names can be set using the config file (`name_validation_scheme`) as well as a CLI flag (`-name.validation_scheme`) * [ENHANCEMENT] Query Frontend: Change to return 400 when the tenant resolving fail. #6715 * [ENHANCEMENT] Querier: Support query parameters to metadata api (/api/v1/metadata) to allow user to limit metadata to return. #6681 * [ENHANCEMENT] Ingester: Add a `cortex_ingester_active_native_histogram_series` metric to track # of active NH series. #6695 @@ -39,7 +40,7 @@ * [BUGFIX] Querier: Fix panic when marshaling QueryResultRequest. #6601 * [BUGFIX] Ingester: Avoid resharding for query when restart readonly ingesters. #6642 * [BUGFIX] Query Frontend: Fix query frontend per `user` metrics clean up. #6698 -* [FEATURE] Config: Name validation scheme for metric and label names can be set using the config file (`name_validation_scheme`) as well as a CLI flag (`-name.validation_scheme`) + ## 1.19.0 2025-02-27 diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index c6e79e6364a..6153c946623 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -150,10 +150,6 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.") f.StringVar(&c.NameValidationScheme, "name.validation_scheme", prom_config.LegacyValidationConfig, "Validation scheme for metric and label names. Set to utf8 to allow UTF-8 characters. legacy by default") - // Setting name validation scheme as legacy if provided with an empty string - if c.NameValidationScheme == "" { - c.NameValidationScheme = prom_config.LegacyValidationConfig - } c.MonitoredResources = []string{} f.Var(&c.MonitoredResources, "monitored.resources", "Comma-separated list of resources to monitor. "+ @@ -201,10 +197,6 @@ func (c *Config) Validate(log log.Logger) error { return errInvalidHTTPPrefix } - if c.NameValidationScheme != "" && c.NameValidationScheme != prom_config.LegacyValidationConfig && c.NameValidationScheme != prom_config.UTF8ValidationConfig { - return fmt.Errorf("invalid name validation scheme") - } - if err := c.API.Validate(); err != nil { return errors.Wrap(err, "invalid api config") } From 29b7231b4be909e0c9b86a93f5f10890fedb804d Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Tue, 13 May 2025 11:26:50 +0530 Subject: [PATCH 6/8] returned error for invalid name validation scheme Signed-off-by: Abhishek Anand --- pkg/cortex/cortex.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index 6153c946623..eff84db057b 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -372,7 +372,7 @@ func New(cfg Config) (*Cortex, error) { case prom_config.UTF8ValidationConfig: model.NameValidationScheme = model.UTF8Validation default: - fmt.Errorf("invalid name validation scheme") + return nil, fmt.Errorf("invalid name validation scheme") } // Swap out the default resolver to support multiple tenant IDs separated by a '|' From f52a715ca92c951c8a6f435c2da8b56dda7feada Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Tue, 13 May 2025 15:41:28 +0530 Subject: [PATCH 7/8] formatted cortex.go using gofmt Signed-off-by: Abhishek Anand --- pkg/cortex/cortex.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index eff84db057b..ff281f868f1 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -150,7 +150,6 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.") f.StringVar(&c.NameValidationScheme, "name.validation_scheme", prom_config.LegacyValidationConfig, "Validation scheme for metric and label names. Set to utf8 to allow UTF-8 characters. legacy by default") - c.MonitoredResources = []string{} f.Var(&c.MonitoredResources, "monitored.resources", "Comma-separated list of resources to monitor. "+ "Supported values are cpu and heap, which tracks metrics from github.com/prometheus/procfs and runtime/metrics "+ From d1e117eaa8763891247efab3a19b5bc01103fa0e Mon Sep 17 00:00:00 2001 From: Abhishek Anand Date: Wed, 14 May 2025 08:38:31 +0000 Subject: [PATCH 8/8] Added validation for name validation scheme in config.validate() Signed-off-by: Abhishek Anand --- pkg/cortex/cortex.go | 5 +++++ pkg/cortex/cortex_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index ff281f868f1..c3bf32f0706 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -70,6 +70,7 @@ import ( var ( errInvalidHTTPPrefix = errors.New("HTTP prefix should be empty or start with /") + errInvalidNameValidationScheme = errors.New("Name validation scheme should either be empty, legacy or utf-8") ) // The design pattern for Cortex is a series of config objects, which are @@ -196,6 +197,10 @@ func (c *Config) Validate(log log.Logger) error { return errInvalidHTTPPrefix } + if (c.NameValidationScheme != "" && c.NameValidationScheme != prom_config.LegacyValidationConfig && c.NameValidationScheme != prom_config.UTF8ValidationConfig) { + return errInvalidNameValidationScheme + } + if err := c.API.Validate(); err != nil { return errors.Wrap(err, "invalid api config") } diff --git a/pkg/cortex/cortex_test.go b/pkg/cortex/cortex_test.go index 16128b47771..605d52af9ac 100644 --- a/pkg/cortex/cortex_test.go +++ b/pkg/cortex/cortex_test.go @@ -220,7 +220,7 @@ func TestConfigValidation(t *testing.T) { configuration.NameValidationScheme = "invalid" return configuration }, - expectedError: fmt.Errorf("invalid name validation scheme"), + expectedError: errInvalidNameValidationScheme, }, } { t.Run(tc.name, func(t *testing.T) {