Skip to content

Commit

Permalink
metrics: golangci-lint fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub authored and askervin committed Dec 11, 2024
1 parent 9aa2f96 commit bec1e79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 8 additions & 2 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -652,7 +658,7 @@ func (g *Gatherer) poller() {
g.ticker = nil
close(doneCh)
return
case _ = <-g.ticker.C:
case <-g.ticker.C:
g.Poll()
}
}
Expand All @@ -668,7 +674,7 @@ func (g *Gatherer) Stop() {

doneCh := make(chan struct{})
g.stopCh <- doneCh
_ = <-doneCh
<-doneCh

g.stopCh = nil
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package metrics_test
import (
"bufio"
"context"
"fmt"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}

0 comments on commit bec1e79

Please sign in to comment.