internal/prometheus: add tenant to http and status metrics
This commit is contained in:
parent
0f946e1c9e
commit
06038b2af6
3 changed files with 11 additions and 3 deletions
|
|
@ -7,6 +7,8 @@ import (
|
|||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/auth"
|
||||
)
|
||||
|
||||
func MetricsMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
|
@ -15,7 +17,10 @@ func MetricsMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
|
|||
if strings.HasSuffix(ctx.Path(), "/compose") {
|
||||
ComposeRequests.Inc()
|
||||
}
|
||||
timer := prometheus.NewTimer(httpDuration.WithLabelValues(ctx.Path()))
|
||||
|
||||
// leave tenant empty in case it's not in the context
|
||||
tenant, _ := ctx.Get(auth.TenantCtxKey).(string)
|
||||
timer := prometheus.NewTimer(httpDuration.WithLabelValues(ctx.Path(), tenant))
|
||||
defer timer.ObserveDuration()
|
||||
return next(ctx)
|
||||
}
|
||||
|
|
@ -35,6 +40,8 @@ func StatusMiddleware(subsystem string) func(next echo.HandlerFunc) echo.Handler
|
|||
path := pathLabel(ctx.Path())
|
||||
method := ctx.Request().Method
|
||||
status := ctx.Response().Status
|
||||
// leave tenant empty in case it's not in the context
|
||||
tenant, _ := ctx.Get(auth.TenantCtxKey).(string)
|
||||
|
||||
httpErr := new(echo.HTTPError)
|
||||
if errors.As(err, &httpErr) {
|
||||
|
|
@ -46,6 +53,7 @@ func StatusMiddleware(subsystem string) func(next echo.HandlerFunc) echo.Handler
|
|||
path,
|
||||
strconv.Itoa(status),
|
||||
subsystem,
|
||||
tenant,
|
||||
).Inc()
|
||||
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue