Skip to content

Commit

Permalink
Merge pull request #12 from smikulcik/concurrentMapBug
Browse files Browse the repository at this point in the history
Make computeApproximateRequestSize non-concurrent
  • Loading branch information
zsais authored Sep 18, 2017
2 parents 56be485 + 994b046 commit f200fd8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ func (p *Prometheus) handlerFunc() gin.HandlerFunc {
}

start := time.Now()
reqSz := make(chan int)
go computeApproximateRequestSize(c.Request, reqSz)
reqSz := computeApproximateRequestSize(c.Request)

c.Next()

Expand All @@ -234,7 +233,7 @@ func (p *Prometheus) handlerFunc() gin.HandlerFunc {

p.reqDur.Observe(elapsed)
p.reqCnt.WithLabelValues(status, c.Request.Method, c.HandlerName(), c.Request.Host).Inc()
p.reqSz.Observe(float64(<-reqSz))
p.reqSz.Observe(float64(reqSz))
p.resSz.Observe(resSz)
}
}
Expand All @@ -247,7 +246,7 @@ func prometheusHandler() gin.HandlerFunc {
}

// From https://github.com/DanielHeckrath/gin-prometheus/blob/master/gin_prometheus.go
func computeApproximateRequestSize(r *http.Request, out chan int) {
func computeApproximateRequestSize(r *http.Request) int {
s := 0
if r.URL != nil {
s = len(r.URL.String())
Expand All @@ -268,5 +267,5 @@ func computeApproximateRequestSize(r *http.Request, out chan int) {
if r.ContentLength != -1 {
s += int(r.ContentLength)
}
out <- s
return s
}

0 comments on commit f200fd8

Please sign in to comment.