diff options
author | Dave Henderson <dhenderson@gmail.com> | 2022-01-25 15:34:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-25 15:34:35 -0500 |
commit | 741b0502ee7cb0ecbd6dd0517c4f186729f52718 (patch) | |
tree | a8dbe6a5bbb0aa10dc9ab9c2f5111e017e559358 /metrics.go | |
parent | 44e5e9e43f3583f04613bbbb1996e9b5a13a60ac (diff) | |
parent | 7ca5921a87c819f9848ccd7ec786aab0f896be72 (diff) |
Merge pull request #4545 from hairyhenderson/metrics-restrict-http-methods
metrics: Enforce smaller set of method labels
Diffstat (limited to 'metrics.go')
-rw-r--r-- | metrics.go | 16 |
1 files changed, 3 insertions, 13 deletions
@@ -2,9 +2,8 @@ package caddy import ( "net/http" - "strconv" - "strings" + "github.com/caddyserver/caddy/v2/internal/metrics" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promauto" @@ -46,8 +45,8 @@ func instrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler) d := newDelegator(w) next.ServeHTTP(d, r) counter.With(prometheus.Labels{ - "code": sanitizeCode(d.status), - "method": strings.ToUpper(r.Method), + "code": metrics.SanitizeCode(d.status), + "method": metrics.SanitizeMethod(r.Method), }).Inc() }) } @@ -67,12 +66,3 @@ func (d *delegator) WriteHeader(code int) { d.status = code d.ResponseWriter.WriteHeader(code) } - -func sanitizeCode(s int) string { - switch s { - case 0, 200: - return "200" - default: - return strconv.Itoa(s) - } -} |