Skip to content

Commit

Permalink
Merge pull request #24 from Jim-Lambert-Bose/url-label-from-context
Browse files Browse the repository at this point in the history
Url label from context
  • Loading branch information
zsais authored Oct 30, 2018
2 parents 1e21add + 9e4603e commit 58963fb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ type Prometheus struct {
MetricsPath string

ReqCntURLLabelMappingFn RequestCounterURLLabelMappingFn

// gin.Context string to use as a prometheus URL label
URLLabelFromContext string
}

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

p.reqDur.Observe(elapsed)
url := p.ReqCntURLLabelMappingFn(c)
// jlambert Oct 2018 - sidecar specific mod
if len(p.URLLabelFromContext) > 0 {
u, found := c.Get(p.URLLabelFromContext)
if !found {
u = "unknown"
}
url = u.(string)
}
p.reqCnt.WithLabelValues(status, c.Request.Method, c.HandlerName(), c.Request.Host, url).Inc()
p.reqSz.Observe(float64(reqSz))
p.resSz.Observe(resSz)
Expand Down

0 comments on commit 58963fb

Please sign in to comment.