mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-06-10 13:30:49 +00:00
Limit cardinality for git_pages_http_request_* metrics.
V12-Ref: F-77243
This commit is contained in:
+7
-2
@@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -130,11 +131,15 @@ func ObserveHTTPHandler(handler http.Handler) http.Handler {
|
||||
next.ServeHTTP(&ow, r)
|
||||
duration := time.Since(start)
|
||||
|
||||
method := r.Method
|
||||
if !slices.Contains([]string{"HEAD", "GET", "PUT", "PATCH", "DELETE", "POST"}, method) {
|
||||
method = "!OTHER"
|
||||
}
|
||||
httpRequestCount.
|
||||
With(prometheus.Labels{"method": r.Method, "code": fmt.Sprintf("%d", ow.status)}).
|
||||
With(prometheus.Labels{"method": method, "code": fmt.Sprintf("%d", ow.status)}).
|
||||
Inc()
|
||||
httpRequestDurationSeconds.
|
||||
With(prometheus.Labels{"method": r.Method}).
|
||||
With(prometheus.Labels{"method": method}).
|
||||
Observe(duration.Seconds())
|
||||
})
|
||||
}(handler)
|
||||
|
||||
Reference in New Issue
Block a user