diff --git a/cmd/drone-server/inject_server.go b/cmd/drone-server/inject_server.go index 07302bd5eb..66ec3c2d0f 100644 --- a/cmd/drone-server/inject_server.go +++ b/cmd/drone-server/inject_server.go @@ -17,6 +17,7 @@ package main import ( "net/http" + chiprometheus "github.com/766b/chi-prometheus" "github.com/drone/drone/cmd/drone-server/config" "github.com/drone/drone/core" "github.com/drone/drone/handler/api" @@ -61,6 +62,8 @@ var serverSet = wire.NewSet( // router that is serves the provided handlers. func provideRouter(api api.Server, web web.Server, rpcv1 rpcHandlerV1, rpcv2 rpcHandlerV2, healthz healthzHandler, metrics *metric.Server, pprof pprofHandler) *chi.Mux { r := chi.NewRouter() + m := chiprometheus.NewMiddleware("server") + r.Use(m) r.Mount("/healthz", healthz) r.Mount("/metrics", metrics) r.Mount("/api", api.Handler()) diff --git a/go.mod b/go.mod index f476016052..a5b5250d84 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/drone/drone replace github.com/docker/docker => github.com/docker/engine v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible require ( + github.com/766b/chi-prometheus v0.0.0-20211217152057-87afa9aa2ca8 github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e github.com/Azure/azure-storage-blob-go v0.7.0 github.com/Azure/go-autorest/autorest/adal v0.8.3 // indirect diff --git a/go.sum b/go.sum index f938fcd7b9..017b385dfa 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= docker.io/go-docker v1.0.0/go.mod h1:7tiAn5a0LFmjbPDbyTPOaTTOuG1ZRNXdPA6RvKY+fpY= +github.com/766b/chi-prometheus v0.0.0-20211217152057-87afa9aa2ca8 h1:hK1G69lDhhrGqJbRA5i1rmT2KI/W77MSdr7hEGHqWdQ= +github.com/766b/chi-prometheus v0.0.0-20211217152057-87afa9aa2ca8/go.mod h1:X/LhbmoBoRu8TxoGIOIraVNhfz3hhikJoaelrOuhdPY= github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e h1:rl2Aq4ZODqTDkeSqQBy+fzpZPamacO1Srp8zq7jf2Sc= github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e/go.mod h1:Xa6lInWHNQnuWoF0YPSsx+INFA9qk7/7pTjwb3PInkY= github.com/Azure/azure-pipeline-go v0.2.1 h1:OLBdZJ3yvOn2MezlWvbrBMTEUQC72zAftRZOMdj5HYo= diff --git a/handler/api/api.go b/handler/api/api.go index a2c7d800ca..615b362c3e 100644 --- a/handler/api/api.go +++ b/handler/api/api.go @@ -18,6 +18,7 @@ import ( "net/http" "os" + chiprometheus "github.com/766b/chi-prometheus" "github.com/drone/drone/core" "github.com/drone/drone/handler/api/acl" "github.com/drone/drone/handler/api/auth" @@ -162,6 +163,8 @@ type Server struct { // Handler returns an http.Handler func (s Server) Handler() http.Handler { r := chi.NewRouter() + m := chiprometheus.NewMiddleware("api") + r.Use(m) r.Use(middleware.Recoverer) r.Use(middleware.NoCache) r.Use(logger.Middleware) diff --git a/handler/web/web.go b/handler/web/web.go index c886f6d7ba..056bb9e30a 100644 --- a/handler/web/web.go +++ b/handler/web/web.go @@ -25,6 +25,7 @@ import ( "github.com/drone/go-login/login" "github.com/drone/go-scm/scm" + chiprometheus "github.com/766b/chi-prometheus" "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/unrolled/secure" @@ -94,6 +95,8 @@ type Server struct { // Handler returns an http.Handler func (s Server) Handler() http.Handler { r := chi.NewRouter() + m := chiprometheus.NewMiddleware("web") + r.Use(m) r.Use(middleware.Recoverer) r.Use(middleware.NoCache) r.Use(logger.Middleware) diff --git a/operator/manager/rpc2/server.go b/operator/manager/rpc2/server.go index f5d587f346..05d732b211 100644 --- a/operator/manager/rpc2/server.go +++ b/operator/manager/rpc2/server.go @@ -2,6 +2,7 @@ // Use of this source code is governed by the Drone Non-Commercial License // that can be found in the LICENSE file. +//go:build !oss // +build !oss package rpc2 @@ -9,6 +10,7 @@ package rpc2 import ( "net/http" + chiprometheus "github.com/766b/chi-prometheus" "github.com/drone/drone/operator/manager" "github.com/go-chi/chi" @@ -23,6 +25,8 @@ type Server http.Handler // interaction with the build controller using the http transport. func NewServer(manager manager.BuildManager, secret string) Server { r := chi.NewRouter() + m := chiprometheus.NewMiddleware("drone") + r.Use(m) r.Use(middleware.Recoverer) r.Use(middleware.NoCache) r.Use(authorization(secret))