Skip to content

Commit

Permalink
fix too many labels with querysting.
Browse files Browse the repository at this point in the history
  • Loading branch information
cupen committed Jul 22, 2019
1 parent 58963fb commit 70cd48d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
},
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 70cd48d

Please sign in to comment.