Skip to content

Instantly share code, notes, and snippets.

@tanan
Created February 26, 2018 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanan/e43440ff5859119007da245a99a4e5f5 to your computer and use it in GitHub Desktop.
Save tanan/e43440ff5859119007da245a99a4e5f5 to your computer and use it in GitHub Desktop.
reload config file (prometheus.yml)
func reloadConfig(filename string, logger log.Logger, rls ...func(*config.Config) error) (err error) {
level.Info(logger).Log("msg", "Loading configuration file", "filename", filename)
defer func() {
if err == nil {
configSuccess.Set(1)
configSuccessTime.SetToCurrentTime()
} else {
configSuccess.Set(0)
}
}()
conf, err := config.LoadFile(filename)
if err != nil {
return fmt.Errorf("couldn't load configuration (--config.file=%s): %v", filename, err)
}
failed := false
for _, rl := range rls {
if err := rl(conf); err != nil {
level.Error(logger).Log("msg", "Failed to apply configuration", "err", err)
failed = true
}
}
if failed {
return fmt.Errorf("one or more errors occurred while applying the new configuration (--config.file=%s)", filename)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment