2
0
Эх сурвалжийг харах

Merge pull request #1481 from porter-dev/enable-profiling

add pprof endpoints middleware
abelanger5 4 жил өмнө
parent
commit
4e3065028d

+ 5 - 0
api/server/router/router.go

@@ -7,6 +7,7 @@ import (
 	"strings"
 
 	"github.com/go-chi/chi"
+	chiMiddleware "github.com/go-chi/chi/middleware"
 	"github.com/porter-dev/porter/api/server/authn"
 	"github.com/porter-dev/porter/api/server/authz"
 	"github.com/porter-dev/porter/api/server/authz/policy"
@@ -50,6 +51,10 @@ func NewAPIRouter(config *config.Config) *chi.Mux {
 	userRegisterer := NewUserScopedRegisterer(projRegisterer)
 	panicMW := middleware.NewPanicMiddleware(config)
 
+	if config.ServerConf.PprofEnabled {
+		r.Mount("/debug", chiMiddleware.Profiler())
+	}
+
 	r.Route("/api", func(r chi.Router) {
 		// set panic middleware for all API endpoints to catch panics
 		r.Use(panicMW.Middleware)

+ 3 - 0
api/server/shared/config/env/envconfs.go

@@ -85,6 +85,9 @@ type ServerConf struct {
 
 	// Token for internal retool to authenticate to internal API endpoints
 	RetoolToken string `env:"RETOOL_TOKEN"`
+
+	// Enable pprof profiling endpoints
+	PprofEnabled bool `env:"PPROF_ENABLED,default=false"`
 }
 
 // DBConf is the database configuration: if generated from environment variables,