Skip to content

Commit

Permalink
lint: minor warns
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Apr 21, 2021
1 parent 68af669 commit 9814963
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/mgmt/metrics.go
Expand Up @@ -9,12 +9,14 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

// Metrics provides registration and middleware for prometheus
type Metrics struct {
totalRequests *prometheus.CounterVec
responseStatus *prometheus.CounterVec
httpDuration *prometheus.HistogramVec
}

// NewMetrics create metrics object with all counters registered
func NewMetrics() *Metrics {
res := &Metrics{}

Expand Down Expand Up @@ -55,6 +57,7 @@ func NewMetrics() *Metrics {
return res
}

// Middleware for the primary proxy server to publish all counters and update metrics
func (m *Metrics) Middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Expand All @@ -81,10 +84,12 @@ type responseWriter struct {
statusCode int
}

func NewResponseWriter(w http.ResponseWriter) *responseWriter {
// NewResponseWriter wraps http.ResponseWriter with stored status code
func NewResponseWriter(w http.ResponseWriter) *responseWriter { //nolint golint
return &responseWriter{w, http.StatusOK}
}

// WriteHeader wraps http.ResponseWriter and stores status code
func (rw *responseWriter) WriteHeader(code int) {
rw.statusCode = code
rw.ResponseWriter.WriteHeader(code)
Expand Down
5 changes: 3 additions & 2 deletions app/mgmt/server.go
Expand Up @@ -54,7 +54,8 @@ func (s *Server) Run(ctx context.Context) error {

go func() {
<-ctx.Done()
httpServer.Shutdown(context.Background())
err := httpServer.Shutdown(context.Background())
log.Printf("[WARN] mgmt server terminated, %v", err)
}()

return httpServer.ListenAndServe()
Expand All @@ -78,7 +79,7 @@ func (s *Server) routesCtrl() func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
res := map[string][]resp{} // rest.RenderJSON(w, s.Informer.Mappers())
res := map[string][]resp{}
for _, mp := range s.Informer.Mappers() {
res[mp.Server] = append(res[mp.Server], resp{Server: mp.Server, Provider: string(mp.ProviderID), Route: mp.SrcMatch.String(),
Destination: mp.Dst, MatchType: mp.MatchType.String(), Ping: mp.PingURL})
Expand Down
1 change: 1 addition & 0 deletions app/proxy/proxy.go
Expand Up @@ -47,6 +47,7 @@ type Matcher interface {
Mappers() (mappers []discovery.URLMapper)
}

// Metrics wraps middleware publishing counts
type Metrics interface {
Middleware(next http.Handler) http.Handler
}
Expand Down

0 comments on commit 9814963

Please sign in to comment.