From 30af43c4c0b704c1472bc760623cc7e6f7573c58 Mon Sep 17 00:00:00 2001 From: Thor Date: Wed, 23 Sep 2026 13:28:40 -0500 Subject: [PATCH] Fix relable configs validation scheme not being set. Add regression test. --- pkg/config/config.go | 3 +++ pkg/config/config_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index ed2753e0241..1e924f470d0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -253,6 +253,9 @@ func (c *ScrapeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if rlcfg == nil { return errors.New("empty or null target relabeling rule in scrape config") } + if err := rlcfg.Validate(model.UTF8Validation); err != nil { + return err + } } // Validate the scrape and timeout internal configuration. When /debug/pprof/profile scraping diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 06c41ea45b8..2568a125226 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -19,6 +19,8 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/discovery" + "github.com/prometheus/prometheus/model/labels" + "github.com/prometheus/prometheus/model/relabel" "github.com/stretchr/testify/require" "github.com/thanos-io/objstore/client" ) @@ -35,6 +37,34 @@ func TestLoad(t *testing.T) { } } +// TestLoadRelabelConfigNameValidationScheme is a regression test for a panic +// ("Invalid name validation scheme requested: unset") that occurred because +// parsed relabel configs never had their NameValidationScheme populated, +// leaving it at the zero value (model.UnsetValidation). +func TestLoadRelabelConfigNameValidationScheme(t *testing.T) { + t.Parallel() + + cfg, err := Load(`scrape_configs: +- job_name: 'test' + static_configs: + - targets: ['localhost:8080'] + relabel_configs: + - source_labels: ['__meta_foo'] + regex: '(.+)' + target_label: '__meta_${1}' + replacement: 'bar' + action: replace`) + require.NoError(t, err) + require.Len(t, cfg.ScrapeConfigs, 1) + require.Len(t, cfg.ScrapeConfigs[0].RelabelConfigs, 1) + require.Equal(t, model.UTF8Validation, cfg.ScrapeConfigs[0].RelabelConfigs[0].NameValidationScheme) + + lb := labels.NewBuilder(labels.FromStrings("__meta_foo", "extra")) + require.NotPanics(t, func() { + relabel.ProcessBuilder(lb, cfg.ScrapeConfigs[0].RelabelConfigs...) + }) +} + func TestLoadComplex(t *testing.T) { t.Parallel()