Skip to content

Commit

Permalink
add http prometheus metrics (#3432)
Browse files Browse the repository at this point in the history
This will add metrics to http endpoints to measure latency and to see if
other parts of infra are working

This will close #2421

Signed-off-by: Max Knee <max.knee@nytimes.com>
  • Loading branch information
maxknee committed Jan 2, 2024
1 parent 9152121 commit 3c37646
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/drone-server/inject_server.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions 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=
Expand Down
3 changes: 3 additions & 0 deletions handler/api/api.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions handler/web/web.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions operator/manager/rpc2/server.go
Expand Up @@ -2,13 +2,15 @@
// 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

import (
"net/http"

chiprometheus "github.com/766b/chi-prometheus"
"github.com/drone/drone/operator/manager"

"github.com/go-chi/chi"
Expand All @@ -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))
Expand Down

0 comments on commit 3c37646

Please sign in to comment.