Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chmllr committed Oct 17, 2024
1 parent 8f6c979 commit f9d0042
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions halo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ COPY --from=alpine:latest /tmp /tmp

COPY halo /app

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s CMD ["/app", "ready"]

# Mount home directory at /halo
VOLUME ["/halo"]

Expand Down
38 changes: 22 additions & 16 deletions halo/cmd/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"time"

"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"
Expand All @@ -14,13 +13,25 @@ import (
"github.com/spf13/cobra"
)

type readyConfig struct {
MonitoringAddr string
}

func defaultReadyConfig() readyConfig {
return readyConfig{
MonitoringAddr: fmt.Sprintf("http://0.0.0.0%v/ready", cmtcfg.DefaultInstrumentationConfig().PrometheusListenAddr),
}
}

func newReadyCmd() *cobra.Command {
cfg := defaultReadyConfig()

cmd := &cobra.Command{
Use: "ready",
Short: "Assert the readiness of the halo node",
Short: "Query node for readiness",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
err := assertReady(cmd.Context())
err := queryReady(cmd.Context(), cfg)
if err != nil {
return errors.Wrap(err, "ready failed")
}
Expand All @@ -32,16 +43,10 @@ func newReadyCmd() *cobra.Command {
return cmd
}

// assertReady calls halo's /ready endpoint and returns nil if the status is ready
// queryReady calls halo's /ready endpoint and returns nil if the status is ready
// or an error otherwise.
func assertReady(ctx context.Context) error {
cfg := cmtcfg.DefaultConfig()
url := fmt.Sprintf("http://0.0.0.0%v/ready", cfg.Instrumentation.PrometheusListenAddr)

ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
func queryReady(ctx context.Context, cfg readyConfig) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.MonitoringAddr, nil)
if err != nil {
return errors.Wrap(err, "http request creation")
}
Expand All @@ -52,10 +57,11 @@ func assertReady(ctx context.Context) error {
}
defer resp.Body.Close()

if resp.StatusCode < 400 {
log.Info(ctx, "The node is ready")
return nil
if resp.StatusCode/100 != 2 {
return errors.New("node not ready")
}

return errors.New("the node is not ready yet")
log.Info(ctx, "Node ready")

return nil
}
2 changes: 1 addition & 1 deletion halo/cmd/testdata/TestCLIReference_halo.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Available Commands:
consensus-pubkey Print the consensus public key
help Help about any command
init Initializes required halo files and directories
ready Assert the readiness of the halo node
ready Query node for readiness
rollback Rollback Cosmos SDK and CometBFT state by one height
run Runs the halo consensus client
status Query remote node for status
Expand Down

0 comments on commit f9d0042

Please sign in to comment.