Merge pull request #1625 from concourse/pr/optional-prometheus-logger-sync

Optional Prometheus Registry
This commit is contained in:
Márk Sági-Kazár 2020-01-21 18:02:20 +01:00 committed by GitHub
commit 8894eed8d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -236,6 +236,13 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
}
}
instrumentHandlerCounter := func(handlerName string, handler http.Handler) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handler.ServeHTTP(w, r)
})
}
if c.PrometheusRegistry != nil {
requestCounter := prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "http_requests_total",
Help: "Count of all HTTP requests.",
@ -246,12 +253,13 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
return nil, fmt.Errorf("server: Failed to register Prometheus HTTP metrics: %v", err)
}
instrumentHandlerCounter := func(handlerName string, handler http.Handler) http.HandlerFunc {
instrumentHandlerCounter = func(handlerName string, handler http.Handler) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
m := httpsnoop.CaptureMetrics(handler, w, r)
requestCounter.With(prometheus.Labels{"handler": handlerName, "code": strconv.Itoa(m.Code), "method": r.Method}).Inc()
})
}
}
r := mux.NewRouter()
handle := func(p string, h http.Handler) {