-
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?
Added name validation scheme as a config field and flag as well #6733
Conversation
Signed-off-by: Abhishek Anand <[email protected]>
2186312
to
146188f
Compare
I am working on the tests for this. |
Signed-off-by: Abhishek Anand <[email protected]>
Added test for name validation scheme in |
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.
Thanks @av153k. Great work and I think it is on the right track. Just few comments
pkg/cortex/cortex.go
Outdated
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
We need to also handle the case where c.NameValidationScheme
is empty and we should use the legacy scheme
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.
The empty case will be handled when we create a new context object as you can see later on in the file.
And in the validation, it does check for non-empty string to validate so I think that will pass as well. Let me know if I need to add something else as well.
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.
I have made the changes and allowed for legacy to be used by default in method to create a new cortex object.
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 unify the code to make it cleaner. You can just use a single switch statement.
switch c.NameValidationScheme {
case "", prom_config.LegacyValidationConfig:
model.NameValidationScheme = model.LegacyValidation
case prom_config.UTF8ValidationConfig:
model.NameValidationScheme = model.UTF8Validation
default:
// return invalid error
}
pkg/cortex/cortex.go
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
The default value should be legacy
instead of strict
.
Let's call the flag name.validation_scheme
.
For flag description, let's make it easier for users to understand. How about Validation scheme for metric and label names. Set to utf8 to allow UTF-8 characters.
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.
Fixed this in the latest commit.
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.
You need to regenerate the doc after updating flag description
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.
I made the changes to the doc config-file-reference.md but missed including it in the commit. I am assuming you mean that, or is there any command to generate the docs automatically?
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.
If you do make docs
it can generate docs automatically
…andled empty name validation scheme and related tests Signed-off-by: Abhishek Anand <[email protected]>
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.
Can you also update changelog?
pkg/cortex/cortex_test.go
Outdated
name: "should not fail validation for utf-8 name validation scheme", | ||
getTestConfig: func() *Config { | ||
configuration := newDefaultConfig() | ||
configuration.NameValidationScheme = "utf-8" |
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 use const here
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.
const as in from prometheus config, right?
pkg/cortex/cortex_test.go
Outdated
name: "should not fail validation for legacy name validation scheme", | ||
getTestConfig: func() *Config { | ||
configuration := newDefaultConfig() | ||
configuration.NameValidationScheme = "legacy" |
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 use const here
pkg/cortex/cortex_test.go
Outdated
expectedError: nil, | ||
}, | ||
{ | ||
name: "should fail validation for invalid(anything other than legacy and utf-8) name validation scheme", |
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.
You can just say should fail validation for invalid name validation scheme
. No need to mention legacy and utf8
What would be the version of this change, though? |
… in the config file and CLI flag, along with corresponding tests. Signed-off-by: Abhishek Anand <[email protected]>
// Setting name validation scheme as legacy if provided with an empty string | ||
if c.NameValidationScheme == "" { | ||
c.NameValidationScheme = prom_config.LegacyValidationConfig | ||
} |
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.
We can remove this code now as it will be handled in the switch statement
@@ -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") | |||
} |
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.
We can remove this code now as it will be handled in the switch statement
@@ -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`) |
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 move the changelog entry to L14. Features
are put together
What this PR does:
name_validation_scheme
as yaml flag andname.validation.scheme
as a flagWhich issue(s) this PR fixes:
Fixes #6702
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]