From baebed55e67fad5ce2338cbea1e45abf42c5321f Mon Sep 17 00:00:00 2001 From: Brodie Kurczynski Date: Tue, 20 Feb 2024 05:32:47 -0800 Subject: [PATCH] Add an error log when the config fails to reload (#6283) Co-authored-by: Paulin Todev Co-authored-by: Paschalis Tsilias --- CHANGELOG.md | 2 ++ service/http/http.go | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d63fa3ef1ee7..e77460c75177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,8 @@ Main (unreleased) - Mutex and block pprofs are now available via the pprof endpoint. (@mattdurham) +- Added an error log when the config fails to reload. (@kurczynski) + - Added additional http client proxy configurations to components for `no_proxy`, `proxy_from_environment`, and `proxy_connect_header`. (@erikbaranowski) diff --git a/service/http/http.go b/service/http/http.go index a8608f4dfcb5..488651d7597d 100644 --- a/service/http/http.go +++ b/service/http/http.go @@ -186,14 +186,16 @@ func (s *Service) Run(ctx context.Context, host service.Host) error { if s.opts.ReloadFunc != nil { r.HandleFunc("/-/reload", func(w http.ResponseWriter, _ *http.Request) { level.Info(s.log).Log("msg", "reload requested via /-/reload endpoint") - defer level.Info(s.log).Log("msg", "config reloaded") _, err := s.opts.ReloadFunc() if err != nil { + level.Error(s.log).Log("msg", "failed to reload config", "err", err.Error()) http.Error(w, err.Error(), http.StatusBadRequest) return } - fmt.Fprintln(w, "config reloaded") + + level.Info(s.log).Log("msg", "config reloaded") + _, _ = fmt.Fprintln(w, "config reloaded") }).Methods(http.MethodGet, http.MethodPost) }