-
Notifications
You must be signed in to change notification settings - Fork 225
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
metrics: record message/request event even in case of error #464
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ func (dht *IpfsDHT) handleNewMessage(s network.Stream) bool { | |
var req pb.Message | ||
msgbytes, err := r.ReadMsg() | ||
if err != nil { | ||
defer r.ReleaseMsg(msgbytes) | ||
r.ReleaseMsg(msgbytes) | ||
if err == io.EOF { | ||
return true | ||
} | ||
|
@@ -96,6 +96,8 @@ func (dht *IpfsDHT) handleNewMessage(s network.Stream) bool { | |
ctx, | ||
[]tag.Mutator{tag.Upsert(metrics.KeyMessageType, "UNKNOWN")}, | ||
metrics.ReceivedMessageErrors.M(1), | ||
metrics.ReceivedMessages.M(1), | ||
metrics.ReceivedBytes.M(int64(req.Size())), | ||
MichaelMure marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
return false | ||
} | ||
|
@@ -107,6 +109,8 @@ func (dht *IpfsDHT) handleNewMessage(s network.Stream) bool { | |
ctx, | ||
[]tag.Mutator{tag.Upsert(metrics.KeyMessageType, "UNKNOWN")}, | ||
metrics.ReceivedMessageErrors.M(1), | ||
metrics.ReceivedMessages.M(1), | ||
metrics.ReceivedBytes.M(int64(req.Size())), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it could always be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that, let me know if that doesn't make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For requests, no. |
||
) | ||
return false | ||
} | ||
|
@@ -164,6 +168,12 @@ func (dht *IpfsDHT) handleNewMessage(s network.Stream) bool { | |
func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message) (*pb.Message, error) { | ||
ctx, _ = tag.New(ctx, metrics.UpsertMessageType(pmes)) | ||
|
||
stats.Record( | ||
ctx, | ||
metrics.SentRequests.M(1), | ||
metrics.SentBytes.M(int64(pmes.Size())), | ||
MichaelMure marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
ms, err := dht.messageSenderForPeer(ctx, p) | ||
if err != nil { | ||
stats.Record(ctx, metrics.SentRequestErrors.M(1)) | ||
|
@@ -183,8 +193,6 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message | |
|
||
stats.Record( | ||
ctx, | ||
metrics.SentRequests.M(1), | ||
metrics.SentBytes.M(int64(pmes.Size())), | ||
MichaelMure marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metrics.OutboundRequestLatency.M( | ||
float64(time.Since(start))/float64(time.Millisecond), | ||
), | ||
|
@@ -198,6 +206,12 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message | |
func (dht *IpfsDHT) sendMessage(ctx context.Context, p peer.ID, pmes *pb.Message) error { | ||
ctx, _ = tag.New(ctx, metrics.UpsertMessageType(pmes)) | ||
|
||
stats.Record( | ||
MichaelMure marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx, | ||
metrics.SentMessages.M(1), | ||
metrics.SentBytes.M(int64(pmes.Size())), | ||
MichaelMure marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
ms, err := dht.messageSenderForPeer(ctx, p) | ||
if err != nil { | ||
stats.Record(ctx, metrics.SentMessageErrors.M(1)) | ||
|
@@ -209,11 +223,6 @@ func (dht *IpfsDHT) sendMessage(ctx context.Context, p peer.ID, pmes *pb.Message | |
return err | ||
} | ||
|
||
stats.Record( | ||
ctx, | ||
metrics.SentMessages.M(1), | ||
metrics.SentBytes.M(int64(pmes.Size())), | ||
) | ||
logger.Event(ctx, "dhtSentMessage", dht.self, p, pmes) | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, we probably shouldn't record either a received message or a message error unless we receive a non-empty message. If the stream's broken for some reason, that's not something the DHT is really concerned about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be fair to not record anything at all ? My understanding is that if the stream is broken we don't get
io.EOF
but we don't have a message either.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I read your message, the more I get confused ;-). It seems to me that there is three thing we can do:
metrics.ReceivedMessages.M(1)
metrics.ReceivedMessages.M(1)
andmetrics.ReceivedMessageErrors.M(1)
So what about:
io.EOF
--> no messagelen(msgbytes)==0
--> no messagelen(msgbytes)!=0
--> broken messageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that, let me know if that doesn't make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might also return early on
err.Error() == "stream reset"
but that's quite brittle.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