Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #34 delete querystring in labels #35

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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