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 Mar 8, 2024
1 parent 432c847 commit 5fd6dad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
9 changes: 7 additions & 2 deletions functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,7 @@ func TestGlobalRateLimitsWithLoadBalancing(t *testing.T) {
assert.Equal(t, status, item.Status, fmt.Sprintf("mismatch status, iteration %d", i))
}

require.NoError(t, waitForBroadcast(1*clock.Minute, owner, 0))
require.NoError(t, waitForBroadcast(1*clock.Minute, nonOwner, 0))
require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...))

// Send two hits that should be processed by the owner and non-owner and
// deplete the limit consistently.
Expand Down Expand Up @@ -1541,6 +1540,8 @@ func TestGlobalBehavior(t *testing.T) {
upgCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/UpdatePeerGlobals\"}")
gprlCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/GetPeerRateLimits\"}")

require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...))

// When
for i := int64(0); i < testCase.Hits; i++ {
sendHit(t, owner, makeReq(name, key, 1), guber.Status_UNDER_LIMIT, 999-i)
Expand Down Expand Up @@ -1657,6 +1658,8 @@ func TestGlobalBehavior(t *testing.T) {
upgCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/UpdatePeerGlobals\"}")
gprlCounters := getPeerCounters(t, cluster.GetDaemons(), "gubernator_grpc_request_duration_count{method=\"/pb.gubernator.PeersV1/GetPeerRateLimits\"}")

require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...))

// When
for i := int64(0); i < testCase.Hits; i++ {
sendHit(t, peers[0], makeReq(name, key, 1), guber.Status_UNDER_LIMIT, 999-i)
Expand Down Expand Up @@ -1787,6 +1790,8 @@ func TestGlobalBehavior(t *testing.T) {
var wg sync.WaitGroup
var mutex sync.Mutex

require.NoError(t, waitForIdle(1*clock.Minute, cluster.GetDaemons()...))

// When
wg.Add(testCase.Hits)
for i := 0; i < testCase.Hits; i++ {
Expand Down
20 changes: 10 additions & 10 deletions global.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ import (
// globalManager manages async hit queue and updates peers in
// the cluster periodically when a global rate limit we own updates.
type globalManager struct {
hitsQueue chan *RateLimitReq
updatesQueue chan *RateLimitReq
wg syncutil.WaitGroup
conf BehaviorConfig
log FieldLogger
instance *V1Instance // todo circular import? V1Instance also holds a reference to globalManager
metricGlobalSendDuration prometheus.Summary
hitsQueue chan *RateLimitReq
updatesQueue chan *RateLimitReq
wg syncutil.WaitGroup
conf BehaviorConfig
log FieldLogger
instance *V1Instance // todo circular import? V1Instance also holds a reference to globalManager
metricGlobalSendDuration prometheus.Summary
metricGlobalSendQueueLength prometheus.Gauge
metricBroadcastDuration prometheus.Summary
metricBroadcastCounter *prometheus.CounterVec
metricGlobalQueueLength prometheus.Gauge
metricBroadcastDuration prometheus.Summary
metricBroadcastCounter *prometheus.CounterVec
metricGlobalQueueLength prometheus.Gauge
}

func newGlobalManager(conf BehaviorConfig, instance *V1Instance) *globalManager {
Expand Down

0 comments on commit 5fd6dad

Please sign in to comment.