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"]

View file

@ -0,0 +1,27 @@
package prometheus
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
TotalRequests = promauto.NewCounter(prometheus.CounterOpts{
Name: "total_http_requests",
Help: "total number of http requests made to osbuild-composer",
})
)
var (
ComposeRequests = promauto.NewCounter(prometheus.CounterOpts{
Name: "total_compose_requests",
Help: "total number of compose requests made to osbuild-composer",
})
)
var (
ComposeSuccesses = promauto.NewCounter(prometheus.CounterOpts{
Name: "total_successful_compose_requests",
Help: "total number of successful compose requests",
})
)

View file

@ -19,6 +19,7 @@ import (
"github.com/labstack/echo/v4"
"github.com/osbuild/osbuild-composer/internal/jobqueue"
"github.com/osbuild/osbuild-composer/internal/prometheus"
"github.com/osbuild/osbuild-composer/internal/worker/api"
)
@ -300,6 +301,16 @@ func (s *Server) FinishJob(token uuid.UUID, result json.RawMessage) error {
}
}
var jobResult OSBuildJobResult
_, _, err = s.JobStatus(jobId, &jobResult)
if err != nil {
return fmt.Errorf("error finding job status: %v", err)
}
if jobResult.Success {
prometheus.ComposeSuccesses.Inc()
}
// Move artifacts from the temporary location to the final job
// location. Log any errors, but do not treat them as fatal. The job is
// already finished.