Skip to content

Commit

Permalink
review: simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 11, 2020
1 parent fd15e24 commit 6fb5928
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pkg/middlewares/metrics/metrics.go
Expand Up @@ -74,11 +74,9 @@ func WrapServiceHandler(ctx context.Context, registry metrics.Registry, serviceN
}

func (m *metricsMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// Initialize labels slice with correct size
labels := make([]string, 0, 2*len([]string{"method", "protocol", "code"})+len(m.baseLabels))
var labels []string
labels = append(labels, m.baseLabels...)
// Adding 4 entries to labels
labels = append(labels, []string{"method", getMethod(req), "protocol", getRequestProtocol(req)}...)
labels = append(labels, "method", getMethod(req), "protocol", getRequestProtocol(req))

m.openConnsGauge.With(labels...).Add(1)
defer m.openConnsGauge.With(labels...).Add(-1)
Expand All @@ -88,7 +86,6 @@ func (m *metricsMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request)
m.next.ServeHTTP(recorder, req)
duration := time.Since(start).Seconds()

// Adding 2 entries to labels
labels = append(labels, "code", strconv.Itoa(recorder.getCode()))

m.reqsCounter.With(labels...).Add(1)
Expand Down

0 comments on commit 6fb5928

Please sign in to comment.