Skip to content
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

Check that metric_relabel_configs has non-nil configuration in runtime config #3868

Merged
merged 2 commits into from
Jan 9, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* [BUGFIX] Update `github.com/thanos-io/objstore` to address issue with Multipart PUT on s3-compatible Object Storage. #3802 #3821
* [BUGFIX] Distributor, Query-scheduler: Make sure ring metrics include a `cortex_` prefix as expected by dashboards. #3809
* [BUGFIX] Querier: canceled requests are no longer reported as "consistency check" failures. #3837
* [BUGFIX] Distributor: don't panic when `metric_relabel_configs` in overrides contains null element. #3868

### Mixin

Expand Down
12 changes: 11 additions & 1 deletion pkg/util/validation/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (l *Limits) UnmarshalYAML(value *yaml.Node) error {
return err
}

return nil
return l.validate()
}

// UnmarshalJSON implements the json.Unmarshaler interface.
Expand All @@ -295,6 +295,16 @@ func (l *Limits) UnmarshalJSON(data []byte) error {
return err
}

return l.validate()
}

func (l *Limits) validate() error {
for _, cfg := range l.MetricRelabelConfigs {
if cfg == nil {
return fmt.Errorf("invalid metric_relabel_configs")
}
}

return nil
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/util/validation/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,22 @@ func TestCustomTrackerConfigDeserialize(t *testing.T) {
assert.False(t, overrides["user"].ActiveSeriesCustomTrackersConfig.Empty())
assert.Equal(t, expectedConfig.String(), overrides["user"].ActiveSeriesCustomTrackersConfig.String())
}

func TestUnmarshalInvalidMetricRelabelConfig(t *testing.T) {
t.Run("yaml", func(t *testing.T) {
limits := Limits{}
cfg := `
metric_relabel_configs:
-
`
err := yaml.Unmarshal([]byte(cfg), &limits)
require.ErrorContains(t, err, "invalid metric_relabel_configs")
})

t.Run("json", func(t *testing.T) {
limits := Limits{}
cfg := `{"metric_relabel_configs": [null]}`
err := json.Unmarshal([]byte(cfg), &limits)
require.ErrorContains(t, err, "invalid metric_relabel_configs")
})
}