@@ -14,6 +14,7 @@ import (
14
14
"github.com/go-kit/log/level"
15
15
"github.com/pkg/errors"
16
16
"github.com/prometheus/client_golang/prometheus"
17
+ "github.com/prometheus/common/model"
17
18
"github.com/prometheus/prometheus/promql"
18
19
prom_storage "github.com/prometheus/prometheus/storage"
19
20
"github.com/weaveworks/common/server"
@@ -90,11 +91,12 @@ var (
90
91
91
92
// Config is the root config for Cortex.
92
93
type 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"`
98
100
99
101
ExternalQueryable prom_storage.Queryable `yaml:"-"`
100
102
ExternalPusher ruler.Pusher `yaml:"-"`
@@ -146,6 +148,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
146
148
f .BoolVar (& c .AuthEnabled , "auth.enabled" , true , "Set to false to disable auth." )
147
149
f .BoolVar (& c .PrintConfig , "print.config" , false , "Print the config and exit." )
148
150
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" )
149
152
150
153
c .MonitoredResources = []string {}
151
154
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 {
193
196
return errInvalidHTTPPrefix
194
197
}
195
198
199
+ if c .NameValidationScheme != "" && c .NameValidationScheme != "legacy" && c .NameValidationScheme != "utf-8" {
200
+ return fmt .Errorf ("invalid name validation scheme" )
201
+ }
202
+
196
203
if err := c .API .Validate (); err != nil {
197
204
return errors .Wrap (err , "invalid api config" )
198
205
}
@@ -361,6 +368,13 @@ func New(cfg Config) (*Cortex, error) {
361
368
os .Exit (0 )
362
369
}
363
370
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
+
364
378
// Swap out the default resolver to support multiple tenant IDs separated by a '|'
365
379
if cfg .TenantFederation .Enabled {
366
380
util_log .WarnExperimentalUse ("tenant-federation" )
0 commit comments