From 9fb0ec905a949b4b341de66233b7f10c517cad13 Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Mon, 9 Dec 2024 18:07:47 +0200 Subject: [PATCH] metrics: golangci-lint fixes. Signed-off-by: Krisztian Litkey --- pkg/metrics/metrics.go | 10 ++++++++-- pkg/metrics/metrics_test.go | 11 +++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 24bcdd7ca..8ba988914 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -163,11 +163,17 @@ func (c *Collector) Matches(glob string) bool { } ok, err := path.Match(glob, c.group) + if err != nil { + log.Warnf("invalid glob pattern %q (group %s): %v", glob, c.group, err) + } if ok { return true } ok, err = path.Match(glob, c.name) + if err != nil { + log.Warnf("invalid glob pattern %q (name %s): %v", glob, c.name, err) + } if ok { return true } @@ -652,7 +658,7 @@ func (g *Gatherer) poller() { g.ticker = nil close(doneCh) return - case _ = <-g.ticker.C: + case <-g.ticker.C: g.Poll() } } @@ -668,7 +674,7 @@ func (g *Gatherer) Stop() { doneCh := make(chan struct{}) g.stopCh <- doneCh - _ = <-doneCh + <-doneCh g.stopCh = nil } diff --git a/pkg/metrics/metrics_test.go b/pkg/metrics/metrics_test.go index cc39fdc0b..2558411b8 100644 --- a/pkg/metrics/metrics_test.go +++ b/pkg/metrics/metrics_test.go @@ -17,6 +17,7 @@ package metrics_test import ( "bufio" "context" + "fmt" "net/http" "strings" "testing" @@ -350,7 +351,6 @@ func (c collected) GetValue(name string) string { type testServer struct { srv *http.Server - mux *http.ServeMux r *metrics.Registry g *metrics.Gatherer } @@ -389,7 +389,10 @@ func newTestServer(t *testing.T, r *metrics.Registry, enabled, polled []string, func (srv *testServer) stop() { if srv.srv != nil { - srv.srv.Shutdown(context.Background()) + err := srv.srv.Shutdown(context.Background()) + if err != nil && err != http.ErrServerClosed { + fmt.Printf("test server shutdown failed: %v\n", err) + } } if srv.g != nil { srv.g.Stop() @@ -422,7 +425,3 @@ func (srv *testServer) collect(t *testing.T) (described, collected) { return described(types), collected(metrics) } - -func (srv *testServer) poll() { - srv.r.Poll() -}