debian-forge-composer/internal/prometheus/helpers.go
Gianluca Zuccarelli 8756ea717d prometheus: middleware to record 5xx errors
Create a custom middleware function
to measure 5xx requests for all composer
& worker routes and not just the `/composer`
endpoint. The result is a prometheus metric
that contains info on the request status code,
path & method.

A helper function has been added to clean the
dynamic parameters in the path routes to reduce
metric cardinality
2022-11-30 11:14:29 +01:00

15 lines
288 B
Go

package prometheus
import (
"regexp"
"strings"
)
func pathLabel(path string) string {
r := regexp.MustCompile(":(.*)")
segments := strings.Split(path, "/")
for i, segment := range segments {
segments[i] = r.ReplaceAllString(segment, "-")
}
return strings.Join(segments, "/")
}