Skip to content

fix: dont panic when schema_config does not exist in the config file #16702

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/loki/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"

"github.com/grafana/dskit/server"
"github.com/grafana/loki/v3/pkg/ingester"
"github.com/grafana/loki/v3/pkg/storage/config"
"github.com/grafana/loki/v3/pkg/storage/types"
"github.com/grafana/loki/v3/pkg/validation"
)

func TestCrossComponentValidation(t *testing.T) {
Expand Down Expand Up @@ -87,6 +89,20 @@ func TestCrossComponentValidation(t *testing.T) {
},
err: true,
},
{
desc: "no schema_config",
base: &Config{
AuthEnabled: false,
Server: server.Config{
HTTPListenPort: 3100,
},
LimitsConfig: validation.Limits{
RejectOldSamples: true,
RejectOldSamplesMaxAge: model.Duration(1),
},
},
err: true,
},
} {
tc.base.RegisterFlags(flag.NewFlagSet(tc.desc, 0))
// This test predates the newer schema required for structured metadata
Expand Down
5 changes: 5 additions & 0 deletions pkg/loki/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func validateBackendAndLegacyReadMode(c *Config) []error {
}

func validateSchemaRequirements(c *Config) []error {
// This error would have already been caught in the SchemaConfig.Validate() function
if len(c.SchemaConfig.Configs) == 0 {
return []error{}
}
Comment on lines +27 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a comment mentioning that the length of c.SchemaConfig.Configs is already validated in the Validate() function of the SchemaConfig itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added the comment


var errs []error
p := config.ActivePeriodConfig(c.SchemaConfig.Configs)

Expand Down
Loading