Skip to content

Commit

Permalink
balancer/wrr: prefer calling Equal() method of time.Time (#7529)
Browse files Browse the repository at this point in the history
  • Loading branch information
aranjans authored Aug 26, 2024
1 parent a8e6e11 commit 9feed00
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions balancer/weightedroundrobin/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (w *weightedSubConn) OnLoadReport(load *v3orcapb.OrcaLoadReport) {
}

w.lastUpdated = internal.TimeNow()
if w.nonEmptySince == (time.Time{}) {
if w.nonEmptySince.Equal(time.Time{}) {
w.nonEmptySince = w.lastUpdated
}
}
Expand Down Expand Up @@ -608,7 +608,7 @@ func (w *weightedSubConn) weight(now time.Time, weightExpirationPeriod, blackout

// The SubConn has not received a load report (i.e. just turned READY with
// no load report).
if w.lastUpdated == (time.Time{}) {
if w.lastUpdated.Equal(time.Time{}) {
endpointWeightNotYetUsableMetric.Record(w.metricsRecorder, 1, w.target, w.locality)
return 0
}
Expand All @@ -625,7 +625,7 @@ func (w *weightedSubConn) weight(now time.Time, weightExpirationPeriod, blackout
}

// If we don't have at least blackoutPeriod worth of data, return 0.
if blackoutPeriod != 0 && (w.nonEmptySince == (time.Time{}) || now.Sub(w.nonEmptySince) < blackoutPeriod) {
if blackoutPeriod != 0 && (w.nonEmptySince.Equal(time.Time{}) || now.Sub(w.nonEmptySince) < blackoutPeriod) {
if recordMetrics {
endpointWeightNotYetUsableMetric.Record(w.metricsRecorder, 1, w.target, w.locality)
}
Expand Down
8 changes: 4 additions & 4 deletions benchmark/latency/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ type Network struct {
}

var (
//Local simulates local network.
// Local simulates local network.
Local = Network{0, 0, 0}
//LAN simulates local area network.
// LAN simulates local area network.
LAN = Network{100 * 1024, 2 * time.Millisecond, 1500}
//WAN simulates wide area network.
// WAN simulates wide area network.
WAN = Network{20 * 1024, 30 * time.Millisecond, 1500}
//Longhaul simulates bad network.
// Longhaul simulates bad network.
Longhaul = Network{1000 * 1024, 200 * time.Millisecond, 9000}
)

Expand Down
2 changes: 1 addition & 1 deletion test/config_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s) TestConfigSelector(t *testing.T) {
}

wantDeadline := tc.wantDeadline
if wantDeadline == (time.Time{}) {
if wantDeadline.Equal(time.Time{}) {
wantDeadline = startTime.Add(tc.wantTimeout)
}
deadlineGot, _ := gotContext.Deadline()
Expand Down

0 comments on commit 9feed00

Please sign in to comment.