From 4b5bbc864e28a667260ddad369ca455b7ea1c6dc Mon Sep 17 00:00:00 2001 From: Javier Palomo Date: Tue, 28 Jul 2020 14:19:50 +0200 Subject: [PATCH] web: Replace usage of sync/atomic with uber-go/atomic Signed-off-by: Javier Palomo --- web/web.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/web/web.go b/web/web.go index fbd404369..ba01327d7 100644 --- a/web/web.go +++ b/web/web.go @@ -34,7 +34,6 @@ import ( "sort" "strings" "sync" - "sync/atomic" template_text "text/template" "time" @@ -68,6 +67,8 @@ import ( api_v1 "github.com/prometheus/prometheus/web/api/v1" api_v2 "github.com/prometheus/prometheus/web/api/v2" "github.com/prometheus/prometheus/web/ui" + + "go.uber.org/atomic" ) // Paths that are handled by the React / Reach router that should all be served the main React app's index.html. @@ -202,7 +203,7 @@ type Handler struct { mtx sync.RWMutex now func() model.Time - ready uint32 // ready is uint32 rather than boolean to be able to use atomic functions. + ready atomic.Uint32 // ready is uint32 rather than boolean to be able to use atomic functions. } // ApplyConfig updates the config field of the Handler struct @@ -293,9 +294,8 @@ func New(logger log.Logger, o *Options) *Handler { notifier: o.Notifier, now: model.Now, - - ready: 0, } + h.ready.Store(0) factoryTr := func(_ context.Context) api_v1.TargetRetriever { return h.scrapeManager } factoryAr := func(_ context.Context) api_v1.AlertmanagerRetriever { return h.notifier } @@ -484,13 +484,12 @@ func serveDebug(w http.ResponseWriter, req *http.Request) { // Ready sets Handler to be ready. func (h *Handler) Ready() { - atomic.StoreUint32(&h.ready, 1) + h.ready.Store(1) } // Verifies whether the server is ready or not. func (h *Handler) isReady() bool { - ready := atomic.LoadUint32(&h.ready) - return ready > 0 + return h.ready.Load() > 0 } // Checks if server is ready, calls f if it is, returns 503 if it is not.