Skip to content

Commit

Permalink
connectivity/check: pass metrics to metricsIncrease by pointer
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tklauser committed May 26, 2023
1 parent dd8a5ab commit ab3d4e5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion connectivity/check/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion connectivity/check/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion connectivity/check/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ab3d4e5

Please sign in to comment.