Skip to content

Commit 00a055e

Browse files
committed
fix panic when the runtime config is null
Signed-off-by: SungJin1212 <[email protected]>
1 parent 5d23973 commit 00a055e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
* [BUGFIX] Runtime-config: Change to check tenant limit validation when loading runtime config only for `all`, `distributor`, `querier`, and `ruler` targets. #6880
102102
* [BUGFIX] Frontend: Fix remote read snappy input due to request string logging when query stats enabled. #7025
103103
* [BUGFIX] Distributor: Fix the `/distributor/all_user_stats` api to work during rolling updates on ingesters. #7026
104+
* [BUGFIX] Runtime-config: Fix panic when the runtime config is `null`. #7062
104105

105106
## 1.19.0 2025-02-27
106107

pkg/cortex/runtime_config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ func (l runtimeConfigLoader) load(r io.Reader) (any, error) {
8585
if strings.Contains(targetStr, target) {
8686
// only check if target is `all`, `distributor`, "querier", and "ruler"
8787
// refer to https://github.com/cortexproject/cortex/issues/6741#issuecomment-3067244929
88-
for _, ul := range overrides.TenantLimits {
89-
if err := ul.Validate(l.cfg.Distributor.ShardByAllLabels, l.cfg.Ingester.ActiveSeriesMetricsEnabled); err != nil {
90-
return nil, err
88+
if overrides != nil {
89+
for _, ul := range overrides.TenantLimits {
90+
if err := ul.Validate(l.cfg.Distributor.ShardByAllLabels, l.cfg.Ingester.ActiveSeriesMetricsEnabled); err != nil {
91+
return nil, err
92+
}
9193
}
9294
}
9395
}

pkg/cortex/runtime_config_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ import (
1212
"github.com/cortexproject/cortex/pkg/util/validation"
1313
)
1414

15+
func TestLoadRuntimeConfig_ShouldNoPanicWhenNull(t *testing.T) {
16+
yamlFile := strings.NewReader(`
17+
null
18+
`)
19+
20+
loader := runtimeConfigLoader{cfg: Config{Target: []string{All}}}
21+
_, err := loader.load(yamlFile)
22+
require.NoError(t, err)
23+
}
24+
1525
// Given limits are usually loaded via a config file, and that
1626
// a configmap is limited to 1MB, we need to minimise the limits file.
1727
// One way to do it is via YAML anchors.

0 commit comments

Comments
 (0)