Skip to content

Remote config loading code could be more clear #536

@kroepke

Description

@kroepke

Small code quality issue, the code is currently a bit harder to follow than feels necessary:

// Prefer rebuilding from the cached raw remote config when the last
// applied status is APPLIED. This keeps the effective config in sync with
// current local overrides across restarts instead of reusing a stale
// previously rendered collector.yaml.
usedCachedRemote := false
if cached, ok := m.loadCachedRemoteConfig(); ok {
m.logger.Info("Rebuilding config from cached remote config",
zap.String("remote_path", filepath.Join(m.cfg.ConfigDir, "remote", filepath.Base(m.cfg.OutputPath))))
config = cached
usedCachedRemote = true
}
bootstrap := len(config) == 0
if bootstrap {
if errors.Is(err, os.ErrNotExist) {
m.logger.Info("No existing config found, writing bootstrap config",
zap.String("path", m.cfg.OutputPath))
} else {
m.logger.Info("Existing config is empty, writing bootstrap config",
zap.String("path", m.cfg.OutputPath))
}
} else if !usedCachedRemote {
m.logger.Info("Re-injecting extensions into cached config",
zap.String("path", m.cfg.OutputPath))
}
if usedCachedRemote {
config, err = m.mergeLocalOverrides(config)
if err != nil {
return fmt.Errorf("failed to rebuild cached remote config with local overrides: %w", err)
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions