Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pprof): Allow enabling pprof endpoint separately from debug flag #2710

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/relayproxy/api/routes_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Server) initMonitoringEndpoint(echoInstance *echo.Echo) {
echoInstance.GET("/health", cHealth.Handler)
echoInstance.GET("/info", cInfo.Handler)

if s.config.Debug {
if s.config.Debug || s.config.EnablePprof {
pprof.Register(echoInstance)
}
}
11 changes: 10 additions & 1 deletion cmd/relayproxy/api/routes_monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestPprofEndpointsStarts(t *testing.T) {
name string
MonitoringPort int
Debug bool
EnablePprof bool
expectedStatusCode int
}
tests := []test{
Expand All @@ -36,11 +37,18 @@ func TestPprofEndpointsStarts(t *testing.T) {
expectedStatusCode: http.StatusOK,
},
{
name: "pprof not available ii debug not enabled",
name: "pprof not available if debug not enabled",
Debug: false,
MonitoringPort: 1032,
expectedStatusCode: http.StatusNotFound,
},
{
name: "pprof available when enablePprof is true",
Debug: false,
EnablePprof: true,
MonitoringPort: 1032,
expectedStatusCode: http.StatusOK,
},
}

for _, tt := range tests {
Expand All @@ -55,6 +63,7 @@ func TestPprofEndpointsStarts(t *testing.T) {
MonitoringPort: tt.MonitoringPort,
ListenPort: 1031,
Debug: tt.Debug,
EnablePprof: tt.EnablePprof,
}

goff, err := service.NewGoFeatureFlagClient(c, z, []notifier.Notifier{})
Expand Down
5 changes: 5 additions & 0 deletions cmd/relayproxy/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ type Config struct {
// Default: false
Debug bool `mapstructure:"debug" koanf:"debug"`

// EnablePprof (optional) if true, go-feature-flag relay proxy will start
// the pprof endpoints on the same port as the monitoring.
// Default: false
EnablePprof bool `mapstructure:"enablePprof" koanf:"enablepprof"`

// EnableSwagger (optional) to have access to the swagger
EnableSwagger bool `mapstructure:"enableSwagger" koanf:"enableswagger"`

Expand Down
11 changes: 6 additions & 5 deletions website/docs/relay_proxy/profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ The information are exposed on the `/debug/pprof` endpoint, and we are using the
to expose the information.

:::warning
By default the profiling endpoints are disabled.
You have to run the relay proxy in debug mode if you want to enable them.
By default the profiling endpoints are disabled, and must be enabled in the configuration file.
:::

List of endpoints exposed is available http://localhost:1031/debug/pprof/

### Enable profiling

In your relay proxy configuration file you need to set the `debug` field to `true`.
In your relay proxy configuration file you need to set the `enablePprof` field to `true`.

```yaml {5}
retriever:
kind: file
path: /goff/flags.yaml # Location of your feature flag files
# ...
debug: true
```
enablePprof: true
```

_Note: the `debug` field also enables profiling, but it is deprecated._
Loading