Skip to content

Commit 0245665

Browse files
committed
Bit of refactor
Signed-off-by: Vishal Rana <[email protected]>
1 parent 0bfc7e7 commit 0245665

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: go
22
go:
3+
- 1.13.x
34
- 1.12.x
4-
- 1.11.x
55
- tip
66
env:
77
- GO111MODULE=on

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ require (
77
github.com/gorilla/context v1.1.1
88
github.com/gorilla/sessions v1.1.3
99
github.com/labstack/echo/v4 v4.1.6
10+
github.com/labstack/gommon v0.2.9
1011
github.com/opentracing/opentracing-go v1.1.0
1112
github.com/pkg/errors v0.8.1 // indirect
1213
github.com/prometheus/client_golang v1.1.0
13-
github.com/sirupsen/logrus v1.4.2
1414
github.com/stretchr/testify v1.3.0
1515
github.com/uber-go/atomic v1.4.0 // indirect
1616
github.com/uber/jaeger-client-go v2.17.0+incompatible

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBf
117117
github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=
118118
github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
119119
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
120-
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
121-
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
122120
github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
123121
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
124122
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@@ -170,7 +168,6 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
170168
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
171169
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
172170
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
173-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
174171
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
175172
golang.org/x/sys v0.0.0-20190609082536-301114b31cce/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
176173
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0=

prometheus/prometheus.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3838
var 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
7878
the cardinality of the request counter's "url" label, which might be required in some contexts.
7979
For instance, if for a "/customer/:name" route you don't want to generate a time series for every
8080
possible customer name, you could use this function:
@@ -92,7 +92,7 @@ func(c echo.Context) string {
9292
9393
which 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)
128128
type 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
210209
func (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() {
226224
func (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

Comments
 (0)