@@ -30,9 +30,9 @@ import (
3030
3131 "github.com/labstack/echo/v4"
3232 "github.com/labstack/echo/v4/middleware"
33+ "github.com/labstack/gommon/log"
3334 "github.com/prometheus/client_golang/prometheus"
3435 "github.com/prometheus/client_golang/prometheus/promhttp"
35- log "github.com/sirupsen/logrus"
3636)
3737
3838var defaultMetricPath = "/metrics"
@@ -74,7 +74,7 @@ var standardMetrics = []*Metric{
7474}
7575
7676/*
77- RequestCounterURLLabelMappingFn is a function which can be supplied to the middleware to control
77+ RequestCounterURLLabelMappingFunc is a function which can be supplied to the middleware to control
7878the cardinality of the request counter's "url" label, which might be required in some contexts.
7979For instance, if for a "/customer/:name" route you don't want to generate a time series for every
8080possible customer name, you could use this function:
@@ -92,7 +92,7 @@ func(c echo.Context) string {
9292
9393which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".
9494*/
95- type RequestCounterURLLabelMappingFn func (c echo.Context ) string
95+ type RequestCounterURLLabelMappingFunc func (c echo.Context ) string
9696
9797// Metric is a definition for the name, description, type, ID, and
9898// prometheus.Collector type (i.e. CounterVec, Summary, etc) of each metric
@@ -118,15 +118,14 @@ type Prometheus struct {
118118 Subsystem string
119119 Skipper middleware.Skipper
120120
121- ReqCntURLLabelMappingFn RequestCounterURLLabelMappingFn
121+ RequestCounterURLLabelMappingFunc RequestCounterURLLabelMappingFunc
122122
123123 // Context string to use as a prometheus URL label
124124 URLLabelFromContext string
125125}
126126
127127// PushGateway contains the configuration for pushing to a Prometheus pushgateway (optional)
128128type PushGateway struct {
129-
130129 // Push interval in seconds
131130 PushIntervalSeconds time.Duration
132131
@@ -164,7 +163,7 @@ func NewPrometheus(subsystem string, skipper middleware.Skipper, customMetricsLi
164163 MetricsPath : defaultMetricPath ,
165164 Subsystem : defaultSubsystem ,
166165 Skipper : skipper ,
167- ReqCntURLLabelMappingFn : func (c echo.Context ) string {
166+ RequestCounterURLLabelMappingFunc : func (c echo.Context ) string {
168167 return c .Path () // i.e. by default do nothing, i.e. return URL as is
169168 },
170169 }
@@ -208,7 +207,6 @@ func (p *Prometheus) SetPushGatewayJob(j string) {
208207
209208// SetMetricsPath set metrics paths
210209func (p * Prometheus ) SetMetricsPath (e * echo.Echo ) {
211-
212210 if p .listenAddress != "" {
213211 p .router .GET (p .MetricsPath , prometheusHandler ())
214212 p .runServer ()
@@ -226,7 +224,7 @@ func (p *Prometheus) runServer() {
226224func (p * Prometheus ) getMetrics () []byte {
227225 response , err := http .Get (p .Ppg .MetricsURL )
228226 if err != nil {
229- log .WithError ( err ). Errorln ( "Error getting metrics" )
227+ log .Errorf ( "Error getting metrics: %v" , err )
230228 }
231229 defer response .Body .Close ()
232230 body , _ := ioutil .ReadAll (response .Body )
@@ -246,7 +244,7 @@ func (p *Prometheus) sendMetricsToPushGateway(metrics []byte) {
246244 req , err := http .NewRequest ("POST" , p .getPushGatewayURL (), bytes .NewBuffer (metrics ))
247245 client := & http.Client {}
248246 if _ , err = client .Do (req ); err != nil {
249- log .WithError ( err ). Errorln ( "Error sending to push gateway" )
247+ log .Errorf ( "Error sending to push gateway: %v" , err )
250248 }
251249}
252250
@@ -340,7 +338,7 @@ func (p *Prometheus) registerMetrics(subsystem string) {
340338 for _ , metricDef := range p .MetricsList {
341339 metric := NewMetric (metricDef , subsystem )
342340 if err := prometheus .Register (metric ); err != nil {
343- log .WithError ( err ). Errorf ("%s could not be registered in Prometheus" , metricDef .Name )
341+ log .Errorf ("%s could not be registered in Prometheus: %v " , metricDef .Name , err )
344342 }
345343 switch metricDef {
346344 case reqCnt :
@@ -381,7 +379,7 @@ func (p *Prometheus) HandlerFunc(next echo.HandlerFunc) echo.HandlerFunc {
381379 resSz := float64 (c .Response ().Size )
382380
383381 p .reqDur .Observe (elapsed )
384- url := p .ReqCntURLLabelMappingFn (c )
382+ url := p .RequestCounterURLLabelMappingFunc (c )
385383
386384 if len (p .URLLabelFromContext ) > 0 {
387385 u := c .Get (p .URLLabelFromContext )
0 commit comments