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"
"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.