Skip to content

Commit 58963fb

Browse files
authored
Merge pull request #24 from Jim-Lambert-Bose/url-label-from-context
Url label from context
2 parents 1e21add + 9e4603e commit 58963fb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

middleware.go

+11
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ type Prometheus struct {
9595
MetricsPath string
9696

9797
ReqCntURLLabelMappingFn RequestCounterURLLabelMappingFn
98+
99+
// gin.Context string to use as a prometheus URL label
100+
URLLabelFromContext string
98101
}
99102

100103
// PrometheusPushGateway contains the configuration for pushing to a Prometheus pushgateway (optional)
@@ -366,6 +369,14 @@ func (p *Prometheus) HandlerFunc() gin.HandlerFunc {
366369

367370
p.reqDur.Observe(elapsed)
368371
url := p.ReqCntURLLabelMappingFn(c)
372+
// jlambert Oct 2018 - sidecar specific mod
373+
if len(p.URLLabelFromContext) > 0 {
374+
u, found := c.Get(p.URLLabelFromContext)
375+
if !found {
376+
u = "unknown"
377+
}
378+
url = u.(string)
379+
}
369380
p.reqCnt.WithLabelValues(status, c.Request.Method, c.HandlerName(), c.Request.Host, url).Inc()
370381
p.reqSz.Observe(float64(reqSz))
371382
p.resSz.Observe(resSz)

0 commit comments

Comments
 (0)