-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(halo): ready command integrated into docker containers (#2179)
- Adds a new halo command `ready` indicating the readiness of the halo node. - Integrates the new command into the halo and halovisor images. - Implements a new prometheus metrics exposing the readiness status issue: #2091
- Loading branch information
Showing
10 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/omni-network/omni/lib/errors" | ||
"github.com/omni-network/omni/lib/log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type readyConfig struct { | ||
MonitoringURL string | ||
} | ||
|
||
func defaultReadyConfig() readyConfig { | ||
return readyConfig{ | ||
MonitoringURL: "http://localhost:26660", | ||
} | ||
} | ||
|
||
func newReadyCmd() *cobra.Command { | ||
cfg := defaultReadyConfig() | ||
|
||
cmd := &cobra.Command{ | ||
Use: "ready", | ||
Short: "Query remote node for readiness", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
err := queryReady(cmd.Context(), cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "ready") | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
bindReadyFlags(cmd, &cfg) | ||
|
||
return cmd | ||
} | ||
|
||
// queryReady calls halo's /ready endpoint and returns nil if the status is ready | ||
// or an error otherwise. | ||
func queryReady(ctx context.Context, cfg readyConfig) error { | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.MonitoringURL, nil) | ||
if err != nil { | ||
return errors.Wrap(err, "http request creation") | ||
} | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return errors.Wrap(err, "http request") | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode/100 != 2 { | ||
return errors.New("node not ready") | ||
} | ||
|
||
log.Info(ctx, "Node ready") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters