From 70cd48db2df602a73afdef60828542bb2a9d67df Mon Sep 17 00:00:00 2001 From: cupen Date: Mon, 22 Jul 2019 16:15:43 +0800 Subject: [PATCH] fix too many labels with querysting. --- README.md | 2 +- middleware.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 11e782b..af24551 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ func main() { p := ginprometheus.NewPrometheus("gin") p.ReqCntURLLabelMappingFn = func(c *gin.Context) string { - url := c.Request.URL.String() + url := c.Request.URL.Path for _, p := range c.Params { if p.Key == "name" { url = strings.Replace(url, p.Value, ":name", 1) diff --git a/middleware.go b/middleware.go index d690b9d..7c655ee 100644 --- a/middleware.go +++ b/middleware.go @@ -58,7 +58,7 @@ For instance, if for a "/customer/:name" route you don't want to generate a time possible customer name, you could use this function: func(c *gin.Context) string { - url := c.Request.URL.String() + url := c.Request.URL.Path for _, p := range c.Params { if p.Key == "name" { url = strings.Replace(url, p.Value, ":name", 1) @@ -137,7 +137,7 @@ func NewPrometheus(subsystem string, customMetricsList ...[]*Metric) *Prometheus MetricsList: metricsList, MetricsPath: defaultMetricPath, ReqCntURLLabelMappingFn: func(c *gin.Context) string { - return c.Request.URL.String() // i.e. by default do nothing, i.e. return URL as is + return c.Request.URL.Path // i.e. by default do nothing, i.e. return URL as is }, } @@ -353,7 +353,7 @@ func (p *Prometheus) UseWithAuth(e *gin.Engine, accounts gin.Accounts) { // HandlerFunc defines handler function for middleware func (p *Prometheus) HandlerFunc() gin.HandlerFunc { return func(c *gin.Context) { - if c.Request.URL.String() == p.MetricsPath { + if c.Request.URL.Path == p.MetricsPath { c.Next() return } @@ -394,7 +394,7 @@ func prometheusHandler() gin.HandlerFunc { func computeApproximateRequestSize(r *http.Request) int { s := 0 if r.URL != nil { - s = len(r.URL.String()) + s = len(r.URL.Path) } s += len(r.Method)