loadConfig loads configuration using the loader function, and if successful, stores it as current configuration and notifies listeners.
(ctx context.Context)
| 166 | // loadConfig loads configuration using the loader function, and if successful, |
| 167 | // stores it as current configuration and notifies listeners. |
| 168 | func (om *Manager) loadConfig(ctx context.Context) error { |
| 169 | buf, err := om.loadConfigFromBucket(ctx) |
| 170 | |
| 171 | if err != nil { |
| 172 | om.configLoadSuccess.Set(0) |
| 173 | return errors.Wrap(err, "read file") |
| 174 | } |
| 175 | hash := sha256.Sum256(buf) |
| 176 | |
| 177 | cfg, err := om.cfg.Loader(bytes.NewReader(buf)) |
| 178 | if err != nil { |
| 179 | om.configLoadSuccess.Set(0) |
| 180 | return errors.Wrap(err, "load file") |
| 181 | } |
| 182 | om.configLoadSuccess.Set(1) |
| 183 | |
| 184 | om.setConfig(cfg) |
| 185 | om.callListeners(cfg) |
| 186 | |
| 187 | // expose hash of runtime config |
| 188 | om.configHash.Reset() |
| 189 | om.configHash.WithLabelValues(fmt.Sprintf("%x", hash[:])).Set(1) |
| 190 | return nil |
| 191 | } |
| 192 | |
| 193 | func (om *Manager) loadConfigFromBucket(ctx context.Context) ([]byte, error) { |
| 194 | readCloser, err := om.bucketClient.Get(ctx, om.cfg.LoadPath) |