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

Allow listening for go debug on all interfaces, not just localhost #1088

Merged
merged 2 commits into from
Oct 11, 2022
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
5 changes: 3 additions & 2 deletions cmd/firefly.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,19 @@ func startFirefly(ctx context.Context, cancelCtx context.CancelFunc, mgr namespa
// Start debug listener
var debugServer *http.Server
debugPort := config.GetInt(coreconfig.DebugPort)
debugAddress := config.GetString(coreconfig.DebugAddress)
if debugPort >= 0 {
r := mux.NewRouter()
r.PathPrefix("/debug/pprof/cmdline").HandlerFunc(pprof.Cmdline)
r.PathPrefix("/debug/pprof/profile").HandlerFunc(pprof.Profile)
r.PathPrefix("/debug/pprof/symbol").HandlerFunc(pprof.Symbol)
r.PathPrefix("/debug/pprof/trace").HandlerFunc(pprof.Trace)
r.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
debugServer = &http.Server{Addr: fmt.Sprintf("localhost:%d", debugPort), Handler: r, ReadHeaderTimeout: 30 * time.Second}
debugServer = &http.Server{Addr: fmt.Sprintf("%s:%d", debugAddress, debugPort), Handler: r, ReadHeaderTimeout: 30 * time.Second}
go func() {
_ = debugServer.ListenAndServe()
}()
log.L(ctx).Debugf("Debug HTTP endpoint listening on localhost:%d", debugPort)
log.L(ctx).Debugf("Debug HTTP endpoint listening on %s:%d", debugAddress, debugPort)
}

defer func() {
Expand Down
1 change: 1 addition & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ nav_order: 2

|Key|Description|Type|Default Value|
|---|-----------|----|-------------|
|address|The HTTP interface the go debugger binds to|`string`|`<nil>`
|port|An HTTP port on which to enable the go debugger|`int`|`<nil>`

## download.retry
Expand Down
3 changes: 3 additions & 0 deletions internal/coreconfig/coreconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ var (
PluginsIdentityList = ffc("plugins.identity")
// DebugPort a HTTP port on which to enable the go debugger
DebugPort = ffc("debug.port")
// DebugAddress the HTTP interface for the debugger to listen on
DebugAddress = ffc("debug.address")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you'll need to add a documentation entry for this one too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, let me do that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where to add the config doc:

ConfigDebugPort = ffc("config.debug.port", "An HTTP port on which to enable the go debugger", i18n.IntType)

Then make reference before you check in.

// EventTransportsDefault the default event transport for new subscriptions
EventTransportsDefault = ffc("event.transports.default")
// EventTransportsEnabled which event interface plugins are enabled
Expand Down Expand Up @@ -359,6 +361,7 @@ func setDefaults() {
viper.SetDefault(string(CacheOperationsTTL), "5m")
viper.SetDefault(string(HistogramsMaxChartRows), 100)
viper.SetDefault(string(DebugPort), -1)
viper.SetDefault(string(DebugAddress), "localhost")
viper.SetDefault(string(DownloadWorkerCount), 10)
viper.SetDefault(string(DownloadRetryMaxAttempts), 100)
viper.SetDefault(string(DownloadRetryInitDelay), "100ms")
Expand Down
2 changes: 2 additions & 0 deletions internal/coreconfig/coreconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ func TestInitConfigOK(t *testing.T) {
Reset()

assert.Equal(t, 25, config.GetInt(APIDefaultFilterLimit))
assert.Equal(t, "localhost", config.GetString(DebugAddress))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this test is for the config scaffolding code, rather than for individual fields - but all good 👍

assert.Equal(t, -1, config.GetInt(DebugPort))
}
3 changes: 2 additions & 1 deletion internal/coremsgs/en_config_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ var (

ConfigPluginDataexchangeFfdxProxyURL = ffc("config.plugins.dataexchange[].ffdx.proxy.url", "Optional HTTP proxy server to use when connecting to the Data Exchange", "URL "+i18n.StringType)

ConfigDebugPort = ffc("config.debug.port", "An HTTP port on which to enable the go debugger", i18n.IntType)
ConfigDebugPort = ffc("config.debug.port", "An HTTP port on which to enable the go debugger", i18n.IntType)
ConfigDebugAddress = ffc("config.debug.address", "The HTTP interface the go debugger binds to", i18n.StringType)

ConfigDownloadWorkerCount = ffc("config.download.worker.count", "The number of download workers", i18n.IntType)
ConfigDownloadWorkerQueueLength = ffc("config.download.worker.queueLength", "The length of the work queue in the channel to the workers - defaults to 2x the worker count", i18n.IntType)
Expand Down