country-geo-locations/internal/exporter/middleware.go
Tom Neuber 8b7f45563a
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful
chore(exporter): rework exporter to fix wrong histogram usage and cache metric data
2025-01-10 14:35:08 +01:00

20 lines
429 B
Go

package exporter
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
)
type Middleware struct {
metrics *Metrics
}
func (m Middleware) handler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
timer := prometheus.NewTimer(m.metrics.metricRequestLatency)
next.ServeHTTP(w, r)
m.metrics.metricRequestsTotal.Inc()
timer.ObserveDuration()
})
}