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
15 lines
288 B
Go
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, "/")
|
|
}
|