Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion model/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ func (c *Config) Validate(nameValidationScheme model.ValidationScheme) error {
// UTF-8 allows ${} characters, so standard validation allow $variables by default.
// TODO(bwplotka): Relabelling users cannot put $ and ${<...>} characters in metric names or values.
// Design escaping mechanism to allow that, once valid use case appears.
return c.NameValidationScheme.IsValidLabelName(value)
switch c.NameValidationScheme {
case model.UTF8Validation:
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) {
return fmt.Errorf("%q is invalid 'target_label' for %s action", c.TargetLabel, c.Action)
Expand Down
16 changes: 16 additions & 0 deletions model/relabel/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,22 @@ func TestRelabelValidate(t *testing.T) {
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 {
t.Run(strconv.Itoa(i), func(t *testing.T) {
Expand Down
Loading