worker: add metrics

use prometheus to gather metrics
This commit is contained in:
Chloe Kaubisch 2021-05-05 14:29:50 +02:00 committed by Sanne Raymaekers
parent b5987a5ca5
commit 4c800f29a7
468 changed files with 63476 additions and 2668 deletions

View file

@ -21,6 +21,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/osbuild1"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/prometheus"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
"github.com/osbuild/osbuild-composer/internal/target"
"github.com/osbuild/osbuild-composer/internal/worker"
@ -55,6 +56,7 @@ func (server *Server) Handler(path string, identityFilter []string) http.Handler
server.identityFilter = identityFilter
r.Use(server.VerifyIdentityHeader)
}
r.Use(server.IncRequests)
r.Route(path, func(r chi.Router) {
HandlerFromMux(server, r)
})
@ -100,6 +102,16 @@ func (server *Server) VerifyIdentityHeader(next http.Handler) http.Handler {
})
}
func (s *Server) IncRequests(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
prometheus.TotalRequests.Inc()
if strings.HasSuffix(r.URL.Path, "/compose") {
prometheus.ComposeRequests.Inc()
}
next.ServeHTTP(w, r)
})
}
// Compose handles a new /compose POST request
func (server *Server) Compose(w http.ResponseWriter, r *http.Request) {
contentType := r.Header["Content-Type"]