From c9ddee839b9dbb4d9aa0d062f92f22c7815f693e Mon Sep 17 00:00:00 2001 From: Matthew Whitehead Date: Tue, 11 Oct 2022 10:33:14 +0100 Subject: [PATCH 1/2] Listen for go debug on all interfaces, not just localhost Signed-off-by: Matthew Whitehead --- cmd/firefly.go | 5 +++-- internal/coreconfig/coreconfig.go | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/firefly.go b/cmd/firefly.go index 3a889ebb1..ffe03f74d 100644 --- a/cmd/firefly.go +++ b/cmd/firefly.go @@ -164,6 +164,7 @@ 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) @@ -171,11 +172,11 @@ func startFirefly(ctx context.Context, cancelCtx context.CancelFunc, mgr namespa 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() { diff --git a/internal/coreconfig/coreconfig.go b/internal/coreconfig/coreconfig.go index 56a0e0ae2..a4895b2b0 100644 --- a/internal/coreconfig/coreconfig.go +++ b/internal/coreconfig/coreconfig.go @@ -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 @@ -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), "") viper.SetDefault(string(DownloadWorkerCount), 10) viper.SetDefault(string(DownloadRetryMaxAttempts), 100) viper.SetDefault(string(DownloadRetryInitDelay), "100ms") From 172a65995a5c28126e9577cb061c9c7ef6c0aa3d Mon Sep 17 00:00:00 2001 From: Matthew Whitehead Date: Tue, 11 Oct 2022 13:59:54 +0100 Subject: [PATCH 2/2] Add docs entry for debug.address, revert default to localhost, update config test Signed-off-by: Matthew Whitehead --- docs/reference/config.md | 1 + internal/coreconfig/coreconfig.go | 2 +- internal/coreconfig/coreconfig_test.go | 2 ++ internal/coremsgs/en_config_descriptions.go | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/reference/config.md b/docs/reference/config.md index 4425795a1..2efe8ef08 100644 --- a/docs/reference/config.md +++ b/docs/reference/config.md @@ -464,6 +464,7 @@ nav_order: 2 |Key|Description|Type|Default Value| |---|-----------|----|-------------| +|address|The HTTP interface the go debugger binds to|`string`|`` |port|An HTTP port on which to enable the go debugger|`int`|`` ## download.retry diff --git a/internal/coreconfig/coreconfig.go b/internal/coreconfig/coreconfig.go index a4895b2b0..ba828acdd 100644 --- a/internal/coreconfig/coreconfig.go +++ b/internal/coreconfig/coreconfig.go @@ -361,7 +361,7 @@ func setDefaults() { viper.SetDefault(string(CacheOperationsTTL), "5m") viper.SetDefault(string(HistogramsMaxChartRows), 100) viper.SetDefault(string(DebugPort), -1) - viper.SetDefault(string(DebugAddress), "") + viper.SetDefault(string(DebugAddress), "localhost") viper.SetDefault(string(DownloadWorkerCount), 10) viper.SetDefault(string(DownloadRetryMaxAttempts), 100) viper.SetDefault(string(DownloadRetryInitDelay), "100ms") diff --git a/internal/coreconfig/coreconfig_test.go b/internal/coreconfig/coreconfig_test.go index f390c4f3f..3344cc0dd 100644 --- a/internal/coreconfig/coreconfig_test.go +++ b/internal/coreconfig/coreconfig_test.go @@ -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)) } diff --git a/internal/coremsgs/en_config_descriptions.go b/internal/coremsgs/en_config_descriptions.go index de083d383..8f0927b64 100644 --- a/internal/coremsgs/en_config_descriptions.go +++ b/internal/coremsgs/en_config_descriptions.go @@ -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)