Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc/node): readiness check #3118

Merged
merged 7 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nodebuilder/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ func ConstructModule(tp node.Type, network p2p.Network, cfg *Config, store Store
state.ConstructModule(tp, &cfg.State, &cfg.Core),
modhead.ConstructModule[*header.ExtendedHeader](tp, &cfg.Header),
share.ConstructModule(tp, &cfg.Share),
rpc.ConstructModule(tp, &cfg.RPC),
gateway.ConstructModule(tp, &cfg.Gateway),
core.ConstructModule(tp, &cfg.Core),
das.ConstructModule(tp, &cfg.DASer),
fraud.ConstructModule(tp),
blob.ConstructModule(),
node.ConstructModule(tp),
prune.ConstructModule(tp),
rpc.ConstructModule(tp, &cfg.RPC),
)

return fx.Module(
Expand Down
8 changes: 8 additions & 0 deletions nodebuilder/node/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ func (m *module) Info(context.Context) (Info, error) {
}, nil
}

func (m *module) Ready(context.Context) (bool, error) {
// Because the node uses FX to provide the RPC last, all services' lifecycles have been started by
// the point this endpoint is available. It is not 100% guaranteed at this point that all services
// are fully ready, but it is very high probability and all endpoints are available at this point
// regardless.
return true, nil
}

func (m *module) LogLevelSet(_ context.Context, name, level string) error {
return logging.SetLogLevel(name, level)
}
Expand Down
8 changes: 8 additions & 0 deletions nodebuilder/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type Module interface {
// Info returns administrative information about the node.
Info(context.Context) (Info, error)

// Ready returns true once the node's RPC is ready to accept requests.
Ready(context.Context) (bool, error)

// LogLevelSet sets the given component log level to the given level.
LogLevelSet(ctx context.Context, name, level string) error

Expand All @@ -28,6 +31,7 @@ var _ Module = (*API)(nil)
type API struct {
Internal struct {
Info func(context.Context) (Info, error) `perm:"admin"`
Ready func(context.Context) (bool, error) `perm:"read"`
LogLevelSet func(ctx context.Context, name, level string) error `perm:"admin"`
AuthVerify func(ctx context.Context, token string) ([]auth.Permission, error) `perm:"admin"`
AuthNew func(ctx context.Context, perms []auth.Permission) (string, error) `perm:"admin"`
Expand All @@ -38,6 +42,10 @@ func (api *API) Info(ctx context.Context) (Info, error) {
return api.Internal.Info(ctx)
}

func (api *API) Ready(ctx context.Context) (bool, error) {
return api.Internal.Ready(ctx)
}

func (api *API) LogLevelSet(ctx context.Context, name, level string) error {
return api.Internal.LogLevelSet(ctx, name, level)
}
Expand Down
4 changes: 4 additions & 0 deletions nodebuilder/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func TestNodeModule(t *testing.T) {
require.NoError(t, err)
require.Equal(t, info.APIVersion, node.APIVersion)

ready, err := client.Node.Ready(ctx)
require.NoError(t, err)
require.True(t, ready)

distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
perms, err := client.Node.AuthVerify(ctx, jwt)
require.NoError(t, err)
require.Equal(t, perms, adminPerms)
Expand Down
Loading