Something went wrong. Try again.
My PaaS for hosting multiple elasticsearch clusters in a Kubernetes environment.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132package server
import ( "net/http" "strconv" "time"
"level3.git.onstackit.cloud/LEVEL3/gabriel/src/metrics")
type statusRecorder struct { http.ResponseWriter status int}
func (s *statusRecorder) WriteHeader(code int) { s.status = code s.ResponseWriter.WriteHeader(code)}
// HTTPMiddleware records per-request metrics (count, duration, status) for every// request that flows through it. It must wrap the outermost handler so auth// failures (which short-circuit before the API handler) are also captured.func HTTPMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() rec := &statusRecorder{ResponseWriter: w, status: http.StatusOK} next.ServeHTTP(rec, r) metrics.RecordHTTP(r.Method, r.URL.Path, strconv.Itoa(rec.status), start) })}