From 516ee3e20a10a8d287a50960635a1323069e8972 Mon Sep 17 00:00:00 2001 From: "Luke Hanley (LukeHandle)" Date: Sat, 22 Jan 2022 15:28:31 +0000 Subject: [PATCH] go/minotarproxy: clean up Prometheus metrics --- go/minotarproxy/minotarproxy.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/go/minotarproxy/minotarproxy.go b/go/minotarproxy/minotarproxy.go index 3aa2a6a157..b19456c37e 100644 --- a/go/minotarproxy/minotarproxy.go +++ b/go/minotarproxy/minotarproxy.go @@ -60,7 +60,7 @@ func (rt *roundRobinRoundtripper) RoundTrip(req *http.Request) (*http.Response, rt.mu.Unlock() handler := handlerName(req.Context()) - labels := prometheus.Labels{"handler": handler, "sourceIP": rt.sip[rt.last]} + labels := prometheus.Labels{"handler": handler} gi := rt.m.mInflight.With(labels) gi.Inc() defer gi.Dec() @@ -76,7 +76,8 @@ func (rt *roundRobinRoundtripper) RoundTrip(req *http.Request) (*http.Response, latency := time.Now().Sub(startTime) hl.Observe(latency.Seconds()) - cvr.With(prometheus.Labels{"responseCode": fmt.Sprintf("%d", resp.StatusCode)}).Inc() + respLabels := prometheus.Labels{"responseCode": fmt.Sprintf("%d", resp.StatusCode), "sourceIP": rt.sip[rt.last]} + cvr.With(respLabels).Inc() return resp, err } @@ -216,21 +217,21 @@ func main() { Name: "proxy_inflight", Help: "Count of current inflight HTTP requests, per source-IP", }, - []string{"handler", "sourceIP"}, + []string{"handler"}, ), mLatency: prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "proxy_latency", Help: "Histogram of request latency distributions", }, - []string{"handler", "sourceIP"}, + []string{"handler"}, ), mRequests: prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "proxy_requests", Help: "Count of requests that have passed through this proxy", }, - []string{"handler", "sourceIP"}, + []string{"handler"}, ), mResponses: prometheus.NewCounterVec( prometheus.CounterOpts{