From 5cefaeaddca938b026a77dc361afc1abed8ea778 Mon Sep 17 00:00:00 2001 From: Abhishek Ranjan <159750762+aranjans@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:08:42 +0530 Subject: [PATCH 1/4] balancer/wrr: prefer calling Equal() method of time.Time over direct comparison --- balancer/weightedroundrobin/balancer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/balancer/weightedroundrobin/balancer.go b/balancer/weightedroundrobin/balancer.go index ed241124219e..4924b76bd8be 100644 --- a/balancer/weightedroundrobin/balancer.go +++ b/balancer/weightedroundrobin/balancer.go @@ -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 time.Time.Equal(w.lastUpdated, time.Time{}) { endpointWeightNotYetUsableMetric.Record(w.metricsRecorder, 1, w.target, w.locality) return 0 } From b8241d8982c06c78bf1566b54e70853fb110e452 Mon Sep 17 00:00:00 2001 From: Abhishek Ranjan <159750762+aranjans@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:22:16 +0530 Subject: [PATCH 2/4] refactor --- benchmark/latency/latency.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benchmark/latency/latency.go b/benchmark/latency/latency.go index 10fcb12c8d4e..4fae637673ee 100644 --- a/benchmark/latency/latency.go +++ b/benchmark/latency/latency.go @@ -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} ) From eeb8a5af250c16ec8e3c38d3ef49b1d176305a05 Mon Sep 17 00:00:00 2001 From: Abhishek Ranjan <159750762+aranjans@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:36:39 +0530 Subject: [PATCH 3/4] fix other occurences across file --- balancer/weightedroundrobin/balancer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/balancer/weightedroundrobin/balancer.go b/balancer/weightedroundrobin/balancer.go index 4924b76bd8be..ec7a8b1061ab 100644 --- a/balancer/weightedroundrobin/balancer.go +++ b/balancer/weightedroundrobin/balancer.go @@ -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 } } @@ -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 time.Time.Equal(w.lastUpdated, time.Time{}) { + if w.lastUpdated.Equal(time.Time{}) { endpointWeightNotYetUsableMetric.Record(w.metricsRecorder, 1, w.target, w.locality) return 0 } @@ -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) } From 359462b443957fe40d52ba4904c85dd7abe388b4 Mon Sep 17 00:00:00 2001 From: Abhishek Ranjan <159750762+aranjans@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:07:21 +0530 Subject: [PATCH 4/4] Update config_selector_test.go --- test/config_selector_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/config_selector_test.go b/test/config_selector_test.go index 69782ef9ce0b..78518d4fb5b9 100644 --- a/test/config_selector_test.go +++ b/test/config_selector_test.go @@ -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()