Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: golangci-lint fixes. #438

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading