From ab3d4e58d2d671e77cb0d21e7179dcd10eca3814 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 26 May 2023 10:13:38 +0200 Subject: [PATCH] connectivity/check: pass metrics to metricsIncrease by pointer To avoid copying this potentially large type and also work around the following erroneous govet warning: > copylocks: metricsIncrease passes lock by value: github.com/prometheus/client_model/go.MetricFamily contains google.golang.org/protobuf/internal/impl.MessageState contains sync.Mutex (govet) Ref. https://github.com/cilium/cilium-cli/actions/runs/5087191687?pr=1661 Signed-off-by: Tobias Klauser --- connectivity/check/metrics.go | 2 +- connectivity/check/metrics_test.go | 2 +- connectivity/check/result.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/connectivity/check/metrics.go b/connectivity/check/metrics.go index 7d839501af..9caf60e4a4 100644 --- a/connectivity/check/metrics.go +++ b/connectivity/check/metrics.go @@ -112,7 +112,7 @@ func parseMetrics(reader io.Reader) (promMetricsFamily, error) { } // metricsIncrease verifies for all the metrics that the values increased. -func metricsIncrease(mf1, mf2 dto.MetricFamily) error { +func metricsIncrease(mf1, mf2 *dto.MetricFamily) error { metrics1 := mf1.GetMetric() metrics2 := mf2.GetMetric() diff --git a/connectivity/check/metrics_test.go b/connectivity/check/metrics_test.go index 218bb88449..f88e72e2cf 100644 --- a/connectivity/check/metrics_test.go +++ b/connectivity/check/metrics_test.go @@ -122,7 +122,7 @@ func TestMetricsIncrease(t *testing.T) { for name, tc := range tt { t.Run(name, func(t *testing.T) { - err := metricsIncrease(tc.before, tc.after) + err := metricsIncrease(&tc.before, &tc.after) if tc.err { assert.Error(t, err) } else { diff --git a/connectivity/check/result.go b/connectivity/check/result.go index 8386fdd1f2..84bde76f38 100644 --- a/connectivity/check/result.go +++ b/connectivity/check/result.go @@ -179,7 +179,7 @@ func assertMetricsIncrease(metrics ...string) assertMetricsFunc { // Additional check needed because previously we do not return in case of error, otherwise we will panic! if bValue != nil && aValue != nil { - errM := metricsIncrease(*bValue, *aValue) + errM := metricsIncrease(bValue, aValue) if errM != nil { err = errors.Join(err, errM) }