-
Notifications
You must be signed in to change notification settings - Fork 54
Remote config loading code could be more clear #536
Copy link
Copy link
Open
Description
Small code quality issue, the code is currently a bit harder to follow than feels necessary:
collector-sidecar/superv/configmanager/manager.go
Lines 276 to 307 in 044b828
| // 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) | |
| } | |
| } |
Reactions are currently unavailable