Skip to content

Commit

Permalink
apply shipper defaults to last relevant period config, not current one.
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d committed May 25, 2022
1 parent 4bc3ddc commit d9f1e06
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions pkg/loki/config_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
//
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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 != "" {
Expand Down

0 comments on commit d9f1e06

Please sign in to comment.