Skip to content

Commit

Permalink
Merge pull request #2686 from lucas-clemente/pto-metrics
Browse files Browse the repository at this point in the history
add a metric for PTOs
  • Loading branch information
marten-seemann authored Jul 27, 2020
2 parents 222c1ee + ee04809 commit a854a4a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
connections = stats.Int64("quic-go/connections", "number of QUIC connections", stats.UnitDimensionless)
lostPackets = stats.Int64("quic-go/lost-packets", "number of packets declared lost", stats.UnitDimensionless)
sentPackets = stats.Int64("quic-go/sent-packets", "number of packets sent", stats.UnitDimensionless)
ptos = stats.Int64("quic-go/ptos", "number of times the PTO timer fired", stats.UnitDimensionless)
closes = stats.Int64("quic-go/close", "number of connections closed", stats.UnitDimensionless)
)

Expand All @@ -32,6 +33,7 @@ var (
keyCloseReason, _ = tag.NewKey("close_reason")
keyCloseRemote, _ = tag.NewKey("close_remote")
keyErrorCode, _ = tag.NewKey("error_code")
keyHandshakePhase, _ = tag.NewKey("handshake_phase")
)

// Views
Expand All @@ -51,6 +53,11 @@ var (
TagKeys: []tag.Key{keyPacketType},
Aggregation: view.Count(),
}
PTOView = &view.View{
Measure: ptos,
TagKeys: []tag.Key{keyHandshakePhase},
Aggregation: view.Count(),
}
CloseView = &view.View{
Measure: closes,
TagKeys: []tag.Key{keyCloseReason, keyErrorCode},
Expand Down Expand Up @@ -93,6 +100,8 @@ func (t *tracer) DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount,
type connTracer struct {
perspective logging.Perspective
tracer logging.Tracer

handshakeComplete bool
}

func newConnTracer(tracer logging.Tracer, perspective logging.Perspective) logging.ConnectionTracer {
Expand Down Expand Up @@ -158,10 +167,14 @@ func (t *connTracer) ClosedConnection(r logging.CloseReason) {
func (t *connTracer) SentTransportParameters(*logging.TransportParameters) {}
func (t *connTracer) ReceivedTransportParameters(*logging.TransportParameters) {}
func (t *connTracer) SentPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, _ *logging.AckFrame, _ []logging.Frame) {
typ := logging.PacketTypeFromHeader(&hdr.Header)
if typ == logging.PacketType1RTT {
t.handshakeComplete = true
}
stats.RecordWithTags(
context.Background(),
[]tag.Mutator{
tag.Upsert(keyPacketType, packetType(logging.PacketTypeFromHeader(&hdr.Header)).String()),
tag.Upsert(keyPacketType, packetType(typ).String()),
},
sentPackets.M(1),
)
Expand All @@ -184,7 +197,20 @@ func (t *connTracer) LostPacket(encLevel logging.EncryptionLevel, _ logging.Pack
lostPackets.M(1),
)
}
func (t *connTracer) UpdatedPTOCount(value uint32) {}
func (t *connTracer) UpdatedPTOCount(value uint32) {
if value == 0 {
return
}
phase := "during_handshake"
if t.handshakeComplete {
phase = "after_handshake"
}
stats.RecordWithTags(
context.Background(),
[]tag.Mutator{tag.Upsert(keyHandshakePhase, phase)},
ptos.M(1),
)
}
func (t *connTracer) UpdatedKeyFromTLS(logging.EncryptionLevel, logging.Perspective) {}
func (t *connTracer) UpdatedKey(logging.KeyPhase, bool) {}
func (t *connTracer) DroppedEncryptionLevel(logging.EncryptionLevel) {}
Expand Down

0 comments on commit a854a4a

Please sign in to comment.