@@ -17,6 +17,7 @@ import (
1717var defaultMetricPath = "/metrics"
1818
1919// Standard default metrics
20+ //
2021// counter, counter_vec, gauge, gauge_vec,
2122// histogram, histogram_vec, summary, summary_vec
2223var reqCnt = & Metric {
@@ -56,21 +57,6 @@ var standardMetrics = []*Metric{
5657/*
5758RequestCounterURLLabelMappingFn is a function which can be supplied to the middleware to control
5859the cardinality of the request counter's "url" label, which might be required in some contexts.
59- For instance, if for a "/customer/:name" route you don't want to generate a time series for every
60- possible customer name, you could use this function:
61-
62- func(c *gin.Context) string {
63- url := c.Request.URL.Path
64- for _, p := range c.Params {
65- if p.Key == "name" {
66- url = strings.Replace(url, p.Value, ":name", 1)
67- break
68- }
69- }
70- return url
71- }
72-
73- which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".
7460*/
7561type RequestCounterURLLabelMappingFn func (c * gin.Context ) string
7662
@@ -140,7 +126,9 @@ func NewPrometheus(subsystem string, customMetricsList ...[]*Metric) *Prometheus
140126 MetricsList : metricsList ,
141127 MetricsPath : defaultMetricPath ,
142128 ReqCntURLLabelMappingFn : func (c * gin.Context ) string {
143- return c .Request .URL .Path // i.e. by default do nothing, i.e. return URL as is
129+ // return route full path
130+ // map "/customer/alice" and "/customer/bob" to their template "/customer/:name"
131+ return c .FullPath ()
144132 },
145133 }
146134
0 commit comments