diff --git a/README.md b/README.md index 3c9d2e5df..095fcd323 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Additional information on how IBC works can be found [here](https://ibc.cosmos.n $ rly start ``` - >When running multiple instances of `rly start`, you will need to use the `--debug-addr` flag and provide an address:port. You can also pass an empty string `''` to turn off this feature or pass `localhost:0` to randomly select a port. + >When running multiple instances of `rly start`, you will need to use the `--debug-listen-addr` flag and provide an address:port. You can also pass an empty string `''` to turn off this feature or pass `localhost:0` to randomly select a port. --- [[TROUBLESHOOTING](docs/troubleshooting.md)] diff --git a/cmd/flags.go b/cmd/flags.go index b52d9674e..500b2287f 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -39,7 +39,9 @@ const ( flagOrder = "order" flagVersion = "version" flagEnableDebugServer = "enable-debug-server" + flagDebugListenAddr = "debug-listen-addr" flagEnableMetricsServer = "enable-metrics-server" + flagMetricsListenAddr = "metrics-listen-addr" flagOverwriteConfig = "overwrite" flagLimit = "limit" flagHeight = "height" @@ -419,6 +421,17 @@ func dstPortFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command { } func debugServerFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command { + cmd.Flags().String( + flagDebugListenAddr, + "", + "address to use for debug and metrics server. By default, "+ + "will be the debug-listen-addr parameter in the global config.", + ) + + if err := v.BindPFlag(flagDebugListenAddr, cmd.Flags().Lookup(flagDebugListenAddr)); err != nil { + panic(err) + } + cmd.Flags().Bool( flagEnableDebugServer, false, @@ -433,6 +446,17 @@ func debugServerFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command { } func metricsServerFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command { + cmd.Flags().String( + flagMetricsListenAddr, + "", + "address to use for metrics server. By default, "+ + "will be the metrics-listen-addr parameter in the global config.", + ) + + if err := v.BindPFlag(flagMetricsListenAddr, cmd.Flags().Lookup(flagMetricsListenAddr)); err != nil { + panic(err) + } + cmd.Flags().Bool( flagEnableMetricsServer, false, diff --git a/cmd/start.go b/cmd/start.go index c233109f0..8fe471d73 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -175,29 +175,38 @@ $ %s start demo-path2 --max-tx-size 10`, appName, appName, appName, appName)), func setupMetricsServer(cmd *cobra.Command, a *appState, err error, chains map[string]*relayer.Chain) (*processor.PrometheusMetrics, error) { var prometheusMetrics *processor.PrometheusMetrics - metricsAddr := a.config.Global.MetricsListenPort + metricsListenAddr := a.config.Global.MetricsListenPort + + metricsListenAddrFlag, err := cmd.Flags().GetString(flagMetricsListenAddr) + if err != nil { + return nil, err + } + + if metricsListenAddrFlag != "" { + metricsListenAddr = metricsListenAddrFlag + } flagEnableMetricsServer, err := cmd.Flags().GetBool(flagEnableMetricsServer) if err != nil { return nil, err } - if flagEnableMetricsServer == false || metricsAddr == "" { + if flagEnableMetricsServer == false || metricsListenAddr == "" { a.log.Warn("Disabled metrics server due to missing metrics-listen-addr setting in config file.") } else { a.log.Info("Metrics server is enabled.") - ln, err := net.Listen("tcp", metricsAddr) + ln, err := net.Listen("tcp", metricsListenAddr) if err != nil { a.log.Error( "Failed to listen on metrics address. If you have another relayer process open, use --" + - metricsAddr + + metricsListenAddr + " to pick a different address or port.", ) - return nil, fmt.Errorf("failed to listen on metrics address %q: %w", metricsAddr, err) + return nil, fmt.Errorf("failed to listen on metrics address %q: %w", metricsListenAddr, err) } log := a.log.With(zap.String("sys", "metricshttp")) - log.Info("Metrics server listening", zap.String("addr", metricsAddr)) + log.Info("Metrics server listening", zap.String("addr", metricsListenAddr)) prometheusMetrics = processor.NewPrometheusMetrics() relayermetrics.StartMetricsServer(cmd.Context(), log, ln, prometheusMetrics.Registry) for _, chain := range chains { @@ -210,29 +219,38 @@ func setupMetricsServer(cmd *cobra.Command, a *appState, err error, chains map[s } func setupDebugServer(cmd *cobra.Command, a *appState, err error) error { - debugAddr := a.config.Global.DebugListenPort + debugListenAddr := a.config.Global.DebugListenPort + + debugListenAddrFlag, err := cmd.Flags().GetString(flagDebugListenAddr) + if err != nil { + return err + } + + if debugListenAddrFlag != "" { + debugListenAddr = debugListenAddrFlag + } flagEnableDebugServer, err := cmd.Flags().GetBool(flagEnableDebugServer) if err != nil { return err } - if flagEnableDebugServer == false || debugAddr == "" { + if flagEnableDebugServer == false || debugListenAddr == "" { a.log.Warn("Disabled debug server due to missing debug-listen-addr setting in config file.") } else { a.log.Warn("SECURITY WARNING! Debug server is enabled. It should only be used with caution and proper security.") - ln, err := net.Listen("tcp", debugAddr) + ln, err := net.Listen("tcp", debugListenAddr) if err != nil { a.log.Error( "Failed to listen on debug address. If you have another relayer process open, use --" + - debugAddr + + debugListenAddr + " to pick a different address or port.", ) - return fmt.Errorf("failed to listen on debug address %q: %w", debugAddr, err) + return fmt.Errorf("failed to listen on debug address %q: %w", debugListenAddr, err) } log := a.log.With(zap.String("sys", "debughttp")) - log.Info("Debug server listening", zap.String("addr", debugAddr)) + log.Info("Debug server listening", zap.String("addr", debugListenAddr)) relaydebug.StartDebugServer(cmd.Context(), log, ln) } return nil diff --git a/cmd/start_test.go b/cmd/start_test.go index 1301e82b0..f3520efaf 100644 --- a/cmd/start_test.go +++ b/cmd/start_test.go @@ -23,14 +23,22 @@ func TestMetricsServerFlag(t *testing.T) { tests := []struct { args []string + wantedPort int wantedRunning bool }{ { []string{"start"}, + 0, false, }, { []string{"start", "--enable-metrics-server"}, + relayermetrics.MetricsServerPort, + true, + }, + { + []string{"start", "--enable-metrics-server", "--metrics-listen-addr", "127.0.0.1:7778"}, + 7778, true, }, } @@ -43,9 +51,9 @@ func TestMetricsServerFlag(t *testing.T) { sys.MustRunWithLogger(t, logger, tt.args...) if tt.wantedRunning == true { - requireRunningMetricsServer(t, logs, relayermetrics.MetricsServerPort) + requireRunningMetricsServer(t, logs, tt.wantedPort) } else { - requireDisabledMetricsServer(t, logs, relayermetrics.MetricsServerPort) + requireDisabledMetricsServer(t, logs, tt.wantedPort) } }) } @@ -72,6 +80,12 @@ func TestMetricsServerConfig(t *testing.T) { 6184, true, }, + { + []string{"start", "--enable-metrics-server", "--metrics-listen-addr", "127.0.0.1:7184"}, + "", + 7184, + true, + }, } for _, tt := range tests { @@ -98,14 +112,22 @@ func TestDebugServerFlag(t *testing.T) { tests := []struct { args []string + wantedPort int wantedRunning bool }{ { []string{"start"}, + 0, false, }, { []string{"start", "--enable-debug-server"}, + relaydebug.DebugServerPort, + true, + }, + { + []string{"start", "--enable-debug-server", "--debug-listen-addr", "127.0.0.1:7777"}, + 7777, true, }, } @@ -118,9 +140,9 @@ func TestDebugServerFlag(t *testing.T) { sys.MustRunWithLogger(t, logger, tt.args...) if tt.wantedRunning == true { - requireRunningDebugServer(t, logs, relaydebug.DebugServerPort) + requireRunningDebugServer(t, logs, tt.wantedPort) } else { - requireDisabledDebugServer(t, logs, relaydebug.DebugServerPort) + requireDisabledDebugServer(t, logs, tt.wantedPort) } }) } diff --git a/docs/advanced_usage.md b/docs/advanced_usage.md index def6c6b96..91fc94f0b 100644 --- a/docs/advanced_usage.md +++ b/docs/advanced_usage.md @@ -4,8 +4,10 @@ **Prometheus exporter** -If you started `rly` with the default `--debug-addr` argument, -you can use `http://$IP:5183/relayer/metrics` as a target for your prometheus scraper. +If you started `rly` with `--enable-metrics-server` argument, +you can use `http://127.0.0.1:5184/relayer/metrics` as a target for your prometheus scraper. + +You can use `--metrics-listen-addr $IP:7777` to customize the address and port where the metrics server. Exported metrics: diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 1988a16fa..af7c5ca21 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -65,11 +65,11 @@ $ rly query clients-expiration ## Inspect Go runtime debug data -If you started `rly` with the default `--debug-addr` argument, -you can open `http://localhost:7597` in your browser to explore details from the Go runtime. +If you started `rly` with `--enable-debug-server` argument, +you can open `http://127.0.0.1:5183` in your browser to explore details from the Go runtime. If you need active assistance from the Relayer development team regarding an unresponsive Relayer instance, -it will be helpful to provide the output from `http://localhost:7597/debug/pprof/goroutine?debug=2` at a minimum. +it will be helpful to provide the output from `http://127.0.0.1:7597/debug/pprof/goroutine?debug=2` at a minimum.
diff --git a/interchaintest/relayer.go b/interchaintest/relayer.go index 0aa4b1945..2ece6b085 100644 --- a/interchaintest/relayer.go +++ b/interchaintest/relayer.go @@ -290,7 +290,7 @@ func (r *Relayer) start(ctx context.Context, remainingArgs ...string) { // Start the debug server on a random port. // It won't be reachable without introspecting the output, // but this will allow catching any possible data races around the debug server. - args := append([]string{"start", "--debug-addr", "localhost:0"}, remainingArgs...) + args := append([]string{"start", "--enable-debug-server", "--debug-listen-addr", "localhost:0", "--enable-metrics-server", "--metrics-listen-addr", "localhost:0"}, remainingArgs...) res := r.Sys().RunC(ctx, r.log(), args...) if res.Err != nil { r.errCh <- res.Err