From 8627af119912bdd2ab6667f771b891a1a9629109 Mon Sep 17 00:00:00 2001 From: Owen Diehl Date: Thu, 27 Aug 2020 13:19:50 -0400 Subject: [PATCH] Error on no schema configs (#2564) * ruler jsonnet * jsonnet fixes * errors instead of panics on no schema configs --- pkg/storage/store.go | 4 ++++ pkg/storage/store_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/pkg/storage/store.go b/pkg/storage/store.go index f33471e280f9..ca2941d97590 100644 --- a/pkg/storage/store.go +++ b/pkg/storage/store.go @@ -28,6 +28,7 @@ import ( var ( currentBoltdbShipperNon24HoursErr = errors.New("boltdb-shipper works best with 24h periodic index config. Either add a new config with future date set to 24h to retain the existing index or change the existing config to use 24h period") upcomingBoltdbShipperNon24HoursErr = errors.New("boltdb-shipper with future date must always have periodic config for index set to 24h") + zeroLengthConfigError = errors.New("Must specify at least one schema configuration.") ) // Config is the loki storage configuration @@ -51,6 +52,9 @@ type SchemaConfig struct { // Validate the schema config and returns an error if the validation doesn't pass func (cfg *SchemaConfig) Validate() error { + if len(cfg.Configs) == 0 { + return zeroLengthConfigError + } activePCIndex := ActivePeriodConfig(*cfg) // if current index type is boltdb-shipper and there are no upcoming index types then it should be set to 24 hours. diff --git a/pkg/storage/store_test.go b/pkg/storage/store_test.go index 264e50b040c7..816ace012e51 100644 --- a/pkg/storage/store_test.go +++ b/pkg/storage/store_test.go @@ -918,6 +918,11 @@ func TestSchemaConfig_Validate(t *testing.T) { configs []chunk.PeriodConfig err error }{ + { + name: "empty", + configs: []chunk.PeriodConfig{}, + err: zeroLengthConfigError, + }, { name: "NOT using boltdb-shipper", configs: []chunk.PeriodConfig{{