mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-26 22:16:14 -04:00
Improve the metrics for the proxy service.
* extend the instrumenter middleware to add a label with the name of
the service the request is being dispatched to
* add a native Prometheus histogram that tracks the durations and also
includes a label for the name of the service the request is being
dispatched to, as well as a 'result' label ('success',
'client-error', 'server-error') based on the HTTP status code of the
response
* add per-service gauge functions to count the number of in-flight
requests
* add a counter for routing failures, for when an inbound request
cannot be mapped to a route
* extend the route.RoutingInfo struct with a service attribute, and a
Service() getter
* remove the 'routing_failure_count' metric, as it is redundant
27 lines
623 B
Go
27 lines
623 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
"github.com/opencloud-eu/opencloud/services/proxy/pkg/metrics"
|
|
)
|
|
|
|
// Instrumenter provides a middleware to create metrics
|
|
func Instrumenter(m metrics.Metrics) func(next http.Handler) http.Handler {
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
m.InFlightInc(r)
|
|
defer m.InFlightDec(r)
|
|
|
|
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
|
|
|
|
next.ServeHTTP(ww, r)
|
|
|
|
m.Duration(r, ww.Status(), time.Since(start))
|
|
})
|
|
}
|
|
}
|