diff --git a/pkg/storageincentives/agent.go b/pkg/storageincentives/agent.go index fece14da8cb..1d04dcf0e06 100644 --- a/pkg/storageincentives/agent.go +++ b/pkg/storageincentives/agent.go @@ -228,8 +228,10 @@ func (a *Agent) start(blockTime time.Duration, blocksPerRound, blocksPerPhase ui case <-time.After(blockTime * time.Duration(checkEvery)): } + a.metrics.BackendCalls.Inc() block, err := a.backend.BlockNumber(context.Background()) if err != nil { + a.metrics.BackendErrors.Inc() a.logger.Error(err, "getting block number") continue } @@ -271,15 +273,20 @@ func (a *Agent) start(blockTime time.Duration, blocksPerRound, blocksPerPhase ui func (a *Agent) reveal(ctx context.Context, storageRadius uint8, sample, obfuscationKey []byte) error { a.metrics.RevealPhase.Inc() - return a.contract.Reveal(ctx, storageRadius, sample, obfuscationKey) + err := a.contract.Reveal(ctx, storageRadius, sample, obfuscationKey) + if err != nil { + a.metrics.ErrReveal.Inc() + } + return err } func (a *Agent) claim(ctx context.Context) error { - a.metrics.ClaimPhase.Inc() + // event claimPhase was processed isWinner, err := a.contract.IsWinner(ctx) if err != nil { + a.metrics.ErrWinner.Inc() return err } @@ -287,6 +294,7 @@ func (a *Agent) claim(ctx context.Context) error { a.metrics.Winner.Inc() err = a.contract.Claim(ctx) if err != nil { + a.metrics.ErrClaim.Inc() return fmt.Errorf("error claiming win: %w", err) } else { a.logger.Info("claimed win") @@ -310,6 +318,7 @@ func (a *Agent) play(ctx context.Context) (uint8, []byte, error) { isPlaying, err := a.contract.IsPlaying(ctx, storageRadius) if !isPlaying || err != nil { + a.metrics.ErrCheckIsPlaying.Inc() return 0, nil, err } @@ -322,15 +331,19 @@ func (a *Agent) play(ctx context.Context) (uint8, []byte, error) { } t := time.Now() + a.metrics.BackendCalls.Inc() block, err := a.backend.BlockNumber(ctx) if err != nil { + a.metrics.BackendErrors.Inc() return 0, nil, err } previousRoundNumber := (block / a.blocksPerRound) - 1 + a.metrics.BackendCalls.Inc() timeLimiterBlock, err := a.backend.HeaderByNumber(ctx, new(big.Int).SetUint64(previousRoundNumber*a.blocksPerRound)) if err != nil { + a.metrics.BackendErrors.Inc() return 0, nil, err } @@ -346,7 +359,6 @@ func (a *Agent) play(ctx context.Context) (uint8, []byte, error) { } func (a *Agent) commit(ctx context.Context, storageRadius uint8, sample []byte) ([]byte, error) { - a.metrics.CommitPhase.Inc() key := make([]byte, swarm.HashSize) @@ -361,6 +373,7 @@ func (a *Agent) commit(ctx context.Context, storageRadius uint8, sample []byte) err = a.contract.Commit(ctx, obfuscatedHash) if err != nil { + a.metrics.ErrCommit.Inc() return nil, err } diff --git a/pkg/storageincentives/metrics.go b/pkg/storageincentives/metrics.go index 22726e77fe8..522610698bd 100644 --- a/pkg/storageincentives/metrics.go +++ b/pkg/storageincentives/metrics.go @@ -10,6 +10,7 @@ import ( ) type metrics struct { + // phase gauge and counter CurrentPhase prometheus.Gauge RevealPhase prometheus.Counter CommitPhase prometheus.Counter @@ -18,6 +19,17 @@ type metrics struct { NeighborhoodSelected prometheus.Counter SampleDuration prometheus.Gauge Round prometheus.Gauge + + // total calls to chain backend + BackendCalls prometheus.Counter + BackendErrors prometheus.Counter + + // metrics for err processing + ErrReveal prometheus.Counter + ErrCommit prometheus.Counter + ErrClaim prometheus.Counter + ErrWinner prometheus.Counter + ErrCheckIsPlaying prometheus.Counter } func newMetrics() metrics { @@ -72,6 +84,52 @@ func newMetrics() metrics { Name: "round", Help: "Current round calculated from the block height.", }), + + // total call + BackendCalls: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "backend_calls", + Help: "total chain backend calls", + }), + BackendErrors: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "backend_errors", + Help: "total chain backend errors", + }), + + // phase errors + ErrReveal: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "reveal_phase_errors", + Help: "total reveal phase errors while processing", + }), + ErrCommit: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "commit_phase_errors", + Help: "total commit phase errors while processing", + }), + ErrClaim: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "claim_phase_errors", + Help: "total claim phase errors while processing", + }), + ErrWinner: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "win_phase_errors", + Help: "total win phase while processing", + }), + ErrCheckIsPlaying: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: m.Namespace, + Subsystem: subsystem, + Name: "is_playing_errors", + Help: "total neighborhood selected errors while processing", + }), } }