Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiTyping committed Sep 20, 2024
1 parent 767bd86 commit 1142eef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-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.
>When running multiple instances of `rly start`, you will need to use the `--enable-debug-server` and `--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)]
Expand Down
2 changes: 1 addition & 1 deletion cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func debugServerFlags(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(
flagDebugListenAddr,
"",
"address to use for debug and metrics server. By default, "+
"address to use for debug server. By default, "+
"will be the debug-listen-addr parameter in the global config. "+
"Make sure to enable debug server using --enable-debug-server flag.",
)
Expand Down
12 changes: 2 additions & 10 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ func setupMetricsServer(cmd *cobra.Command, a *appState, err error, chains map[s
a.log.Info("Metrics server is enabled")
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 --" +
metricsListenAddr +
" to pick a different address or port.",
)
a.log.Error(fmt.Sprintf("Failed to start metrics server. You can change the address and port using metrics-listen-addr config settingh or --metrics-listen-flag."))

return nil, fmt.Errorf("failed to listen on metrics address %q: %w", metricsListenAddr, err)
}
Expand Down Expand Up @@ -246,11 +242,7 @@ func setupDebugServer(cmd *cobra.Command, a *appState, err error) error {
a.log.Warn("SECURITY WARNING! Debug server should only be run with caution and proper security in place.")
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 --" +
debugListenAddr +
" to pick a different address or port.",
)
a.log.Error(fmt.Sprintf("Failed to start debug server. You can change the address and port using debug-listen-addr config settingh or --debug-listen-flag."))

return fmt.Errorf("failed to listen on debug address %q: %w", debugListenAddr, err)
}
Expand Down
30 changes: 15 additions & 15 deletions cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"go.uber.org/zap/zaptest/observer"
)

func TestMetricsServerFlag(t *testing.T) {
func TestMetricsServerFlags(t *testing.T) {
t.Parallel()

tests := []struct {
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestMissingMetricsListenAddr(t *testing.T) {
requireMessage(t, logs, "Disabled metrics server due to missing metrics-listen-addr setting in config file or --metrics-listen-addr flag.")
}

func TestDebugServerFlag(t *testing.T) {
func TestDebugServerFlags(t *testing.T) {
t.Parallel()

tests := []struct {
Expand Down Expand Up @@ -182,19 +182,6 @@ func TestDebugServerFlag(t *testing.T) {
}
}

func TestMissingDebugListenAddr(t *testing.T) {
sys := setupRelayer(t)

logs, logger := setupLogger()

updateConfig(t, sys, "debug-listen-addr: 127.0.0.1:5183", "")

sys.MustRunWithLogger(t, logger, []string{"start", "--enable-debug-server"}...)

requireDisabledMetricsServer(t, logs, 0)
requireMessage(t, logs, "Disabled debug server due to missing debug-listen-addr setting in config file or --debug-listen-addr flag.")
}

func TestDebugServerConfig(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -237,6 +224,19 @@ func TestDebugServerConfig(t *testing.T) {
}
}

func TestMissingDebugListenAddr(t *testing.T) {
sys := setupRelayer(t)

logs, logger := setupLogger()

updateConfig(t, sys, "debug-listen-addr: 127.0.0.1:5183", "")

sys.MustRunWithLogger(t, logger, []string{"start", "--enable-debug-server"}...)

requireDisabledMetricsServer(t, logs, 0)
requireMessage(t, logs, "Disabled debug server due to missing debug-listen-addr setting in config file or --debug-listen-addr flag.")
}

func requireDisabledMetricsServer(t *testing.T, logs *observer.ObservedLogs, port int) {
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port))
if conn != nil {
Expand Down

0 comments on commit 1142eef

Please sign in to comment.