Updated metrics

This commit is contained in:
Andrej Mickov
2026-02-27 16:38:51 +01:00
parent f04f7601c0
commit 6ca3fb8701
5 changed files with 530 additions and 112 deletions

View File

@@ -88,8 +88,13 @@ func HTTPMiddleware(logger *slog.Logger, cfg Config) func(http.Handler) http.Han
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
metrics.Default.IncHTTPInFlight()
defer metrics.Default.DecHTTPInFlight()
op := metricOperationLabel(r)
metrics.Default.IncHTTPInFlightOp(op)
metrics.Default.IncWorkerPoolActive()
defer func() {
metrics.Default.DecHTTPInFlightOp(op)
metrics.Default.DecWorkerPoolActive()
}()
requestID := middleware.GetReqID(r.Context())
if requestID != "" {
ww.Header().Set("x-amz-request-id", requestID)
@@ -103,7 +108,7 @@ func HTTPMiddleware(logger *slog.Logger, cfg Config) func(http.Handler) http.Han
status = http.StatusOK
}
route := metricRouteLabel(r)
metrics.Default.ObserveHTTPRequest(r.Method, route, status, elapsed, ww.BytesWritten())
metrics.Default.ObserveHTTPRequestDetailed(r.Method, route, op, status, elapsed, ww.BytesWritten())
if !cfg.Audit && !cfg.DebugMode {
return
@@ -167,6 +172,17 @@ func metricRouteLabel(r *http.Request) string {
return "/{bucket}/*"
}
func metricOperationLabel(r *http.Request) string {
if r == nil {
return "other"
}
isDeletePost := false
if r.Method == http.MethodPost && r.URL != nil {
_, isDeletePost = r.URL.Query()["delete"]
}
return metrics.NormalizeHTTPOperation(r.Method, isDeletePost)
}
func envBool(key string, defaultValue bool) bool {
raw := os.Getenv(key)
if raw == "" {