From e5e0c55967ae484170a132994a8ce40d87d3f560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nussbaumer?= Date: Mon, 22 Jul 2024 14:22:24 +0200 Subject: [PATCH] fix: include failed requests in total count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes: https://github.com/postfinance/kubenurse/issues/147 Signed-off-by: Clément Nussbaumer --- internal/servicecheck/httptrace.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/servicecheck/httptrace.go b/internal/servicecheck/httptrace.go index 636ca02..fc66e5c 100644 --- a/internal/servicecheck/httptrace.go +++ b/internal/servicecheck/httptrace.go @@ -34,7 +34,7 @@ func withHttptrace(registry *prometheus.Registry, next http.RoundTripper, durHis Name: "httpclient_requests_total", Help: "A counter for requests from the kubenurse http client.", }, - []string{"code", "method", "type"}, + []string{"code", "type"}, ) httpclientReqDuration := prometheus.NewHistogramVec( @@ -144,6 +144,11 @@ func withHttptrace(registry *prometheus.Registry, next http.RoundTripper, durHis } } else { eventType := "round_trip_error" + labels := map[string]string{ + "code": eventType, // we reuse round_trip_error as status code to prevent introducing a new label + "type": kubenurseRequestType, + } + httpclientReqTotal.With(labels).Inc() // also increment the total counter, as InstrumentRoundTripperCounter only instruments successful requests // errorCounter.WithLabelValues(eventType, kubenurseRequestType).Inc() // normally, errors are already accounted for in the ClientTrace section. // we still log the error, so in the future we can compare the log entries and see if somehow