Skip to content

Commit

Permalink
Merge pull request #1088 from matthew1001/debug-port-all-interfaces
Browse files Browse the repository at this point in the history
Allow listening for go debug on all interfaces, not just localhost
  • Loading branch information
peterbroadhurst authored Oct 11, 2022
2 parents 892ebae + 172a659 commit 2ba1adc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
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")
// 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))
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

0 comments on commit 2ba1adc

Please sign in to comment.