-
Notifications
You must be signed in to change notification settings - Fork 828
feat: 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 4 commits
146188f
2d7737b
9e161d9
c5acc77
196306c
29b7231
f52a715
d1e117e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ import ( | |
"github.com/go-kit/log/level" | ||
"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" | ||
"github.com/weaveworks/common/server" | ||
|
@@ -31,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" | ||
|
@@ -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,12 @@ 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", 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 | ||
} | ||
yeya24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
c.MonitoredResources = []string{} | ||
f.Var(&c.MonitoredResources, "monitored.resources", "Comma-separated list of resources to monitor. "+ | ||
|
@@ -193,6 +201,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 fmt.Errorf("invalid name validation scheme") | ||
} | ||
yeya24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if err := c.API.Validate(); err != nil { | ||
return errors.Wrap(err, "invalid api config") | ||
} | ||
|
@@ -361,6 +373,16 @@ func New(cfg Config) (*Cortex, error) { | |
os.Exit(0) | ||
} | ||
|
||
// Sets the NameValidationScheme in prometheus/common | ||
switch cfg.NameValidationScheme { | ||
case "", prom_config.LegacyValidationConfig: | ||
model.NameValidationScheme = model.LegacyValidation | ||
case prom_config.UTF8ValidationConfig: | ||
model.NameValidationScheme = model.UTF8Validation | ||
default: | ||
fmt.Errorf("invalid name validation scheme") | ||
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. This needs to be returned 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. Okay. I will add that. Anything else apart from this? Also after this is done, can you please point me to a few issues that you think I can take up on. Thank you. |
||
} | ||
|
||
// Swap out the default resolver to support multiple tenant IDs separated by a '|' | ||
if cfg.TenantFederation.Enabled { | ||
util_log.WarnExperimentalUse("tenant-federation") | ||
|
Uh oh!
There was an error while loading. Please reload this page.