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(agent):metrics for errors in agent #3449

Merged
4 commits merged into from Oct 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions pkg/storageincentives/agent.go
Expand Up @@ -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()
This conversation was marked as resolved.
Show resolved Hide resolved
block, err := a.backend.BlockNumber(context.Background())
if err != nil {
a.metrics.BackendErrors.Inc()
This conversation was marked as resolved.
Show resolved Hide resolved
a.logger.Error(err, "getting block number")
continue
}
Expand Down Expand Up @@ -271,22 +273,28 @@ 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
}

if isWinner {
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")
Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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
}

Expand Down
58 changes: 58 additions & 0 deletions pkg/storageincentives/metrics.go
Expand Up @@ -10,6 +10,7 @@ import (
)

type metrics struct {
// phase gauge and counter
CurrentPhase prometheus.Gauge
RevealPhase prometheus.Counter
CommitPhase prometheus.Counter
Expand All @@ -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
Comment on lines +23 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally these should be exposed by ChainBackend interface (or any other type wrapping this interface in order to provide this this functionality.


// metrics for err processing
ErrReveal prometheus.Counter
ErrCommit prometheus.Counter
ErrClaim prometheus.Counter
ErrWinner prometheus.Counter
ErrCheckIsPlaying prometheus.Counter
}

func newMetrics() metrics {
Expand Down Expand Up @@ -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",
}),
}
}

Expand Down