Enable http metrics (#3459)

Adding config option to enable http metrics

---------

Signed-off-by: Max Knee <max.knee@nytimes.com>
pull/3451/head
Max Knee 2024-04-24 10:40:32 -04:00 committed by GitHub
parent e1fc66e077
commit 94bcb869dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 15 deletions

View File

@ -170,6 +170,7 @@ type (
// Prometheus provides the prometheus configuration.
Prometheus struct {
EnableAnonymousAccess bool `envconfig:"DRONE_PROMETHEUS_ANONYMOUS_ACCESS" default:"false"`
EnableHTTPMetrics bool `envconfig:"DRONE_PROMETHEUS_HTTP_METRICS" default:"false"`
}
// Redis provides the redis configuration.

View File

@ -60,10 +60,12 @@ var serverSet = wire.NewSet(
// provideRouter is a Wire provider function that returns a
// 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 {
func provideRouter(api api.Server, web web.Server, rpcv1 rpcHandlerV1, rpcv2 rpcHandlerV2, healthz healthzHandler, metrics *metric.Server, pprof pprofHandler, config config.Config) *chi.Mux {
r := chi.NewRouter()
m := chiprometheus.NewMiddleware("server")
r.Use(m)
if config.Prometheus.EnableHTTPMetrics {
m := chiprometheus.NewPatternMiddleware("server")
r.Use(m)
}
r.Mount("/healthz", healthz)
r.Mount("/metrics", metrics)
r.Mount("/api", api.Handler())

View File

@ -1,7 +1,8 @@
// Code generated by Wire. DO NOT EDIT.
//go:generate wire
//+build !wireinject
//go:generate go run github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject
package main
@ -113,7 +114,7 @@ func InitializeApplication(config2 config.Config) (application, error) {
mainHealthzHandler := provideHealthz()
metricServer := provideMetric(session, config2)
mainPprofHandler := providePprof(config2)
mux := provideRouter(server, webServer, mainRpcHandlerV1, mainRpcHandlerV2, mainHealthzHandler, metricServer, mainPprofHandler)
mux := provideRouter(server, webServer, mainRpcHandlerV1, mainRpcHandlerV2, mainHealthzHandler, metricServer, mainPprofHandler, config2)
serverServer := provideServer(mux, config2)
mainApplication := newApplication(cronScheduler, reaper, datadog, runner, serverServer, userStore)
return mainApplication, nil

View File

@ -18,7 +18,6 @@ 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"
@ -163,8 +162,6 @@ 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)

View File

@ -25,7 +25,6 @@ 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"
@ -95,8 +94,6 @@ 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)

View File

@ -10,7 +10,6 @@ package rpc2
import (
"net/http"
chiprometheus "github.com/766b/chi-prometheus"
"github.com/drone/drone/operator/manager"
"github.com/go-chi/chi"
@ -25,8 +24,6 @@ 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))