diff options
author | Dave Henderson <dhenderson@gmail.com> | 2020-09-22 22:10:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-22 20:10:34 -0600 |
commit | f197cec7f3a599ca18807e7b7719ef7666cfdb70 (patch) | |
tree | 59561ce5893b6a9a6ef972285507e6c79dde42b6 /modules/caddyhttp | |
parent | be6daa5fd46edc9f66a5129347482b38e22bf103 (diff) |
metrics: Always track method label in uppercase (#3742)
* metrics: Always track method label in uppercase
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
* Just use strings.ToUpper for clarity
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r-- | modules/caddyhttp/metrics.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/modules/caddyhttp/metrics.go b/modules/caddyhttp/metrics.go index b764b90..3e5d639 100644 --- a/modules/caddyhttp/metrics.go +++ b/modules/caddyhttp/metrics.go @@ -4,6 +4,7 @@ import ( "context" "net/http" "strconv" + "strings" "sync" "time" @@ -108,7 +109,10 @@ func newMetricsInstrumentedHandler(handler string, mh MiddlewareHandler) *metric func (h *metricsInstrumentedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next Handler) error { server := serverNameFromContext(r.Context()) labels := prometheus.Labels{"server": server, "handler": h.handler} - statusLabels := prometheus.Labels{"server": server, "handler": h.handler, "method": r.Method, "code": ""} + method := strings.ToUpper(r.Method) + // the "code" value is set later, but initialized here to eliminate the possibility + // of a panic + statusLabels := prometheus.Labels{"server": server, "handler": h.handler, "method": method, "code": ""} inFlight := httpMetrics.requestInFlight.With(labels) inFlight.Inc() @@ -154,7 +158,6 @@ func sanitizeCode(code int) string { return "200" } return strconv.Itoa(code) - } // taken from https://github.com/prometheus/client_golang/blob/6007b2b5cae01203111de55f753e76d8dac1f529/prometheus/promhttp/instrument_server.go#L298 |