fix(metrics): skip connection wrapping when metrics are disabled
When xmetrics.IsEnabled() is false (no -api / no metrics.addr configured), WrapListener now returns the listener unchanged instead of wrapping every accepted connection in a metrics.serverConn. This allows bare *net.TCPConn to reach the forwarding layer, enabling future splice(2) optimization.
This commit is contained in:
@@ -2,6 +2,8 @@ package wrapper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
xmetrics "github.com/go-gost/x/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
type listener struct {
|
type listener struct {
|
||||||
@@ -10,10 +12,11 @@ type listener struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WrapListener wraps a net.Listener so that all accepted connections are
|
// WrapListener wraps a net.Listener so that all accepted connections are
|
||||||
// automatically wrapped with WrapConn for metrics tracking. If ln is nil,
|
// automatically wrapped with WrapConn for metrics tracking. If metrics are
|
||||||
// nil is returned.
|
// not enabled, ln is returned unchanged to allow splice(2) optimization
|
||||||
|
// on bare *net.TCPConn. If ln is nil, nil is returned.
|
||||||
func WrapListener(service string, ln net.Listener) net.Listener {
|
func WrapListener(service string, ln net.Listener) net.Listener {
|
||||||
if ln == nil {
|
if ln == nil || !xmetrics.IsEnabled() {
|
||||||
return ln
|
return ln
|
||||||
}
|
}
|
||||||
return &listener{
|
return &listener{
|
||||||
|
|||||||
Reference in New Issue
Block a user