diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index ed6dd48..68f717d 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -26,10 +26,18 @@ basic_auth_enabled: true # Map of basic authentication users. The key is the username and the value is the password. Valid only when `basic_auth_enabled` is true. # # Default: {} +# basic_auth_users: user1: password1 user2: password2 +# +# Enable debug mode. +# +# Default: false +# +debug: false + # # Metrics server configuration. This is used to expose Prometheus metrics on endpoint `/metrics`. # diff --git a/go.mod b/go.mod index b303142..f7f350a 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.22 require ( github.com/cbrgm/githubevents v1.13.0 github.com/containerd/log v0.1.0 + github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/requestid v0.0.6 github.com/gin-gonic/gin v1.9.1 github.com/google/go-github/v60 v60.0.0 diff --git a/go.sum b/go.sum index 1fe407e..c90671c 100644 --- a/go.sum +++ b/go.sum @@ -312,6 +312,8 @@ github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcP github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg= +github.com/gin-contrib/pprof v1.4.0/go.mod h1:RrehPJasUVBPK6yTUwOl8/NP6i0vbUgmxtis+Z5KE90= github.com/gin-contrib/requestid v0.0.6 h1:mGcxTnHQ45F6QU5HQRgQUDsAfHprD3P7g2uZ4cSZo9o= github.com/gin-contrib/requestid v0.0.6/go.mod h1:9i4vKATX/CdggbkY252dPVasgVucy/ggBeELXuQztm4= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= diff --git a/server/config.go b/server/config.go index 7bf4799..65f6359 100644 --- a/server/config.go +++ b/server/config.go @@ -17,6 +17,7 @@ type Config struct { GitHub *GitHubConfig `yaml:"github" validate:"required"` Pools []*PoolConfig `yaml:"pools" validate:"required,min=1"` LogLevel string `yaml:"log_level" validate:"required,oneof=debug info warn error fatal panic trace"` + Debug bool `yaml:"debug" validate:""` path string } @@ -64,6 +65,7 @@ func DefaultConfig() *Config { GitHub: &GitHubConfig{AppPrivateKey: "", AppID: 0, WebhookSecret: ""}, Pools: []*PoolConfig{}, LogLevel: "debug", + Debug: false, } return c diff --git a/server/server.go b/server/server.go index 06124c0..9a5b0f3 100644 --- a/server/server.go +++ b/server/server.go @@ -8,6 +8,7 @@ import ( "sync" "time" + "github.com/gin-contrib/pprof" "github.com/gin-contrib/requestid" "github.com/gin-gonic/gin" "github.com/hostinger/fireactions" @@ -97,6 +98,10 @@ func New(config *Config, opts ...Opt) (*Server, error) { handler.GET("/healthz", getHealthzHandler()) handler.GET("/version", getVersionHandler()) + if config.Debug { + pprof.Register(handler) + } + api := handler.Group("/api") if config.BasicAuthEnabled { api.Use(gin.BasicAuth(gin.Accounts(config.BasicAuthUsers))) @@ -118,6 +123,9 @@ func New(config *Config, opts ...Opt) (*Server, error) { // Run starts the server and blocks until the context is canceled. func (s *Server) Run(ctx context.Context) error { s.logger.Info().Str("version", fireactions.Version).Str("date", fireactions.Date).Str("commit", fireactions.Commit).Msgf("Starting server on %s", s.config.BindAddress) + if s.config.Debug { + s.logger.Warn().Msg("Debug mode enabled") + } listener, err := net.Listen("tcp", s.config.BindAddress) if err != nil { diff --git a/server/testdata/config1.yaml b/server/testdata/config1.yaml index 173f44a..8f2914d 100644 --- a/server/testdata/config1.yaml +++ b/server/testdata/config1.yaml @@ -6,6 +6,8 @@ basic_auth_users: user1: password1 user2: password2 +debug: false + metrics: enabled: true address: 127.0.0.1:8081