@@ -14,6 +14,7 @@ import (
1414 "github.com/go-kit/log/level"
1515 "github.com/pkg/errors"
1616 "github.com/prometheus/client_golang/prometheus"
17+ "github.com/prometheus/common/model"
1718 "github.com/prometheus/prometheus/promql"
1819 prom_storage "github.com/prometheus/prometheus/storage"
1920 "github.com/weaveworks/common/server"
@@ -90,11 +91,12 @@ var (
9091
9192// Config is the root config for Cortex.
9293type Config struct {
93- Target flagext.StringSliceCSV `yaml:"target"`
94- AuthEnabled bool `yaml:"auth_enabled"`
95- PrintConfig bool `yaml:"-"`
96- HTTPPrefix string `yaml:"http_prefix"`
97- MonitoredResources flagext.StringSliceCSV `yaml:"monitored_resources"`
94+ Target flagext.StringSliceCSV `yaml:"target"`
95+ AuthEnabled bool `yaml:"auth_enabled"`
96+ PrintConfig bool `yaml:"-"`
97+ HTTPPrefix string `yaml:"http_prefix"`
98+ NameValidationScheme string `yaml:"name_validation_scheme"`
99+ MonitoredResources flagext.StringSliceCSV `yaml:"monitored_resources"`
98100
99101 ExternalQueryable prom_storage.Queryable `yaml:"-"`
100102 ExternalPusher ruler.Pusher `yaml:"-"`
@@ -146,6 +148,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
146148 f .BoolVar (& c .AuthEnabled , "auth.enabled" , true , "Set to false to disable auth." )
147149 f .BoolVar (& c .PrintConfig , "print.config" , false , "Print the config and exit." )
148150 f .StringVar (& c .HTTPPrefix , "http.prefix" , "/api/prom" , "HTTP path prefix for Cortex API." )
151+ f .StringVar (& c .NameValidationScheme , "name.validation.scheme" , "strict" , "Used to set name validation scheme in prometheus common. legacy by default" )
149152
150153 c .MonitoredResources = []string {}
151154 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 {
193196 return errInvalidHTTPPrefix
194197 }
195198
199+ if c .NameValidationScheme != "" && c .NameValidationScheme != "legacy" && c .NameValidationScheme != "utf-8" {
200+ return fmt .Errorf ("invalid name validation scheme" )
201+ }
202+
196203 if err := c .API .Validate (); err != nil {
197204 return errors .Wrap (err , "invalid api config" )
198205 }
@@ -361,6 +368,13 @@ func New(cfg Config) (*Cortex, error) {
361368 os .Exit (0 )
362369 }
363370
371+ // Sets the NameValidationScheme in prometheus/common
372+ if cfg .NameValidationScheme != "legacy" {
373+ model .NameValidationScheme = model .LegacyValidation
374+ } else {
375+ model .NameValidationScheme = model .UTF8Validation
376+ }
377+
364378 // Swap out the default resolver to support multiple tenant IDs separated by a '|'
365379 if cfg .TenantFederation .Enabled {
366380 util_log .WarnExperimentalUse ("tenant-federation" )
0 commit comments