Skip to content

Commit

Permalink
quicreuse: remove QUIC metrics tracer (#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored and sukunrt committed Oct 18, 2023
1 parent ee5c82a commit fc01c74
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 416 deletions.
30 changes: 7 additions & 23 deletions p2p/transport/quicreuse/connmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type ConnManager struct {
quicListeners map[string]quicListenerEntry

srk quic.StatelessResetKey
mt *metricsTracer
}

type quicListenerEntry struct {
Expand All @@ -48,26 +47,20 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (*

quicConf := quicConfig.Clone()

if cm.enableMetrics {
cm.mt = newMetricsTracer()
}
quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) quiclogging.ConnectionTracer {
tracers := make([]quiclogging.ConnectionTracer, 0, 2)
var tracer quiclogging.ConnectionTracer
if qlogTracerDir != "" {
tracers = append(tracers, qloggerForDir(qlogTracerDir, p, ci))
}
if cm.mt != nil {
tracers = append(tracers, cm.mt.TracerForConnection(ctx, p, ci))
tracer = qloggerForDir(qlogTracerDir, p, ci)
}
return quiclogging.NewMultiplexedConnectionTracer(tracers...)
return tracer
}
serverConfig := quicConf.Clone()

cm.clientConfig = quicConf
cm.serverConfig = serverConfig
if cm.enableReuseport {
cm.reuseUDP4 = newReuse(&statelessResetKey, cm.mt)
cm.reuseUDP6 = newReuse(&statelessResetKey, cm.mt)
cm.reuseUDP4 = newReuse(&statelessResetKey)
cm.reuseUDP6 = newReuse(&statelessResetKey)
}
return cm, nil
}
Expand Down Expand Up @@ -149,11 +142,7 @@ func (c *ConnManager) transportForListen(network string, laddr *net.UDPAddr) (re
if err != nil {
return nil, err
}
tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}
if c.mt != nil {
tr.Transport.Tracer = c.mt
}
return tr, nil
return &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil
}

func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (quic.Connection, error) {
Expand Down Expand Up @@ -208,12 +197,7 @@ func (c *ConnManager) TransportForDial(network string, raddr *net.UDPAddr) (refC
if err != nil {
return nil, err
}
tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}
if c.mt != nil {
tr.Transport.Tracer = c.mt
}

return tr, nil
return &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil
}

func (c *ConnManager) Protocols() []int {
Expand Down
20 changes: 7 additions & 13 deletions p2p/transport/quicreuse/reuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,16 @@ type reuse struct {
globalDialers map[int]*refcountedTransport

statelessResetKey *quic.StatelessResetKey
metricsTracer *metricsTracer
}

func newReuse(srk *quic.StatelessResetKey, mt *metricsTracer) *reuse {
func newReuse(srk *quic.StatelessResetKey) *reuse {
r := &reuse{
unicast: make(map[string]map[int]*refcountedTransport),
globalListeners: make(map[int]*refcountedTransport),
globalDialers: make(map[int]*refcountedTransport),
closeChan: make(chan struct{}),
gcStopChan: make(chan struct{}),
statelessResetKey: srk,
metricsTracer: mt,
}
go r.gc()
return r
Expand Down Expand Up @@ -271,9 +269,6 @@ func (r *reuse) transportForDialLocked(network string, source *net.IP) (*refcoun
Conn: conn,
StatelessResetKey: r.statelessResetKey,
}, packetConn: conn}
if r.metricsTracer != nil {
tr.Transport.Tracer = r.metricsTracer
}
r.globalDialers[conn.LocalAddr().(*net.UDPAddr).Port] = tr
return tr, nil
}
Expand Down Expand Up @@ -317,14 +312,13 @@ func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcoun
return nil, err
}
localAddr := conn.LocalAddr().(*net.UDPAddr)
tr := &refcountedTransport{Transport: quic.Transport{
Conn: conn,
StatelessResetKey: r.statelessResetKey,
}, packetConn: conn}
if r.metricsTracer != nil {
tr.Transport.Tracer = r.metricsTracer
tr := &refcountedTransport{
Transport: quic.Transport{
Conn: conn,
StatelessResetKey: r.statelessResetKey,
},
packetConn: conn,
}

tr.IncreaseCount()

// Deal with listen on a global address
Expand Down
16 changes: 8 additions & 8 deletions p2p/transport/quicreuse/reuse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func cleanup(t *testing.T, reuse *reuse) {
}

func TestReuseListenOnAllIPv4(t *testing.T) {
reuse := newReuse(nil, nil)
reuse := newReuse(nil)
require.Eventually(t, isGarbageCollectorRunning, 500*time.Millisecond, 50*time.Millisecond, "expected garbage collector to be running")
cleanup(t, reuse)

Expand All @@ -73,7 +73,7 @@ func TestReuseListenOnAllIPv4(t *testing.T) {
}

func TestReuseListenOnAllIPv6(t *testing.T) {
reuse := newReuse(nil, nil)
reuse := newReuse(nil)
require.Eventually(t, isGarbageCollectorRunning, 500*time.Millisecond, 50*time.Millisecond, "expected garbage collector to be running")
cleanup(t, reuse)

Expand All @@ -86,7 +86,7 @@ func TestReuseListenOnAllIPv6(t *testing.T) {
}

func TestReuseCreateNewGlobalConnOnDial(t *testing.T) {
reuse := newReuse(nil, nil)
reuse := newReuse(nil)
cleanup(t, reuse)

addr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234")
Expand All @@ -100,7 +100,7 @@ func TestReuseCreateNewGlobalConnOnDial(t *testing.T) {
}

func TestReuseConnectionWhenDialing(t *testing.T) {
reuse := newReuse(nil, nil)
reuse := newReuse(nil)
cleanup(t, reuse)

addr, err := net.ResolveUDPAddr("udp4", "0.0.0.0:0")
Expand All @@ -117,7 +117,7 @@ func TestReuseConnectionWhenDialing(t *testing.T) {
}

func TestReuseConnectionWhenListening(t *testing.T) {
reuse := newReuse(nil, nil)
reuse := newReuse(nil)
cleanup(t, reuse)

raddr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234")
Expand All @@ -132,7 +132,7 @@ func TestReuseConnectionWhenListening(t *testing.T) {
}

func TestReuseConnectionWhenDialBeforeListen(t *testing.T) {
reuse := newReuse(nil, nil)
reuse := newReuse(nil)
cleanup(t, reuse)

// dial any address
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestReuseListenOnSpecificInterface(t *testing.T) {
if platformHasRoutingTables() {
t.Skip("this test only works on platforms that support routing tables")
}
reuse := newReuse(nil, nil)
reuse := newReuse(nil)
cleanup(t, reuse)

router, err := netroute.New()
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestReuseGarbageCollect(t *testing.T) {
maxUnusedDuration = 10 * maxUnusedDuration
}

reuse := newReuse(nil, nil)
reuse := newReuse(nil)
cleanup(t, reuse)

numGlobals := func() int {
Expand Down
Loading

0 comments on commit fc01c74

Please sign in to comment.