Skip to content

Commit

Permalink
simplify HealthReport() implementations (#10867)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Oct 5, 2023
1 parent edbcda7 commit 5d088a5
Show file tree
Hide file tree
Showing 23 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion common/headtracker/head_broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (hb *HeadBroadcaster[H, BLOCK_HASH]) Name() string {
}

func (hb *HeadBroadcaster[H, BLOCK_HASH]) HealthReport() map[string]error {
return map[string]error{hb.Name(): hb.StartStopOnce.Healthy()}
return map[string]error{hb.Name(): hb.Healthy()}
}

func (hb *HeadBroadcaster[H, BLOCK_HASH]) BroadcastNewLongestChain(head H) {
Expand Down
4 changes: 1 addition & 3 deletions common/headtracker/head_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ func (ht *HeadTracker[HTH, S, ID, BLOCK_HASH]) Name() string {
}

func (ht *HeadTracker[HTH, S, ID, BLOCK_HASH]) HealthReport() map[string]error {
report := map[string]error{
ht.Name(): ht.StartStopOnce.Healthy(),
}
report := map[string]error{ht.Name(): ht.Healthy()}
services.CopyHealth(report, ht.headListener.HealthReport())
return report
}
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) Name
}

func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) HealthReport() map[string]error {
return map[string]error{eb.Name(): eb.StartStopOnce.Healthy()}
return map[string]error{eb.Name(): eb.Healthy()}
}

// Trigger forces the monitor for a particular address to recheck for new txes
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Nam
}

func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) HealthReport() map[string]error {
return map[string]error{ec.Name(): ec.StartStopOnce.Healthy()}
return map[string]error{ec.Name(): ec.Healthy()}
}

func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) runLoop() {
Expand Down
2 changes: 1 addition & 1 deletion common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Name() str
}

