Skip to content

Commit

Permalink
Services implement HealthReport (#8534)
Browse files Browse the repository at this point in the history
* Services implement HealthReport

This PR implements HealthReport for all services in core node.
Current implementation is a 1:1 to previous Healthy() Logic
Next steps:
- Go over srvcs
- Define Healthy() correctly per service
- Implement HealthReport to return health status for the service as well
  as it's subservices.

* go generate

* fix tests

* lint fixes

* fix missing HealthReport defaults
  • Loading branch information
essamhassan authored Feb 24, 2023
1 parent f1b84db commit e7527e6
Show file tree
Hide file tree
Showing 49 changed files with 711 additions and 14 deletions.
8 changes: 8 additions & 0 deletions core/chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ func (c *chain) Healthy() (merr error) {
return
}

func (c *chain) Name() string {
return c.logger.Name()
}

func (c *chain) HealthReport() map[string]error {
return map[string]error{c.Name(): c.Healthy()}
}

func (c *chain) ID() *big.Int { return c.id }
func (c *chain) Client() evmclient.Client { return c.client }
func (c *chain) Config() evmconfig.ChainScopedConfig { return c.cfg }
Expand Down
9 changes: 9 additions & 0 deletions core/chains/evm/chain_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ func (cll *chainSet) Healthy() (err error) {
}
return
}

func (cll *chainSet) Name() string {
return cll.logger.Name()
}

func (cll *chainSet) HealthReport() map[string]error {
return map[string]error{cll.Name(): cll.Healthy()}
}

func (cll *chainSet) Ready() (err error) {
for _, c := range cll.Chains() {
err = multierr.Combine(err, c.Ready())
Expand Down
7 changes: 7 additions & 0 deletions core/chains/evm/gas/block_history_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ func (b *BlockHistoryEstimator) Close() error {
})
}

func (b *BlockHistoryEstimator) Name() string {
return b.logger.Name()
}
func (b *BlockHistoryEstimator) HealthReport() map[string]error {
return map[string]error{b.Name(): b.Healthy()}
}

func (b *BlockHistoryEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLimit uint32, maxGasPriceWei *assets.Wei, _ ...Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, err error) {
ok := b.IfStarted(func() {
chainSpecificGasLimit = applyMultiplier(gasLimit, b.config.EvmGasLimitMultiplier())
Expand Down
7 changes: 7 additions & 0 deletions core/chains/evm/headtracker/head_broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func (hb *headBroadcaster) Close() error {
})
}

func (hb *headBroadcaster) Name() string {
return hb.logger.Name()
}
func (hb *headBroadcaster) HealthReport() map[string]error {
return map[string]error{hb.Name(): hb.Healthy()}
}

func (hb *headBroadcaster) BroadcastNewLongestChain(head *evmtypes.Head) {
hb.mailbox.Deliver(head)
}
Expand Down
20 changes: 15 additions & 5 deletions core/chains/evm/headtracker/head_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ func (ht *headTracker) Healthy() error {
return nil
}

func (ht *headTracker) Name() string {
return ht.log.Name()
}

func (ht *headTracker) HealthReport() map[string]error {
return map[string]error{ht.Name(): ht.Healthy()}
}

func (ht *headTracker) Backfill(ctx context.Context, headWithChain *evmtypes.Head, depth uint) (err error) {
if uint(headWithChain.ChainLength()) >= depth {
return nil
Expand Down Expand Up @@ -346,11 +354,13 @@ var NullTracker httypes.HeadTracker = &nullTracker{}

type nullTracker struct{}

func (*nullTracker) Start(context.Context) error { return nil }
func (*nullTracker) Close() error { return nil }
func (*nullTracker) Ready() error { return nil }
func (*nullTracker) Healthy() error { return nil }
func (*nullTracker) SetLogLevel(zapcore.Level) {}
func (*nullTracker) Start(context.Context) error { return nil }
func (*nullTracker) Close() error { return nil }
func (*nullTracker) Ready() error { return nil }
func (*nullTracker) Healthy() error { return nil }
func (*nullTracker) HealthReport() map[string]error { return map[string]error{} }
func (*nullTracker) Name() string { return "" }
func (*nullTracker) SetLogLevel(zapcore.Level) {}
func (*nullTracker) Backfill(ctx context.Context, headWithChain *evmtypes.Head, depth uint) (err error) {
return nil
}
Expand Down
30 changes: 30 additions & 0 deletions core/chains/evm/headtracker/mocks/head_broadcaster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions core/chains/evm/headtracker/mocks/head_tracker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions core/chains/evm/log/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ func (b *broadcaster) Close() error {
})
}

func (b *broadcaster) Name() string {
return b.logger.Name()
}

func (b *broadcaster) HealthReport() map[string]error {
return map[string]error{b.Name(): b.Healthy()}
}

func (b *broadcaster) awaitInitialSubscribers() {
defer b.wgDone.Done()
b.logger.Debug("Starting to await initial subscribers until all dependents are ready...")
Expand Down Expand Up @@ -778,11 +786,14 @@ func (n *NullBroadcaster) AwaitDependents() <-chan struct{} {
// DependentReady does noop for NullBroadcaster.
func (n *NullBroadcaster) DependentReady() {}

func (n *NullBroadcaster) Name() string { return "" }

// Start does noop for NullBroadcaster.
func (n *NullBroadcaster) Start(context.Context) error { return nil }
func (n *NullBroadcaster) Close() error { return nil }
func (n *NullBroadcaster) Healthy() error { return nil }
func (n *NullBroadcaster) Ready() error { return nil }
func (n *NullBroadcaster) HealthReport() map[string]error { return nil }
func (n *NullBroadcaster) OnNewLongestChain(context.Context, *evmtypes.Head) {}
func (n *NullBroadcaster) Pause() {}
func (n *NullBroadcaster) Resume() {}
Expand Down
30 changes: 30 additions & 0 deletions core/chains/evm/log/mocks/broadcaster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions core/chains/evm/logpoller/disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var (

type disabled struct{}

func (disabled) Name() string { return "disabledLogPoller" }

func (disabled) Start(ctx context.Context) error { return ErrDisabled }

func (disabled) Close() error { return ErrDisabled }
Expand All @@ -24,6 +26,10 @@ func (disabled) Ready() error { return ErrDisabled }

func (disabled) Healthy() error { return ErrDisabled }

func (disabled) HealthReport() map[string]error {
return map[string]error{"disabledLogPoller": ErrDisabled}
}

func (disabled) Replay(ctx context.Context, fromBlock int64) error { return ErrDisabled }

func (disabled) RegisterFilter(filter Filter) error { return ErrDisabled }
Expand Down
8 changes: 8 additions & 0 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ func (lp *logPoller) Close() error {
})
}

func (lp *logPoller) Name() string {
return lp.lggr.Name()
}

func (lp *logPoller) HealthReport() map[string]error {
return map[string]error{lp.Name(): lp.Healthy()}
}

func (lp *logPoller) getReplayFromBlock(ctx context.Context, requested int64) (int64, error) {
lastProcessed, err := lp.orm.SelectLatestBlock(pg.WithParentCtx(ctx))
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions core/chains/evm/logpoller/mocks/log_poller.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions core/chains/evm/mocks/balance_monitor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e7527e6

Please sign in to comment.