feat: Add node uptime rpc / output in info command

This commit is contained in:
Łukasz Magiera 2022-10-05 19:44:55 +00:00
parent e74838f024
commit 2c11f9d265
17 changed files with 119 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package api
import ( import (
"context" "context"
"fmt" "fmt"
"time"
"github.com/google/uuid" "github.com/google/uuid"
@ -49,6 +50,9 @@ type Common interface {
// trigger graceful shutdown // trigger graceful shutdown
Shutdown(context.Context) error //perm:admin Shutdown(context.Context) error //perm:admin
// StartTime returns node start time
StartTime(context.Context) (time.Time, error) //perm:read
// Session returns a random UUID of api provider session // Session returns a random UUID of api provider session
Session(context.Context) (uuid.UUID, error) //perm:read Session(context.Context) (uuid.UUID, error) //perm:read

View File

@ -2272,6 +2272,21 @@ func (mr *MockFullNodeMockRecorder) Shutdown(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shutdown", reflect.TypeOf((*MockFullNode)(nil).Shutdown), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shutdown", reflect.TypeOf((*MockFullNode)(nil).Shutdown), arg0)
} }
// StartTime mocks base method.
func (m *MockFullNode) StartTime(arg0 context.Context) (time.Time, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StartTime", arg0)
ret0, _ := ret[0].(time.Time)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StartTime indicates an expected call of StartTime.
func (mr *MockFullNodeMockRecorder) StartTime(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartTime", reflect.TypeOf((*MockFullNode)(nil).StartTime), arg0)
}
// StateAccountKey mocks base method. // StateAccountKey mocks base method.
func (m *MockFullNode) StateAccountKey(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (address.Address, error) { func (m *MockFullNode) StateAccountKey(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (address.Address, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View File

@ -79,6 +79,8 @@ type CommonStruct struct {
Shutdown func(p0 context.Context) error `perm:"admin"` Shutdown func(p0 context.Context) error `perm:"admin"`
StartTime func(p0 context.Context) (time.Time, error) `perm:"read"`
Version func(p0 context.Context) (APIVersion, error) `perm:"read"` Version func(p0 context.Context) (APIVersion, error) `perm:"read"`
} }
} }
@ -1162,6 +1164,17 @@ func (s *CommonStub) Shutdown(p0 context.Context) error {
return ErrNotSupported return ErrNotSupported
} }
func (s *CommonStruct) StartTime(p0 context.Context) (time.Time, error) {
if s.Internal.StartTime == nil {
return *new(time.Time), ErrNotSupported
}
return s.Internal.StartTime(p0)
}
func (s *CommonStub) StartTime(p0 context.Context) (time.Time, error) {
return *new(time.Time), ErrNotSupported
}
func (s *CommonStruct) Version(p0 context.Context) (APIVersion, error) { func (s *CommonStruct) Version(p0 context.Context) (APIVersion, error) {
if s.Internal.Version == nil { if s.Internal.Version == nil {
return *new(APIVersion), ErrNotSupported return *new(APIVersion), ErrNotSupported

View File

@ -2157,6 +2157,21 @@ func (mr *MockFullNodeMockRecorder) Shutdown(arg0 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shutdown", reflect.TypeOf((*MockFullNode)(nil).Shutdown), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shutdown", reflect.TypeOf((*MockFullNode)(nil).Shutdown), arg0)
} }
// StartTime mocks base method.
func (m *MockFullNode) StartTime(arg0 context.Context) (time.Time, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StartTime", arg0)
ret0, _ := ret[0].(time.Time)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StartTime indicates an expected call of StartTime.
func (mr *MockFullNodeMockRecorder) StartTime(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartTime", reflect.TypeOf((*MockFullNode)(nil).StartTime), arg0)
}
// StateAccountKey mocks base method. // StateAccountKey mocks base method.
func (m *MockFullNode) StateAccountKey(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (address.Address, error) { func (m *MockFullNode) StateAccountKey(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (address.Address, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -41,7 +41,13 @@ func infoCmdAct(cctx *cli.Context) error {
return err return err
} }
start, err := fullapi.StartTime(ctx)
if err != nil {
return err
}
fmt.Printf("Network: %s\n", network.NetworkName) fmt.Printf("Network: %s\n", network.NetworkName)
fmt.Printf("StartTime: %s (started at %s)\n", time.Now().Sub(start).Truncate(time.Second), start.Truncate(time.Second))
fmt.Print("Chain: ") fmt.Print("Chain: ")
err = SyncBasefeeCheck(ctx, fullapi) err = SyncBasefeeCheck(ctx, fullapi)
if err != nil { if err != nil {

View File

@ -92,6 +92,12 @@ func infoCmdAct(cctx *cli.Context) error {
fmt.Println("Enabled subsystems (from markets API):", subsystems) fmt.Println("Enabled subsystems (from markets API):", subsystems)
start, err := fullapi.StartTime(ctx)
if err != nil {
return err
}
fmt.Printf("StartTime: %s (started at %s)\n", time.Now().Sub(start).Truncate(time.Second), start.Truncate(time.Second))
fmt.Print("Chain: ") fmt.Print("Chain: ")
err = lcli.SyncBasefeeCheck(ctx, fullapi) err = lcli.SyncBasefeeCheck(ctx, fullapi)

View File

@ -167,6 +167,8 @@
* [SectorsSummary](#SectorsSummary) * [SectorsSummary](#SectorsSummary)
* [SectorsUnsealPiece](#SectorsUnsealPiece) * [SectorsUnsealPiece](#SectorsUnsealPiece)
* [SectorsUpdate](#SectorsUpdate) * [SectorsUpdate](#SectorsUpdate)
* [Start](#Start)
* [StartTime](#StartTime)
* [Storage](#Storage) * [Storage](#Storage)
* [StorageAddLocal](#StorageAddLocal) * [StorageAddLocal](#StorageAddLocal)
* [StorageAttach](#StorageAttach) * [StorageAttach](#StorageAttach)
@ -3621,6 +3623,18 @@ Inputs:
Response: `{}` Response: `{}`
## Start
### StartTime
Perms: read
Inputs: `null`
Response: `"0001-01-01T00:00:00Z"`
## Storage ## Storage

View File

@ -156,6 +156,8 @@
* [PaychVoucherCreate](#PaychVoucherCreate) * [PaychVoucherCreate](#PaychVoucherCreate)
* [PaychVoucherList](#PaychVoucherList) * [PaychVoucherList](#PaychVoucherList)
* [PaychVoucherSubmit](#PaychVoucherSubmit) * [PaychVoucherSubmit](#PaychVoucherSubmit)
* [Start](#Start)
* [StartTime](#StartTime)
* [State](#State) * [State](#State)
* [StateAccountKey](#StateAccountKey) * [StateAccountKey](#StateAccountKey)
* [StateActorCodeCIDs](#StateActorCodeCIDs) * [StateActorCodeCIDs](#StateActorCodeCIDs)
@ -4615,6 +4617,18 @@ Response:
} }
``` ```
## Start
### StartTime
Perms: read
Inputs: `null`
Response: `"0001-01-01T00:00:00Z"`
## State ## State
The State methods are used to query, inspect, and interact with chain state. The State methods are used to query, inspect, and interact with chain state.
Most methods take a TipSetKey as a parameter. The state looked up is the parent state of the tipset. Most methods take a TipSetKey as a parameter. The state looked up is the parent state of the tipset.

View File

@ -164,6 +164,8 @@
* [PaychVoucherCreate](#PaychVoucherCreate) * [PaychVoucherCreate](#PaychVoucherCreate)
* [PaychVoucherList](#PaychVoucherList) * [PaychVoucherList](#PaychVoucherList)
* [PaychVoucherSubmit](#PaychVoucherSubmit) * [PaychVoucherSubmit](#PaychVoucherSubmit)
* [Start](#Start)
* [StartTime](#StartTime)
* [State](#State) * [State](#State)
* [StateAccountKey](#StateAccountKey) * [StateAccountKey](#StateAccountKey)
* [StateActorCodeCIDs](#StateActorCodeCIDs) * [StateActorCodeCIDs](#StateActorCodeCIDs)
@ -5047,6 +5049,18 @@ Response:
} }
``` ```
## Start
### StartTime
Perms: read
Inputs: `null`
Response: `"0001-01-01T00:00:00Z"`
## State ## State
The State methods are used to query, inspect, and interact with chain state. The State methods are used to query, inspect, and interact with chain state.
Most methods take a TipSetKey as a parameter. The state looked up is the parent state of the tipset. Most methods take a TipSetKey as a parameter. The state looked up is the parent state of the tipset.

View File

@ -155,6 +155,7 @@ func defaults() []Option {
Override(new(journal.DisabledEvents), journal.EnvDisabledEvents), Override(new(journal.DisabledEvents), journal.EnvDisabledEvents),
Override(new(journal.Journal), modules.OpenFilesystemJournal), Override(new(journal.Journal), modules.OpenFilesystemJournal),
Override(new(*alerting.Alerting), alerting.NewAlertingSystem), Override(new(*alerting.Alerting), alerting.NewAlertingSystem),
Override(new(dtypes.NodeStartTime), FromVal(dtypes.NodeStartTime(time.Now()))),
Override(CheckFDLimit, modules.CheckFdLimit(build.DefaultFDLimit)), Override(CheckFDLimit, modules.CheckFdLimit(build.DefaultFDLimit)),

View File

@ -2,6 +2,7 @@ package common
import ( import (
"context" "context"
"time"
"github.com/gbrlsnchs/jwt/v3" "github.com/gbrlsnchs/jwt/v3"
"github.com/google/uuid" "github.com/google/uuid"
@ -26,6 +27,8 @@ type CommonAPI struct {
Alerting *alerting.Alerting Alerting *alerting.Alerting
APISecret *dtypes.APIAlg APISecret *dtypes.APIAlg
ShutdownChan dtypes.ShutdownChan ShutdownChan dtypes.ShutdownChan
Start dtypes.NodeStartTime
} }
type jwtPayload struct { type jwtPayload struct {
@ -91,3 +94,7 @@ func (a *CommonAPI) Session(ctx context.Context) (uuid.UUID, error) {
func (a *CommonAPI) Closing(ctx context.Context) (<-chan struct{}, error) { func (a *CommonAPI) Closing(ctx context.Context) (<-chan struct{}, error) {
return make(chan struct{}), nil // relies on jsonrpc closing return make(chan struct{}), nil // relies on jsonrpc closing
} }
func (a *CommonAPI) StartTime(context.Context) (time.Time, error) {
return time.Time(a.Start), nil
}

View File

@ -1,6 +1,8 @@
package dtypes package dtypes
import ( import (
"time"
"github.com/gbrlsnchs/jwt/v3" "github.com/gbrlsnchs/jwt/v3"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
) )
@ -8,3 +10,5 @@ import (
type APIAlg jwt.HMACSHA type APIAlg jwt.HMACSHA
type APIEndpoint multiaddr.Multiaddr type APIEndpoint multiaddr.Multiaddr
type NodeStartTime time.Time

View File

@ -93,6 +93,12 @@ func From(typ interface{}) interface{} {
}).Interface() }).Interface()
} }
func FromVal[T any](v T) func() T {
return func() T {
return v
}
}
// from go-ipfs // from go-ipfs
// as casts input constructor to a given interface (if a value is given, it // as casts input constructor to a given interface (if a value is given, it
// wraps it into a constructor). // wraps it into a constructor).