func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) HealthReport() map[string]error {
report := map[string]error{b.Name(): b.StartStopOnce.Healthy()}
report := map[string]error{b.Name(): b.Healthy()}

// only query if txm started properly
b.IfStarted(func() {
Expand Down
9 changes: 4 additions & 5 deletions core/chains/cosmos/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
cosmosclient "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client"
coscfg "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/config"
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/db"
"github.com/smartcontractkit/chainlink/v2/core/services"

"github.com/smartcontractkit/chainlink-relay/pkg/logger"
"github.com/smartcontractkit/chainlink-relay/pkg/loop"
Expand Down Expand Up @@ -204,11 +205,9 @@ func (c *chain) Ready() error {
}

func (c *chain) HealthReport() map[string]error {
return map[string]error{
c.Name(): multierr.Combine(
c.StartStopOnce.Healthy(),
c.txm.Healthy()),
}
m := map[string]error{c.Name(): c.Healthy()}
services.CopyHealth(m, c.txm.HealthReport())
return m
}

// ChainService interface
Expand Down
4 changes: 1 addition & 3 deletions core/chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,7 @@ func (c *chain) Name() string {
}

func (c *chain) HealthReport() map[string]error {
report := map[string]error{
c.Name(): c.StartStopOnce.Healthy(),
}
report := map[string]error{c.Name(): c.Healthy()}
services.CopyHealth(report, c.txm.HealthReport())
services.CopyHealth(report, c.headBroadcaster.HealthReport())
services.CopyHealth(report, c.headTracker.HealthReport())
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/forwarders/forwarder_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,5 @@ func (f *FwdMgr) Close() error {
}

func (f *FwdMgr) HealthReport() map[string]error {
return map[string]error{f.Name(): f.StartStopOnce.Healthy()}
return map[string]error{f.Name(): f.Healthy()}
}
5 changes: 4 additions & 1 deletion core/chains/evm/gas/arbitrum_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/assets"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down Expand Up @@ -92,7 +93,9 @@ func (a *arbitrumEstimator) Close() error {
func (a *arbitrumEstimator) Ready() error { return a.StartStopOnce.Ready() }

func (a *arbitrumEstimator) HealthReport() map[string]error {
return map[string]error{a.Name(): a.StartStopOnce.Healthy()}
hp := map[string]error{a.Name(): a.Healthy()}
services.CopyHealth(hp, a.EvmEstimator.HealthReport())
return hp
}

// GetLegacyGas estimates both the gas price and the gas limit.
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/gas/block_history_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (b *BlockHistoryEstimator) Name() string {
return b.logger.Name()
}
func (b *BlockHistoryEstimator) HealthReport() map[string]error {
return map[string]error{b.Name(): b.StartStopOnce.Healthy()}
return map[string]error{b.Name(): b.Healthy()}
}

func (b *BlockHistoryEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLimit uint32, maxGasPriceWei *assets.Wei, _ ...feetypes.Opt) (gasPrice *assets.Wei, chainSpecificGasLimit uint32, err error) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/gas/l2_suggested_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (o *l2SuggestedPriceEstimator) Close() error {
}

func (o *l2SuggestedPriceEstimator) HealthReport() map[string]error {
return map[string]error{o.Name(): o.StartStopOnce.Healthy()}
return map[string]error{o.Name(): o.Healthy()}
}

func (o *l2SuggestedPriceEstimator) run() {
Expand Down
3 changes: 2 additions & 1 deletion core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"

commonfee "github.com/smartcontractkit/chainlink/v2/common/fee"
feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
commontypes "github.com/smartcontractkit/chainlink/v2/common/types"
Expand Down Expand Up @@ -212,7 +213,7 @@ func (e *WrappedEvmEstimator) Ready() error {
}

func (e *WrappedEvmEstimator) HealthReport() map[string]error {
report := map[string]error{e.Name(): e.StartStopOnce.Healthy()}
report := map[string]error{e.Name(): e.Healthy()}
services.CopyHealth(report, e.EvmEstimator.HealthReport())
if e.l1Oracle != nil {
services.CopyHealth(report, e.l1Oracle.HealthReport())
Expand Down
4 changes: 1 addition & 3 deletions core/chains/evm/gas/rollups/l1_gas_price_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ func (o *l1GasPriceOracle) Close() error {
})
}

func (o *l1GasPriceOracle) Ready() error { return o.StartStopOnce.Ready() }

func (o *l1GasPriceOracle) HealthReport() map[string]error {
return map[string]error{o.Name(): o.StartStopOnce.Healthy()}
return map[string]error{o.Name(): o.Healthy()}
}

func (o *l1GasPriceOracle) run() {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/log/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (b *broadcaster) Name() string {
}

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

func (b *broadcaster) awaitInitialSubscribers() {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (lp *logPoller) Name() string {
}

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

func (lp *logPoller) GetReplayFromBlock(ctx context.Context, requested int64) (int64, error) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/monitor/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (bm *balanceMonitor) Name() string {
}

func (bm *balanceMonitor) HealthReport() map[string]error {
return map[string]error{bm.Name(): bm.StartStopOnce.Healthy()}
return map[string]error{bm.Name(): bm.Healthy()}
}

// OnNewLongestChain checks the balance for each key
Expand Down
2 changes: 1 addition & 1 deletion core/chains/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (c *chain) Ready() error {
}

func (c *chain) HealthReport() map[string]error {
report := map[string]error{c.Name(): c.StartStopOnce.Healthy()}
report := map[string]error{c.Name(): c.Healthy()}
services.CopyHealth(report, c.txm.HealthReport())
return report
}
Expand Down
2 changes: 1 addition & 1 deletion core/chains/starknet/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (c *chain) Ready() error {
}

func (c *chain) HealthReport() map[string]error {
report := map[string]error{c.Name(): c.StartStopOnce.Healthy()}
report := map[string]error{c.Name(): c.Healthy()}
services.CopyHealth(report, c.txm.HealthReport())
return report
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/job/spawner.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (js *spawner) Name() string {
}

func (js *spawner) HealthReport() map[string]error {
return map[string]error{js.Name(): js.StartStopOnce.Healthy()}
return map[string]error{js.Name(): js.Healthy()}
}

func (js *spawner) startAllServices(ctx context.Context) {
Expand Down
4 changes: 1 addition & 3 deletions core/services/relay/evm/mercury/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,10 @@ func (mt *mercuryTransmitter) Close() error {
})
}

func (mt *mercuryTransmitter) Ready() error { return mt.StartStopOnce.Ready() }

func (mt *mercuryTransmitter) Name() string { return mt.lggr.Name() }

func (mt *mercuryTransmitter) HealthReport() map[string]error {
report := map[string]error{mt.Name(): mt.StartStopOnce.Healthy()}
report := map[string]error{mt.Name(): mt.Healthy()}
services.CopyHealth(report, mt.rpcClient.HealthReport())
services.CopyHealth(report, mt.queue.HealthReport())
return report
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (NoopTelemetryIngressBatchClient) Close() error { return nil }
// Send is a no-op
func (NoopTelemetryIngressBatchClient) Send(TelemPayload) {}

// Healthy is a no-op
func (NoopTelemetryIngressBatchClient) HealthReport() map[string]error { return map[string]error{} }
func (NoopTelemetryIngressBatchClient) Name() string { return "NoopTelemetryIngressBatchClient" }

Expand Down Expand Up @@ -163,7 +162,7 @@ func (tc *telemetryIngressBatchClient) Name() string {
}

func (tc *telemetryIngressBatchClient) HealthReport() map[string]error {
return map[string]error{tc.Name(): tc.StartStopOnce.Healthy()}
return map[string]error{tc.Name(): tc.Healthy()}
}

// getCSAPrivateKey gets the client's CSA private key
Expand Down
2 changes: 1 addition & 1 deletion core/services/synchronization/telemetry_ingress_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (tc *telemetryIngressClient) Name() string {
}

func (tc *telemetryIngressClient) HealthReport() map[string]error {
return map[string]error{tc.Name(): tc.StartStopOnce.Healthy()}
return map[string]error{tc.Name(): tc.Healthy()}
}

func (tc *telemetryIngressClient) connect(ctx context.Context, clientPrivKey []byte) {
Expand Down
2 changes: 1 addition & 1 deletion core/utils/mailbox_prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (m *MailboxMonitor) Close() error {
}

func (m *MailboxMonitor) HealthReport() map[string]error {
return map[string]error{m.Name(): m.StartStopOnce.Healthy()}
return map[string]error{m.Name(): m.Healthy()}
}

func (m *MailboxMonitor) monitorLoop(ctx context.Context, c <-chan time.Time) {
Expand Down

0 comments on commit 5d088a5

Please sign in to comment.