Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Tidy code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Baliedge committed Oct 10, 2023
1 parent a963c28 commit f1c6bc2
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions global.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)))

Expand Down Expand Up @@ -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()

Expand All @@ -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() {
Expand Down

0 comments on commit f1c6bc2

Please sign in to comment.