Skip to content

Commit 35aeae6

Browse files
committed
fix: adjust tests for missing default in relabel config; set default relabel validation scheme when unmarshaling limits
1 parent 250cdf2 commit 35aeae6

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

pkg/distributor/distributor_test.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5342,11 +5342,12 @@ func TestRelabelMiddleware(t *testing.T) {
53425342
ctx: ctxWithUser,
53435343
relabelConfigs: []*relabel.Config{
53445344
{
5345-
SourceLabels: []model.LabelName{"label1"},
5346-
Action: relabel.DefaultRelabelConfig.Action,
5347-
Regex: relabel.DefaultRelabelConfig.Regex,
5348-
TargetLabel: "target",
5349-
Replacement: "prefix_$1",
5345+
SourceLabels: []model.LabelName{"label1"},
5346+
Action: relabel.DefaultRelabelConfig.Action,
5347+
Regex: relabel.DefaultRelabelConfig.Regex,
5348+
TargetLabel: "target",
5349+
Replacement: "prefix_$1",
5350+
MetricNameValidationScheme: model.UTF8Validation,
53505351
},
53515352
},
53525353
relabelingEnabled: true,
@@ -5376,11 +5377,12 @@ func TestRelabelMiddleware(t *testing.T) {
53765377
ctx: ctxWithUser,
53775378
relabelConfigs: []*relabel.Config{
53785379
{
5379-
SourceLabels: []model.LabelName{metaLabelTenantID},
5380-
Action: relabel.DefaultRelabelConfig.Action,
5381-
Regex: relabel.DefaultRelabelConfig.Regex,
5382-
TargetLabel: "tenant_id",
5383-
Replacement: "$1",
5380+
SourceLabels: []model.LabelName{metaLabelTenantID},
5381+
Action: relabel.DefaultRelabelConfig.Action,
5382+
Regex: relabel.DefaultRelabelConfig.Regex,
5383+
TargetLabel: "tenant_id",
5384+
Replacement: "$1",
5385+
MetricNameValidationScheme: model.UTF8Validation,
53845386
},
53855387
},
53865388
relabelingEnabled: true,
@@ -7468,11 +7470,12 @@ func TestDistributor_Push_Relabel(t *testing.T) {
74687470
expectedSeries: labelAdapters("__name__", "foo", "cluster", "two"),
74697471
metricRelabelConfigs: []*relabel.Config{
74707472
{
7471-
SourceLabels: []model.LabelName{"cluster"},
7472-
Action: relabel.DefaultRelabelConfig.Action,
7473-
Regex: relabel.DefaultRelabelConfig.Regex,
7474-
TargetLabel: "cluster",
7475-
Replacement: "two",
7473+
SourceLabels: []model.LabelName{"cluster"},
7474+
Action: relabel.DefaultRelabelConfig.Action,
7475+
Regex: relabel.DefaultRelabelConfig.Regex,
7476+
TargetLabel: "cluster",
7477+
Replacement: "two",
7478+
MetricNameValidationScheme: model.UTF8Validation,
74767479
},
74777480
},
74787481
},

pkg/util/validation/limits.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,16 @@ func (l *Limits) unmarshal(decode func(any) error) error {
525525
}
526526
l.extensions = getExtensions()
527527

528+
// Set relabel config name validation scheme to match the requested validation scheme for this tenant.
529+
for _, relabelCfg := range l.MetricRelabelConfigs {
530+
if relabelCfg == nil {
531+
continue
532+
}
533+
// TODO: for now this is hard coded, but will change when Limits correctly stores
534+
// a setting for controlling validation scheme.
535+
relabelCfg.MetricNameValidationScheme = model.LegacyValidation
536+
}
537+
528538
return l.validate()
529539
}
530540

pkg/util/validation/limits_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ metric_relabel_configs:
159159
`
160160
exp := relabel.DefaultRelabelConfig
161161
exp.Action = relabel.Drop
162+
exp.MetricNameValidationScheme = model.LegacyValidation
162163
regex, err := relabel.NewRegexp(".+")
163164
require.NoError(t, err)
164165
exp.Regex = regex

0 commit comments

Comments
 (0)