web: Replace usage of sync/atomic with uber-go/atomic

Signed-off-by: Javier Palomo <javier.palomo.almena@gmail.com>
pull/7683/head
Javier Palomo 2020-07-28 14:19:50 +02:00
parent 90324bcfc4
commit 4b5bbc864e
1 changed files with 6 additions and 7 deletions

View File

@ -34,7 +34,6 @@ import (
"sort" "sort"
"strings" "strings"
"sync" "sync"
"sync/atomic"
template_text "text/template" template_text "text/template"
"time" "time"
@ -68,6 +67,8 @@ import (
api_v1 "github.com/prometheus/prometheus/web/api/v1" api_v1 "github.com/prometheus/prometheus/web/api/v1"
api_v2 "github.com/prometheus/prometheus/web/api/v2" api_v2 "github.com/prometheus/prometheus/web/api/v2"
"github.com/prometheus/prometheus/web/ui" "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. // 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 mtx sync.RWMutex
now func() model.Time 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 // ApplyConfig updates the config field of the Handler struct
@ -293,9 +294,8 @@ func New(logger log.Logger, o *Options) *Handler {
notifier: o.Notifier, notifier: o.Notifier,
now: model.Now, now: model.Now,
ready: 0,
} }
h.ready.Store(0)
factoryTr := func(_ context.Context) api_v1.TargetRetriever { return h.scrapeManager } factoryTr := func(_ context.Context) api_v1.TargetRetriever { return h.scrapeManager }
factoryAr := func(_ context.Context) api_v1.AlertmanagerRetriever { return h.notifier } 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. // Ready sets Handler to be ready.
func (h *Handler) Ready() { func (h *Handler) Ready() {
atomic.StoreUint32(&h.ready, 1) h.ready.Store(1)
} }
// Verifies whether the server is ready or not. // Verifies whether the server is ready or not.
func (h *Handler) isReady() bool { func (h *Handler) isReady() bool {
ready := atomic.LoadUint32(&h.ready) return h.ready.Load() > 0
return ready > 0
} }
// Checks if server is ready, calls f if it is, returns 503 if it is not. // Checks if server is ready, calls f if it is, returns 503 if it is not.