lint: minor warns

This commit is contained in:
Umputun 2021-04-20 19:17:44 -05:00
parent aef3040b60
commit f16d92b774
3 changed files with 10 additions and 3 deletions

View File

@ -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{}
@ -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) {
@ -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)

View File

@ -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()
@ -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})

View File

@ -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
}