Skip to content

Commit

Permalink
metrics: create a new tracer on every call of DefaultConnectionTracer (
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Jun 7, 2024
1 parent 4d0562d commit 8cae5d8
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions metrics/connection_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net"
"sync"
"time"

"github.com/quic-go/quic-go"
Expand Down Expand Up @@ -52,25 +51,14 @@ var (
)
)

var (
defaultServerConnectionTracerOnce, defaultClientConnectionTracerOnce sync.Once
defaultServerConnectionTracer, defaultClientConnectionTracer *logging.ConnectionTracer
)

// DefaultConnectionTracer returns a callback that creates a metrics ConnectionTracer.
// The ConnectionTracer returned can be set on the quic.Config for a new connection.
func DefaultConnectionTracer(_ context.Context, p logging.Perspective, _ logging.ConnectionID) *logging.ConnectionTracer {
switch p {
case logging.PerspectiveClient:
defaultClientConnectionTracerOnce.Do(func() {
defaultClientConnectionTracer = NewClientConnectionTracerWithRegisterer(prometheus.DefaultRegisterer)
})
return defaultClientConnectionTracer
return NewClientConnectionTracerWithRegisterer(prometheus.DefaultRegisterer)
case logging.PerspectiveServer:
defaultServerConnectionTracerOnce.Do(func() {
defaultServerConnectionTracer = NewServerConnectionTracerWithRegisterer(prometheus.DefaultRegisterer)
})
return defaultServerConnectionTracer
return NewServerConnectionTracerWithRegisterer(prometheus.DefaultRegisterer)
default:
panic("invalid perspective")
}
Expand Down

0 comments on commit 8cae5d8

Please sign in to comment.