quic: only register Prometheus counters when metrics are enabled
This commit is contained in:
parent
82315917f7
commit
e37ca354f1
|
@ -54,7 +54,7 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (*
|
|||
tracers = append(tracers, qlogTracer)
|
||||
}
|
||||
if cm.enableMetrics {
|
||||
tracers = append(tracers, &metricsTracer{})
|
||||
tracers = append(tracers, newMetricsTracer())
|
||||
}
|
||||
if len(tracers) > 0 {
|
||||
quicConf.Tracer = quiclogging.NewMultiplexedTracer(tracers...)
|
||||
|
|
|
@ -85,7 +85,9 @@ func (c *aggregatingCollector) RemoveConn(id string) {
|
|||
|
||||
var collector *aggregatingCollector
|
||||
|
||||
func init() {
|
||||
var initMetricsOnce sync.Once
|
||||
|
||||
func initMetrics() {
|
||||
const (
|
||||
direction = "direction"
|
||||
encLevel = "encryption_level"
|
||||
|
@ -173,6 +175,11 @@ type metricsTracer struct {
|
|||
|
||||
var _ logging.Tracer = &metricsTracer{}
|
||||
|
||||
func newMetricsTracer() *metricsTracer {
|
||||
initMetricsOnce.Do(func() { initMetrics() })
|
||||
return &metricsTracer{}
|
||||
}
|
||||
|
||||
func (m *metricsTracer) TracerForConnection(_ context.Context, p logging.Perspective, connID logging.ConnectionID) logging.ConnectionTracer {
|
||||
return &metricsConnTracer{perspective: p, connID: connID}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue