77
88 "github.com/prometheus/client_golang/prometheus"
99 "github.com/quic-go/quic-go/logging"
10+ "github.com/rs/zerolog"
1011)
1112
1213const (
1819 clientMetrics = struct {
1920 totalConnections prometheus.Counter
2021 closedConnections prometheus.Counter
22+ maxUDPPayloadSize * prometheus.GaugeVec
2123 sentFrames * prometheus.CounterVec
2224 sentBytes * prometheus.CounterVec
2325 receivedFrames * prometheus.CounterVec
4547 Help : "Number of connections that has been closed" ,
4648 },
4749 ),
50+ maxUDPPayloadSize : prometheus .NewGaugeVec (
51+ prometheus.GaugeOpts {
52+ Namespace : namespace ,
53+ Subsystem : "client" ,
54+ Name : "max_udp_payload" ,
55+ Help : "Maximum UDP payload size in bytes for a QUIC packet" ,
56+ },
57+ clientConnLabels ,
58+ ),
4859 sentFrames : prometheus .NewCounterVec (
4960 prometheus.CounterOpts {
5061 Namespace : namespace ,
@@ -148,14 +159,16 @@ var (
148159)
149160
150161type clientCollector struct {
151- index string
162+ index string
163+ logger * zerolog.Logger
152164}
153165
154- func newClientCollector (index uint8 ) * clientCollector {
166+ func newClientCollector (index string , logger * zerolog. Logger ) * clientCollector {
155167 registerClient .Do (func () {
156168 prometheus .MustRegister (
157169 clientMetrics .totalConnections ,
158170 clientMetrics .closedConnections ,
171+ clientMetrics .maxUDPPayloadSize ,
159172 clientMetrics .sentFrames ,
160173 clientMetrics .sentBytes ,
161174 clientMetrics .receivedFrames ,
@@ -169,25 +182,32 @@ func newClientCollector(index uint8) *clientCollector {
169182 packetTooBigDropped ,
170183 )
171184 })
185+
172186 return & clientCollector {
173- index : uint8ToString (index ),
187+ index : index ,
188+ logger : logger ,
174189 }
175190}
176191
177192func (cc * clientCollector ) startedConnection () {
178193 clientMetrics .totalConnections .Inc ()
179194}
180195
181- func (cc * clientCollector ) closedConnection (err error ) {
196+ func (cc * clientCollector ) closedConnection (error ) {
182197 clientMetrics .closedConnections .Inc ()
183198}
184199
200+ func (cc * clientCollector ) receivedTransportParameters (params * logging.TransportParameters ) {
201+ clientMetrics .maxUDPPayloadSize .WithLabelValues (cc .index ).Set (float64 (params .MaxUDPPayloadSize ))
202+ cc .logger .Debug ().Msgf ("Received transport parameters: MaxUDPPayloadSize=%d, MaxIdleTimeout=%v, MaxDatagramFrameSize=%d" , params .MaxUDPPayloadSize , params .MaxIdleTimeout , params .MaxDatagramFrameSize )
203+ }
204+
185205func (cc * clientCollector ) sentPackets (size logging.ByteCount , frames []logging.Frame ) {
186- cc .collectPackets (size , frames , clientMetrics .sentFrames , clientMetrics .sentBytes )
206+ cc .collectPackets (size , frames , clientMetrics .sentFrames , clientMetrics .sentBytes , sent )
187207}
188208
189209func (cc * clientCollector ) receivedPackets (size logging.ByteCount , frames []logging.Frame ) {
190- cc .collectPackets (size , frames , clientMetrics .receivedFrames , clientMetrics .receivedBytes )
210+ cc .collectPackets (size , frames , clientMetrics .receivedFrames , clientMetrics .receivedBytes , received )
191211}
192212
193213func (cc * clientCollector ) bufferedPackets (packetType logging.PacketType ) {
@@ -212,8 +232,14 @@ func (cc *clientCollector) updatedRTT(rtt *logging.RTTStats) {
212232 clientMetrics .smoothedRTT .WithLabelValues (cc .index ).Set (durationToPromGauge (rtt .SmoothedRTT ()))
213233}
214234
215- func (cc * clientCollector ) collectPackets (size logging.ByteCount , frames []logging.Frame , counter , bandwidth * prometheus.CounterVec ) {
235+ func (cc * clientCollector ) collectPackets (size logging.ByteCount , frames []logging.Frame , counter , bandwidth * prometheus.CounterVec , direction direction ) {
216236 for _ , frame := range frames {
237+ switch f := frame .(type ) {
238+ case logging.DataBlockedFrame :
239+ cc .logger .Debug ().Msgf ("%s data_blocked frame" , direction )
240+ case logging.StreamDataBlockedFrame :
241+ cc .logger .Debug ().Int64 ("streamID" , int64 (f .StreamID )).Msgf ("%s stream_data_blocked frame" , direction )
242+ }
217243 counter .WithLabelValues (cc .index , frameName (frame )).Inc ()
218244 }
219245 bandwidth .WithLabelValues (cc .index ).Add (byteCountToPromCount (size ))
@@ -227,3 +253,17 @@ func frameName(frame logging.Frame) string {
227253 return strings .TrimSuffix (name , "Frame" )
228254 }
229255}
256+
257+ type direction uint8
258+
259+ const (
260+ sent direction = iota
261+ received
262+ )
263+
264+ func (d direction ) String () string {
265+ if d == sent {
266+ return "sent"
267+ }
268+ return "received"
269+ }
0 commit comments