diff --git a/pkg/loki/config_wrapper.go b/pkg/loki/config_wrapper.go index 239b6c97b2a7f..417b4f4fc3687 100644 --- a/pkg/loki/config_wrapper.go +++ b/pkg/loki/config_wrapper.go @@ -99,12 +99,12 @@ func (c *ConfigWrapper) ApplyDynamicConfig() cfg.Source { return err } - if len(r.SchemaConfig.Configs) > 0 && config.UsingBoltdbShipper(r.SchemaConfig.Configs) { - betterBoltdbShipperDefaults(r, &defaults) + if i := lastBoltdbShipperConfig(r.SchemaConfig.Configs); i != len(r.SchemaConfig.Configs) { + betterBoltdbShipperDefaults(r, &defaults, r.SchemaConfig.Configs[i]) } - if len(r.SchemaConfig.Configs) > 0 && config.UsingTSDB(r.SchemaConfig.Configs) { - betterTSDBShipperDefaults(r, &defaults) + if i := lastTSDBConfig(r.SchemaConfig.Configs); i != len(r.SchemaConfig.Configs) { + betterTSDBShipperDefaults(r, &defaults, r.SchemaConfig.Configs[i]) } applyFIFOCacheConfig(r) @@ -116,6 +116,27 @@ func (c *ConfigWrapper) ApplyDynamicConfig() cfg.Source { } } +func lastConfigFor(configs []config.PeriodConfig, predicate func(config.PeriodConfig) bool) int { + for i := len(configs) - 1; i >= 0; i-- { + if predicate(configs[i]) { + return i + } + } + return len(configs) +} + +func lastBoltdbShipperConfig(configs []config.PeriodConfig) int { + return lastConfigFor(configs, func(p config.PeriodConfig) bool { + return p.IndexType == config.BoltDBShipperType + }) +} + +func lastTSDBConfig(configs []config.PeriodConfig) int { + return lastConfigFor(configs, func(p config.PeriodConfig) bool { + return p.IndexType == config.TSDBType + }) +} + // applyInstanceConfigs apply to Loki components instance-related configurations under the common // config section. // @@ -486,16 +507,14 @@ func applyStorageConfig(cfg, defaults *ConfigWrapper) error { return nil } -func betterBoltdbShipperDefaults(cfg, defaults *ConfigWrapper) { - currentSchemaIdx := config.ActivePeriodConfig(cfg.SchemaConfig.Configs) - currentSchema := cfg.SchemaConfig.Configs[currentSchemaIdx] +func betterBoltdbShipperDefaults(cfg, defaults *ConfigWrapper, period config.PeriodConfig) { if cfg.StorageConfig.BoltDBShipperConfig.SharedStoreType == defaults.StorageConfig.BoltDBShipperConfig.SharedStoreType { - cfg.StorageConfig.BoltDBShipperConfig.SharedStoreType = currentSchema.ObjectType + cfg.StorageConfig.BoltDBShipperConfig.SharedStoreType = period.ObjectType } if cfg.CompactorConfig.SharedStoreType == defaults.CompactorConfig.SharedStoreType { - cfg.CompactorConfig.SharedStoreType = currentSchema.ObjectType + cfg.CompactorConfig.SharedStoreType = period.ObjectType } if cfg.Common.PathPrefix != "" { @@ -511,16 +530,14 @@ func betterBoltdbShipperDefaults(cfg, defaults *ConfigWrapper) { } } -func betterTSDBShipperDefaults(cfg, defaults *ConfigWrapper) { - currentSchemaIdx := config.ActivePeriodConfig(cfg.SchemaConfig.Configs) - currentSchema := cfg.SchemaConfig.Configs[currentSchemaIdx] +func betterTSDBShipperDefaults(cfg, defaults *ConfigWrapper, period config.PeriodConfig) { if cfg.StorageConfig.TSDBShipperConfig.SharedStoreType == defaults.StorageConfig.TSDBShipperConfig.SharedStoreType { - cfg.StorageConfig.TSDBShipperConfig.SharedStoreType = currentSchema.ObjectType + cfg.StorageConfig.TSDBShipperConfig.SharedStoreType = period.ObjectType } if cfg.CompactorConfig.SharedStoreType == defaults.CompactorConfig.SharedStoreType { - cfg.CompactorConfig.SharedStoreType = currentSchema.ObjectType + cfg.CompactorConfig.SharedStoreType = period.ObjectType } if cfg.Common.PathPrefix != "" {