Skip to content

Commit

Permalink
fix: improved the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans committed Aug 4, 2024
1 parent 8037961 commit 71819c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 3 additions & 4 deletions balancer/rls/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var (
clientConnUpdateHook = func() {}
dataCachePurgeHook = func() {}
resetBackoffHook = func() {}
newPickerGenerated = func() {}
newPickerHook = func() {}
)

func init() {
Expand Down Expand Up @@ -306,8 +306,7 @@ func (b *rlsBalancer) UpdateClientConnState(ccs balancer.ClientConnState) error
// `resizeCache` boolean) because `cacheMu` needs to be grabbed before
// `stateMu` if we are to hold both locks at the same time.
b.cacheMu.Lock()
evicted := b.dataCache.resize(newCfg.cacheSizeBytes)
if evicted {
if b.dataCache.resize(newCfg.cacheSizeBytes) {
b.sendNewPickerLocked()
}
b.cacheMu.Unlock()
Expand Down Expand Up @@ -511,10 +510,10 @@ func (b *rlsBalancer) sendNewPickerLocked() {
ConnectivityState: aggregatedState,
Picker: picker,
}
newPickerGenerated()
if !b.inhibitPickerUpdates {
b.logger.Infof("New balancer.State: %+v", state)
b.cc.UpdateState(state)
newPickerHook()
} else {
b.logger.Infof("Delaying picker update: %+v", state)
}
Expand Down
18 changes: 10 additions & 8 deletions balancer/rls/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,18 +660,18 @@ func (s) TestPickerUpdateOnDataCacheSizeDecrease(t *testing.T) {
clientConnUpdateHook = func() { clientConnUpdateDone <- struct{}{} }
defer func() { clientConnUpdateHook = origClientConnUpdateHook }()

// Override the newPickerGenerated to measure the number of times
// Override the newPickerHook to measure the number of times
// the picker is generated because state updates can be inhibited.
pickerUpdateCh := make(chan struct{})
// Block udpates until the last configuration update
blkUpdates := atomic.Bool{}
origNewPickerGenerated := newPickerGenerated
newPickerGenerated = func() {
origNewPickerHook := newPickerHook
newPickerHook = func() {
if blkUpdates.Load() == true {
pickerUpdateCh <- struct{}{}
}
}
defer func() { newPickerGenerated = origNewPickerGenerated }()
defer func() { newPickerHook = origNewPickerHook }()

// Override the cache entry size func, and always return 1.
origEntrySizeFunc := computeDataCacheEntrySize
Expand Down Expand Up @@ -799,9 +799,11 @@ func (s) TestPickerUpdateOnDataCacheSizeDecrease(t *testing.T) {

cc := <-ccCh
defer cc.Close()

// Make an RPC call with empty metadata, which will eventually throw
// the error as no metadata will match from rlsServer response
// callback defined above. This will cause the control channel to
// throw the error and cause the item to get into backoff.
makeTestRPCAndVerifyError(ctx, t, cc, codes.Unavailable, nil)
t.Logf("Verifying if RPC failed when listener is stopped.")

ctxOutgoing := metadata.AppendToOutgoingContext(ctx, "n1", "v1")
makeTestRPCAndExpectItToReachBackend(ctxOutgoing, t, cc, backendCh1)
Expand All @@ -823,7 +825,7 @@ func (s) TestPickerUpdateOnDataCacheSizeDecrease(t *testing.T) {
case <-clientConnUpdateDone:
t.Fatalf("Client conn update was completed before picker update.")
case <-ctx.Done():
t.Errorf("error waiting for picker update on receipt of configuration udpate: %v", ctx.Err().Error())
t.Fatal("Timed out waiting for picker update upon receiving a configuration update")
}
}

Expand All @@ -832,7 +834,7 @@ func (s) TestPickerUpdateOnDataCacheSizeDecrease(t *testing.T) {
select {
case <-clientConnUpdateDone:
case <-ctx.Done():
t.Errorf("client conn update could not complete: %v", ctx.Err().Error())
t.Fatal("Timed out waiting for client conn update upon receiving a configuration update")
}
}

Expand Down

0 comments on commit 71819c6

Please sign in to comment.