From f1c6bc2b3daf324444deec232d0c9291391ecbe7 Mon Sep 17 00:00:00 2001 From: Shawn Poulson Date: Tue, 10 Oct 2023 10:52:46 -0400 Subject: [PATCH] Tidy code. --- global.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/global.go b/global.go index 1fc619e1..ad33ef55 100644 --- a/global.go +++ b/global.go @@ -18,9 +18,7 @@ package gubernator import ( "context" - "time" - "github.com/mailgun/holster/v4/clock" "github.com/mailgun/holster/v4/ctxutil" "github.com/mailgun/holster/v4/syncutil" "github.com/prometheus/client_golang/prometheus" @@ -128,8 +126,8 @@ func (gm *globalManager) sendHits(hits map[string]*RateLimitReq) { client *PeerClient req GetPeerRateLimitsReq } + defer prometheus.NewTimer(gm.metricAsyncDuration).ObserveDuration() peerRequests := make(map[string]*pair) - start := clock.Now() // Assign each request to a peer for _, r := range hits { @@ -162,7 +160,6 @@ func (gm *globalManager) sendHits(hits map[string]*RateLimitReq) { continue } } - gm.metricAsyncDuration.Observe(time.Since(start).Seconds()) } // runBroadcasts collects status changes for global rate limits and broadcasts the changes to each peer in the cluster. @@ -206,9 +203,8 @@ func (gm *globalManager) runBroadcasts() { // broadcastPeers broadcasts global rate limit statuses to all other peers func (gm *globalManager) broadcastPeers(ctx context.Context, updates map[string]*RateLimitReq) { - defer prometheus.NewTimer(metricFuncTimeDuration.WithLabelValues("globalManager.broadcastPeers")).ObserveDuration() + defer prometheus.NewTimer(gm.metricBroadcastDuration).ObserveDuration() var req UpdatePeerGlobalsReq - start := clock.Now() metricGlobalQueueLength.Set(float64(len(updates))) @@ -239,7 +235,7 @@ func (gm *globalManager) broadcastPeers(ctx context.Context, updates map[string] continue } - ctx, cancel := ctxutil.WithTimeout(context.Background(), gm.conf.GlobalTimeout) + ctx, cancel := ctxutil.WithTimeout(ctx, gm.conf.GlobalTimeout) _, err := peer.UpdatePeerGlobals(ctx, &req) cancel() @@ -251,8 +247,6 @@ func (gm *globalManager) broadcastPeers(ctx context.Context, updates map[string] continue } } - - gm.metricBroadcastDuration.Observe(time.Since(start).Seconds()) } func (gm *globalManager) Close() {