quic-go icon indicating copy to clipboard operation
quic-go copied to clipboard

Prometheus Metric for Packet Loss

Open gus3inov opened this issue 1 year ago • 3 comments

I would like to monitor packet loss for streams using Prometheus. I noticed server_received_packets_dropped_total metric: https://github.com/quic-go/quic-go/blob/f96923b5b276471d171d1363f1bc33bb6240e5c3/metrics/tracer.go#L37-L44

Could you confirm if this metric is suitable for tracking packet loss, or would it be better to implement my own custom metrics on both the client and server side? I was thinking of calculating packet loss with the following very simple formula: $\text{Packet Loss} = \frac{\text{Sent Packets} - \text{Received Packets}}{\text{Sent Packets}} \times 100$

gus3inov avatar Oct 24 '24 09:10 gus3inov

Unfortunately, it's a bit more complicated than that.

First of all, dropped packets is something completely different from lost packets. It refers to packets that we intentionally drop, for a variety of reasons (could be DoS protection, or because they're invalid in one sense or another).

If you wanted to determine the packet loss rate, you'd have to hook into the SentLongHeaderPacket,SentShortHeaderPacket and LostPacket packet callbacks on the ConnectionTracer.

This will work, however, it won't be super performant, since SentShortHeaderPacket assembles a slices of frames contained in the packet, which causes additional allocations: https://github.com/quic-go/quic-go/blob/98de6aebf7b139cd7ab3a93972ef9b9c1e378c1d/connection_logging.go#L115-L138

This won't matter unless you're aiming for Gbps transfer speeds, but it would make me hesitant to merge a PR that adds this feature.

I'm not quite sure yet what the best way would be to work around this problem. We might need to add a SentShortHeaderPacketWithoutFrames, which would be exactly the same as SentShortHeaderPacket, just without the frame slice. Or we could add some configuration flag to the logging.ConnectionTracer. Maybe a ExcludeFrames bool, and if it's set, we'd omit the frame slices on all events.

marten-seemann avatar Oct 24 '24 09:10 marten-seemann

@marten-seemann Thank you!

gus3inov avatar Oct 24 '24 09:10 gus3inov

Let's not close this. This is a totally valid feature request.

marten-seemann avatar Oct 24 '24 09:10 marten-seemann