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: invalid stamp metric #2502

Merged
merged 3 commits into from
Sep 15, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions pkg/pushsync/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import (
)

type metrics struct {
TotalSent prometheus.Counter
TotalReceived prometheus.Counter
TotalErrors prometheus.Counter
TotalHandlerErrors prometheus.Counter
TotalReplicated prometheus.Counter
TotalReplicatedError prometheus.Counter
TotalSendAttempts prometheus.Counter
TotalFailedSendAttempts prometheus.Counter
TotalSkippedPeers prometheus.Counter
TotalOutgoing prometheus.Counter
TotalOutgoingErrors prometheus.Counter
TotalSent prometheus.Counter
TotalReceived prometheus.Counter
TotalErrors prometheus.Counter
TotalHandlerErrors prometheus.Counter
TotalReplicated prometheus.Counter
TotalReplicatedError prometheus.Counter
TotalSendAttempts prometheus.Counter
TotalFailedSendAttempts prometheus.Counter
TotalSkippedPeers prometheus.Counter
TotalOutgoing prometheus.Counter
TotalOutgoingErrors prometheus.Counter
InvalidStampErrors prometheus.Counter
TotalHandlerReplicationErrors prometheus.Counter
}

func newMetrics() metrics {
Expand Down Expand Up @@ -94,6 +96,18 @@ func newMetrics() metrics {
Name: "total_outgoing_errors",
Help: "Total no of errors of entire operation to sync a chunk (multiple attempts included)",
}),
InvalidStampErrors: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "invalid_stamps",
Help: "No of invalid stamp errors.",
}),
TotalHandlerReplicationErrors: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_replication_handlers_errors",
Help: "Total no of errors of pushsync handler neighborhood replication.",
}),
}
}

Expand Down
15 changes: 14 additions & 1 deletion pkg/pushsync/pushsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,36 +164,47 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)
bytes := chunkAddress.Bytes()
if dcmp, _ := swarm.DistanceCmp(bytes, p.Address.Bytes(), ps.address.Bytes()); dcmp == 1 {
if ps.topologyDriver.IsWithinDepth(chunkAddress) {

ctxd, canceld := context.WithTimeout(context.Background(), timeToWaitForPushsyncToNeighbor)
defer canceld()

chunk, err = ps.validStamp(chunk, ch.Stamp)
if err != nil {
ps.metrics.InvalidStampErrors.Inc()
ps.metrics.TotalHandlerReplicationErrors.Inc()
return fmt.Errorf("pushsync valid stamp: %w", err)
}

_, err = ps.storer.Put(ctxd, storage.ModePutSync, chunk)
if err != nil {
ps.metrics.TotalHandlerReplicationErrors.Inc()
return fmt.Errorf("chunk store: %w", err)
}

debit, err := ps.accounting.PrepareDebit(p.Address, price)
if err != nil {
ps.metrics.TotalHandlerReplicationErrors.Inc()
return fmt.Errorf("prepare debit to peer %s before writeback: %w", p.Address.String(), err)
}
defer debit.Cleanup()

// return back receipt
signature, err := ps.signer.Sign(bytes)
if err != nil {
ps.metrics.TotalHandlerReplicationErrors.Inc()
return fmt.Errorf("receipt signature: %w", err)
}
receipt := pb.Receipt{Address: bytes, Signature: signature, BlockHash: ps.blockHash}
if err := w.WriteMsgWithContext(ctxd, &receipt); err != nil {
ps.metrics.TotalHandlerReplicationErrors.Inc()
return fmt.Errorf("send receipt to peer %s: %w", p.Address.String(), err)
}

return debit.Apply()
err = debit.Apply()
if err != nil {
ps.metrics.TotalHandlerReplicationErrors.Inc()
}
return err
}

return ErrOutOfDepthReplication
Expand All @@ -206,6 +217,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)

chunk, err = ps.validStamp(chunk, ch.Stamp)
if err != nil {
ps.metrics.InvalidStampErrors.Inc()
return fmt.Errorf("pushsync valid stamp: %w", err)
}

Expand All @@ -227,6 +239,7 @@ func (ps *PushSync) handler(ctx context.Context, p p2p.Peer, stream p2p.Stream)

chunk, err = ps.validStamp(chunk, ch.Stamp)
if err != nil {
ps.metrics.InvalidStampErrors.Inc()
return fmt.Errorf("pushsync valid stamp: %w", err)
}

Expand Down