-
Notifications
You must be signed in to change notification settings - Fork 818
Added name validation scheme as a config field and flag as well #6733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
// } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default value should be Let's call the flag |
||
|
||
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" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just import and use the string constants from Prometheus https://github.com/prometheus/prometheus/blob/ba4b058b7ab60105e03f83380cc3200a8a66e52f/config/config.go#L72 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to also handle the case where |
||
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") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just remove this file and its parent folder