Restructured authmiddleware fn and added tests (#2410)
* Created separate file for authmiddleware fn * Optimize auth login and middleware * Added unittests for authmiddleware * Fixed authURL * Removed featureConfig as global variable * Fix integration test according to examples repo changes * Fix integration test path for go module-example Co-authored-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
co-authored by
Sanket Sudake
parent
b98538ba24
commit
90c479b23c
@@ -62,31 +62,29 @@ func (rw *ResponseWriterWrapper) WriteHeader(statuscode int) {
|
||||
rw.ResponseWriter.WriteHeader(statuscode)
|
||||
}
|
||||
|
||||
func HTTPMetricMiddleware() mux.MiddlewareFunc {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if util.IsWebsocketRequest(r) {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
func HTTPMetricMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if util.IsWebsocketRequest(r) {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
labels := make(prometheus.Labels, 0)
|
||||
labels["path"] = r.URL.Path
|
||||
if route := mux.CurrentRoute(r); route != nil {
|
||||
if routePath, err := route.GetPathTemplate(); err == nil {
|
||||
labels["path"] = routePath
|
||||
}
|
||||
labels := make(prometheus.Labels, 0)
|
||||
labels["path"] = r.URL.Path
|
||||
if route := mux.CurrentRoute(r); route != nil {
|
||||
if routePath, err := route.GetPathTemplate(); err == nil {
|
||||
labels["path"] = routePath
|
||||
}
|
||||
}
|
||||
labels["method"] = r.Method
|
||||
rw := ResponseWriterWrapper{w, http.StatusOK}
|
||||
httpRequestInFlight.With(labels).Inc()
|
||||
httpRequestDuration := prometheus.NewTimer(httpRequestDuration.With(labels))
|
||||
defer func() {
|
||||
httpRequestDuration.ObserveDuration()
|
||||
httpRequestInFlight.With(labels).Dec()
|
||||
labels["code"] = fmt.Sprintf("%d", rw.statusCode)
|
||||
httpRequestsTotal.With(labels).Inc()
|
||||
}()
|
||||
next.ServeHTTP(&rw, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
labels["method"] = r.Method
|
||||
rw := ResponseWriterWrapper{w, http.StatusOK}
|
||||
httpRequestInFlight.With(labels).Inc()
|
||||
httpRequestDuration := prometheus.NewTimer(httpRequestDuration.With(labels))
|
||||
defer func() {
|
||||
httpRequestDuration.ObserveDuration()
|
||||
httpRequestInFlight.With(labels).Dec()
|
||||
labels["code"] = fmt.Sprintf("%d", rw.statusCode)
|
||||
httpRequestsTotal.With(labels).Inc()
|
||||
}()
|
||||
next.ServeHTTP(&rw, r)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user