Skip to content

Commit ff7c485

Browse files
committed
TUN-5261: Collect QUIC metrics about RTT, packets and bytes transfered and log events at tracing level
1 parent 958650b commit ff7c485

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+12360
-13
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ require (
7070
github.com/cheekybits/genny v1.0.0 // indirect
7171
github.com/davecgh/go-spew v1.1.1 // indirect
7272
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
73+
github.com/francoispqt/gojay v1.2.13 // indirect
7374
github.com/gdamore/encoding v1.0.0 // indirect
7475
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
7576
github.com/golang/protobuf v1.5.2 // indirect

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
197197
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
198198
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
199199
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
200+
github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk=
200201
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
201202
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
202203
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=

origin/tunnel.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/cloudflare/cloudflared/edgediscovery"
2121
"github.com/cloudflare/cloudflared/edgediscovery/allregions"
2222
"github.com/cloudflare/cloudflared/h2mux"
23+
quicpogs "github.com/cloudflare/cloudflared/quic"
2324
"github.com/cloudflare/cloudflared/retry"
2425
"github.com/cloudflare/cloudflared/signal"
2526
"github.com/cloudflare/cloudflared/tunnelrpc"
@@ -358,6 +359,7 @@ func serveTunnel(
358359
config,
359360
connOptions,
360361
controlStream,
362+
connIndex,
361363
reconnectCh,
362364
gracefulShutdownC)
363365

@@ -508,6 +510,7 @@ func ServeQUIC(
508510
config *TunnelConfig,
509511
connOptions *tunnelpogs.ConnectionOptions,
510512
controlStreamHandler connection.ControlStreamHandler,
513+
connIndex uint8,
511514
reconnectCh chan ReconnectSignal,
512515
gracefulShutdownC <-chan struct{},
513516
) (err error, recoverable bool) {
@@ -518,6 +521,7 @@ func ServeQUIC(
518521
MaxIncomingStreams: connection.MaxConcurrentStreams,
519522
MaxIncomingUniStreams: connection.MaxConcurrentStreams,
520523
KeepAlive: true,
524+
Tracer: quicpogs.NewClientTracer(config.Log, connIndex),
521525
}
522526
for {
523527
select {
@@ -559,19 +563,6 @@ func ServeQUIC(
559563
}
560564
}
561565

562-
type quicLogger struct {
563-
*zerolog.Logger
564-
}
565-
566-
func (ql *quicLogger) Write(p []byte) (n int, err error) {
567-
ql.Debug().Msgf("quic log: %v", string(p))
568-
return len(p), nil
569-
}
570-
571-
func (ql *quicLogger) Close() error {
572-
return nil
573-
}
574-
575566
func listenReconnect(ctx context.Context, reconnectCh <-chan ReconnectSignal, gracefulShutdownCh <-chan struct{}) error {
576567
select {
577568
case reconnect := <-reconnectCh:

quic/conversion.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package quic
2+
3+
import (
4+
"strconv"
5+
"time"
6+
7+
"github.com/lucas-clemente/quic-go/logging"
8+
)
9+
10+
func perspectiveString(p logging.Perspective) string {
11+
switch p {
12+
case logging.PerspectiveClient:
13+
return "client"
14+
case logging.PerspectiveServer:
15+
return "server"
16+
default:
17+
return ""
18+
}
19+
}
20+
21+
// Helper to convert logging.ByteCount(alias for int64) to float64 used in prometheus
22+
func byteCountToPromCount(count logging.ByteCount) float64 {
23+
return float64(count)
24+
}
25+
26+
// Helper to convert Duration to float64 used in prometheus
27+
func durationToPromGauge(duration time.Duration) float64 {
28+
return float64(duration.Milliseconds())
29+
}
30+
31+
// Helper to convert https://pkg.go.dev/github.com/lucas-clemente/[email protected]/logging#PacketType into string
32+
func packetTypeString(pt logging.PacketType) string {
33+
switch pt {
34+
case logging.PacketTypeInitial:
35+
return "initial"
36+
case logging.PacketTypeHandshake:
37+
return "handshake"
38+
case logging.PacketTypeRetry:
39+
return "retry"
40+
case logging.PacketType0RTT:
41+
return "0_rtt"
42+
case logging.PacketTypeVersionNegotiation:
43+
return "version_negotiation"
44+
case logging.PacketType1RTT:
45+
return "1_rtt"
46+
case logging.PacketTypeStatelessReset:
47+
return "stateless_reset"
48+
case logging.PacketTypeNotDetermined:
49+
return "undetermined"
50+
default:
51+
return "unknown_packet_type"
52+
}
53+
}
54+
55+
// Helper to convert https://pkg.go.dev/github.com/lucas-clemente/[email protected]/logging#PacketDropReason into string
56+
func packetDropReasonString(reason logging.PacketDropReason) string {
57+
switch reason {
58+
case logging.PacketDropKeyUnavailable:
59+
return "key_unavailable"
60+
case logging.PacketDropUnknownConnectionID:
61+
return "unknown_conn_id"
62+
case logging.PacketDropHeaderParseError:
63+
return "header_parse_err"
64+
case logging.PacketDropPayloadDecryptError:
65+
return "payload_decrypt_err"
66+
case logging.PacketDropProtocolViolation:
67+
return "protocol_violation"
68+
case logging.PacketDropDOSPrevention:
69+
return "dos_prevention"
70+
case logging.PacketDropUnsupportedVersion:
71+
return "unsupported_version"
72+
case logging.PacketDropUnexpectedPacket:
73+
return "unexpected_packet"
74+
case logging.PacketDropUnexpectedSourceConnectionID:
75+
return "unexpected_src_conn_id"
76+
case logging.PacketDropUnexpectedVersion:
77+
return "unexpected_version"
78+
case logging.PacketDropDuplicate:
79+
return "duplicate"
80+
default:
81+
return "unknown_reason"
82+
}
83+
}
84+
85+
// Helper to convert https://pkg.go.dev/github.com/lucas-clemente/[email protected]/logging#PacketLossReason into string
86+
func packetLossReasonString(reason logging.PacketLossReason) string {
87+
switch reason {
88+
case logging.PacketLossReorderingThreshold:
89+
return "reordering"
90+
case logging.PacketLossTimeThreshold:
91+
return "timeout"
92+
default:
93+
return "unknown_loss_reason"
94+
}
95+
}
96+
97+
func uint8ToString(input uint8) string {
98+
return strconv.FormatUint(uint64(input), 10)
99+
}

0 commit comments

Comments
 (0)