mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-04 00:51:02 +01:00
Merge pull request #17372 from roidelapluie/roidelapluie/relabeling
relabeling: Fix labelmap action validation with legacy metric name scheme
This commit is contained in:
commit
34360d3068
@ -145,7 +145,13 @@ func (c *Config) Validate(nameValidationScheme model.ValidationScheme) error {
|
|||||||
// UTF-8 allows ${} characters, so standard validation allow $variables by default.
|
// UTF-8 allows ${} characters, so standard validation allow $variables by default.
|
||||||
// TODO(bwplotka): Relabelling users cannot put $ and ${<...>} characters in metric names or values.
|
// TODO(bwplotka): Relabelling users cannot put $ and ${<...>} characters in metric names or values.
|
||||||
// Design escaping mechanism to allow that, once valid use case appears.
|
// Design escaping mechanism to allow that, once valid use case appears.
|
||||||
|
switch c.NameValidationScheme {
|
||||||
|
case model.UTF8Validation:
|
||||||
return c.NameValidationScheme.IsValidLabelName(value)
|
return c.NameValidationScheme.IsValidLabelName(value)
|
||||||
|
default:
|
||||||
|
// For legacy validation, use the legacy regex that allows $variables.
|
||||||
|
return relabelTargetLegacy.MatchString(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if c.Action == Replace && varInRegexTemplate(c.TargetLabel) && !isValidLabelNameWithRegexVarFn(c.TargetLabel) {
|
if c.Action == Replace && varInRegexTemplate(c.TargetLabel) && !isValidLabelNameWithRegexVarFn(c.TargetLabel) {
|
||||||
return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action)
|
return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action)
|
||||||
|
|||||||
@ -831,6 +831,22 @@ func TestRelabelValidate(t *testing.T) {
|
|||||||
NameValidationScheme: model.UTF8Validation,
|
NameValidationScheme: model.UTF8Validation,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
config: Config{
|
||||||
|
Regex: MustNewRegexp("__meta_kubernetes_pod_label_(strimzi_io_.+)"),
|
||||||
|
Action: LabelMap,
|
||||||
|
Replacement: "$1",
|
||||||
|
NameValidationScheme: model.LegacyValidation,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: Config{
|
||||||
|
Regex: MustNewRegexp("__meta_(.+)"),
|
||||||
|
Action: LabelMap,
|
||||||
|
Replacement: "${1}",
|
||||||
|
NameValidationScheme: model.LegacyValidation,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user