Skip to content

Commit

Permalink
Address linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
acrmp committed Jun 14, 2022
1 parent d856da4 commit 89d9b59
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/cmd/config-generator/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func LoadConfig(log *log.Logger) Config {
log.Fatal(err)
}

envstruct.WriteReport(&cfg)
if err := envstruct.WriteReport(&cfg); err != nil {
log.Fatal(err)
}

return cfg
}
2 changes: 1 addition & 1 deletion src/cmd/config-generator/app/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io/ioutil"
"log"
"net/http"
_ "net/http/pprof"
_ "net/http/pprof" // nolint:gosec
"os"
"sync"
"time"
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/discovery-registrar/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func LoadConfig(log *log.Logger) Config {
log.Fatal(err)
}

envstruct.WriteReport(&cfg)
if err := envstruct.WriteReport(&cfg); err != nil {
log.Fatal(err)
}

return cfg
}
11 changes: 8 additions & 3 deletions src/cmd/discovery-registrar/app/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
_ "net/http/pprof" // nolint:gosec
"time"

metrics "code.cloudfoundry.org/go-metric-registry"
Expand Down Expand Up @@ -55,7 +55,12 @@ func (r *DynamicRegistrar) Start(debugMetrics bool, pprofPort uint16) {
if debugMetrics {
r.metrics.RegisterDebugMetrics()
r.pprofServer = &http.Server{Addr: fmt.Sprintf("127.0.0.1:%d", pprofPort), Handler: http.DefaultServeMux}
go func() { r.pprofServer.ListenAndServe() }()
go func() {
err := r.pprofServer.ListenAndServe()
if err != http.ErrServerClosed {
log.Fatalf("pprof error: %s", err)
}
}()
}
ticker := time.NewTicker(r.publishInterval)

Expand All @@ -75,7 +80,7 @@ func (r *DynamicRegistrar) Start(debugMetrics bool, pprofPort uint16) {
func (r *DynamicRegistrar) publishTargets() {
targets := r.targetProvider()
for _, t := range targets {
bytes, err := yaml.Marshal(&t)
bytes, err := yaml.Marshal(t)
if err != nil {
r.logger.Printf("unable to marshal target(%s): %s\n", t.Source, err)
continue
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/metrics-agent/app/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
"fmt"
"log"
"time"

"code.cloudfoundry.org/go-envstruct"
Expand Down Expand Up @@ -59,11 +59,14 @@ func LoadConfig() Config {
ExpirationInterval: time.Minute,
},
}

if err := envstruct.Load(&cfg); err != nil {
panic(fmt.Sprintf("Failed to load config from environment: %s", err))
log.Fatal(err)
}

envstruct.WriteReport(&cfg)
if err := envstruct.WriteReport(&cfg); err != nil {
log.Fatal(err)
}

return cfg
}
4 changes: 2 additions & 2 deletions src/cmd/metrics-agent/app/metrics_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
_ "net/http/pprof" // nolint:gosec
"time"

gendiodes "code.cloudfoundry.org/go-diodes"
Expand Down Expand Up @@ -244,7 +244,7 @@ func (m *MetricsAgent) Stop() {
defer cancelFunc()

if m.metricsServer != nil {
m.metricsServer.Shutdown(ctx)
_ = m.metricsServer.Shutdown(ctx)
}
}()

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/metrics-agent/app/metrics_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ func newStubPromServer() *stubPromServer {
func (s *stubPromServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.requestHeaders <- req.Header
s.requestPaths <- req.URL.Path
w.Write([]byte(s.resp))
_, err := w.Write([]byte(s.resp))
Expect(err).ToNot(HaveOccurred())
}

const promOutput = `
Expand Down
1 change: 0 additions & 1 deletion src/cmd/metrics-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"log"
_ "net/http/pprof"
"os"
"time"

Expand Down
2 changes: 1 addition & 1 deletion src/internal/gatherer/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (c *ProxyGatherer) scrape(scrapeConfig scraper.PromScraperConfig) ([]*io_pr
}

defer func() {
io.Copy(ioutil.Discard, resp.Body)
_, _ = io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}()

Expand Down
3 changes: 2 additions & 1 deletion src/internal/gatherer/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ func newStubHttpsPromServer(scrapeCerts *testhelpers.TestCerts) *stubPromServer
func (s *stubPromServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.requestHeaders <- req.Header
s.requestPaths <- req.URL.Path
w.Write([]byte(s.resp))
_, err := w.Write([]byte(s.resp))
Expect(err).ToNot(HaveOccurred())
}

func haveFamilyName(name string) types.GomegaMatcher {
Expand Down

0 comments on commit 89d9b59

Please sign in to comment.