Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: turn on pprof only on debug is on (#9978)

Danny Xu6d9d2c17491a
diff --git a/backend/bin/server/cmd/profile.go b/backend/bin/server/cmd/profile.go
index 4d801a929a..87d4956d56 100644
--- a/backend/bin/server/cmd/profile.go
+++ b/backend/bin/server/cmd/profile.go
@@ -27,6 +27,7 @@ func getBaseProfile(dataDir string) config.Profile {
SampleDatabasePort: sampleDatabasePort,
Readonly: flags.readonly,
SaaS: flags.saas,
+ Debug: flags.debug,
DataDir: dataDir,
ResourceDir: common.GetResourceDir(dataDir),
DemoName: flags.demoName,
diff --git a/backend/component/config/profile.go b/backend/component/config/profile.go
index 3bae70906d..f81bc137a2 100644
--- a/backend/component/config/profile.go
+++ b/backend/component/config/profile.go
@@ -32,6 +32,8 @@ type Profile struct {
Readonly bool
// When we are running in SaaS mode, some features are not allowed to edit by users.
SaaS bool
+ // Debug is the startup time debug
+ Debug bool
// DataDir is the directory stores the data including Bytebase's own database, backups, etc.
DataDir string
// ResourceDir is the directory stores the resources including embedded postgres, mysqlutil, mongoutil and etc.
diff --git a/backend/server/routers.go b/backend/server/routers.go
index 0036ab978f..e2557eb7df 100644
--- a/backend/server/routers.go
+++ b/backend/server/routers.go
@@ -17,9 +17,10 @@ import (
"google.golang.org/grpc"
"github.com/bytebase/bytebase/backend/common/log"
+ "github.com/bytebase/bytebase/backend/component/config"
)
-func configureEchoRouters(e *echo.Echo, grpcServer *grpc.Server, mux *grpcruntime.ServeMux) {
+func configureEchoRouters(e *echo.Echo, grpcServer *grpc.Server, mux *grpcruntime.ServeMux, profile config.Profile) {
// Embed frontend.
embedFrontend(e)
@@ -67,7 +68,9 @@ func configureEchoRouters(e *echo.Echo, grpcServer *grpc.Server, mux *grpcruntim
return context.JSON(http.StatusTooManyRequests, nil)
},
}))
- pprof.Register(e)
+ if profile.Debug {
+ pprof.Register(e)
+ }
p := prometheus.NewPrometheus("api", nil)
p.Use(e)
diff --git a/backend/server/server.go b/backend/server/server.go
index 129dd6551a..1a2def218f 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -335,7 +335,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {
recoveryStreamInterceptor,
),
)
- configureEchoRouters(s.e, s.grpcServer, mux)
+ configureEchoRouters(s.e, s.grpcServer, mux, profile)
postCreateUser := func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error {
if profile.TestOnlySkipOnboardingData {
return nil