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 all commits
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
1 change: 1 addition & 0 deletions website/docs/relay_proxy/configure_relay_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ex: `AUTHORIZEDKEYS_EVALUATION=my-first-key,my-second-key`)_.
| `persistentFlagConfigurationFile` | string | **none** | If set GO Feature Flag will store the flags configuration in this file to be able to serve the flags even if none of the retrievers is available during starting time.<br/>By default, the flag configuration is not persisted and stays on the retriever system. By setting a file here, you ensure that GO Feature Flag will always start with a configuration but which can be out-dated.<br/><br/>_(example: `/tmp/goff_persist_conf.yaml`)_ |
| `startAsAwsLambda` | boolean | **`false`** | If set GO Feature Flag start the relay-proxy as a AWS Lambda, it means that it will start the server to receive request in the AWS format _(see `awsLambdaAdapter` to set the request/response format you are using)_. |
| `awsLambdaAdapter` | string | **`APIGatewayV2`** | This param is used only if `startAsAwsLambda` is `true`.<br/>This parameter allow you to decide which type of AWS lambda handler you wan to use.<br/>Accepted values are `APIGatewayV2`, `APIGatewayV1`, `ALB`. |
| `enablePprof` | boolean | **`false`** | This param is used to enable **pprof endpoints** if you wish to enable profiling. |

## type `authorizedKeys`

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