Skip to content

Commit

Permalink
Use consts for metric names
Browse files Browse the repository at this point in the history
  • Loading branch information
ypaq committed Jul 18, 2023
1 parent 4a04830 commit 474dfe2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions hmiddleware/httpmetrics/httpmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
"github.com/heroku/x/go-kit/metricsregistry"
)

const (
requestCount = "http.server.requests"
requestDuration = "http.server.request-duration.ms"
)

// New returns an HTTP middleware which captures request metrics and reports
// them to the given provider.
func New(p metrics.Provider) func(http.Handler) http.Handler {
Expand Down Expand Up @@ -97,8 +102,8 @@ func NewV2(p metrics.Provider) func(http.Handler) http.Handler {
"response-status", sts,
}

reg.GetOrRegisterCounter("http.server.requests").With(labels...).Add(1)
reg.GetOrRegisterExplicitHistogram("http.server.request-duration.ms", metrics.ThirtySecondDistribution).With(labels...).Observe(ms(dur))
reg.GetOrRegisterCounter(requestCount).With(labels...).Add(1)
reg.GetOrRegisterExplicitHistogram(requestDuration, metrics.ThirtySecondDistribution).With(labels...).Observe(ms(dur))
})
}
}
Expand Down

0 comments on commit 474dfe2

Please sign in to comment.