Skip to content

Commit

Permalink
refactor(BUX-566): fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored and jakubmkowalski committed Feb 13, 2024
1 parent 9d7359a commit 32853ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// Metrics is the metrics collector
type Metrics struct {
gatherer prometheus.Gatherer
registerer prometheus.Registerer
}

// newMetrics will create a new Metrics object; this is private to ensure only one, global instance is created
func newMetrics() *Metrics {
registry := prometheus.NewRegistry()
constLabels := prometheus.Labels{"app": appName}
Expand All @@ -25,6 +27,7 @@ func newMetrics() *Metrics {
return m
}

func (m *Metrics) HttpHandler() http.Handler {
// HTTPHandler will return the http.Handler for the metrics
func (m *Metrics) HTTPHandler() http.Handler {
return promhttp.HandlerFor(metrics.gatherer, promhttp.HandlerOpts{Registry: metrics.registerer})
}
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *Server) Handlers() *nrhttprouter.Router {
s.Router.HTTPRouter.Handler(http.MethodGet, "/swagger", http.RedirectHandler("/swagger/index.html", http.StatusMovedPermanently))
s.Router.HTTPRouter.Handler(http.MethodGet, "/swagger/*any", httpSwagger.WrapHandler)
if metrics, enabled := metrics.Get(); enabled {
s.Router.HTTPRouter.Handler(http.MethodGet, "/metrics", metrics.HttpHandler())
s.Router.HTTPRouter.Handler(http.MethodGet, "/metrics", metrics.HTTPHandler())
}
segment.End()

Expand Down

0 comments on commit 32853ba

Please sign in to comment.