core/envoy: only enable port reuse on linux (#5066)

* core/envoy: only enable port reuse on linux

* fix alert
This commit is contained in:
Caleb Doxsey 2024-04-11 16:19:20 -06:00 committed by GitHub
parent ed378af744
commit f03b1cd9ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 15 deletions

View file

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"net" "net"
"net/url" "net/url"
"runtime"
"strings" "strings"
"time" "time"
@ -676,6 +677,11 @@ func newEnvoyListener(name string) *envoy_config_listener_v3.Listener {
return &envoy_config_listener_v3.Listener{ return &envoy_config_listener_v3.Listener{
Name: name, Name: name,
PerConnectionBufferLimitBytes: wrapperspb.UInt32(listenerBufferLimit), PerConnectionBufferLimitBytes: wrapperspb.UInt32(listenerBufferLimit),
// SO_REUSEPORT only works properly on linux and is force-disabled by
// envoy on mac and windows, so we disable it explitly to avoid a
// noisy log message
EnableReusePort: wrapperspb.Bool(runtime.GOOS == "linux"),
} }
} }

View file

@ -7,6 +7,7 @@ import (
"encoding/base64" "encoding/base64"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"testing" "testing"
"text/template" "text/template"
@ -89,7 +90,10 @@ func Test_buildMetricsHTTPConnectionManagerFilter(t *testing.T) {
}, },
}) })
expect := testData(t, "metrics_http_connection_manager.json", struct{ CertFile, KeyFile string }{certFileName, keyFileName}) expect := testData(t, "metrics_http_connection_manager.json", struct {
CertFile, KeyFile string
EnableReusePort bool
}{certFileName, keyFileName, runtime.GOOS == "linux"})
require.NoError(t, err) require.NoError(t, err)
testutil.AssertProtoJSONEqual(t, expect, li) testutil.AssertProtoJSONEqual(t, expect, li)
} }

View file

@ -15,7 +15,7 @@ import (
) )
func (b *Builder) buildOutboundListener(cfg *config.Config) (*envoy_config_listener_v3.Listener, error) { func (b *Builder) buildOutboundListener(cfg *config.Config) (*envoy_config_listener_v3.Listener, error) {
outboundPort, err := strconv.Atoi(cfg.OutboundPort) outboundPort, err := strconv.ParseUint(cfg.OutboundPort, 10, 32)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid outbound port %v: %w", cfg.OutboundPort, err) return nil, fmt.Errorf("invalid outbound port %v: %w", cfg.OutboundPort, err)
} }
@ -25,23 +25,21 @@ func (b *Builder) buildOutboundListener(cfg *config.Config) (*envoy_config_liste
return nil, fmt.Errorf("error building outbound http connection manager filter: %w", err) return nil, fmt.Errorf("error building outbound http connection manager filter: %w", err)
} }
li := &envoy_config_listener_v3.Listener{ li := newEnvoyListener("outbound-ingress")
Name: "outbound-ingress", li.Address = &envoy_config_core_v3.Address{
Address: &envoy_config_core_v3.Address{ Address: &envoy_config_core_v3.Address_SocketAddress{
Address: &envoy_config_core_v3.Address_SocketAddress{ SocketAddress: &envoy_config_core_v3.SocketAddress{
SocketAddress: &envoy_config_core_v3.SocketAddress{ Address: "127.0.0.1",
Address: "127.0.0.1", PortSpecifier: &envoy_config_core_v3.SocketAddress_PortValue{
PortSpecifier: &envoy_config_core_v3.SocketAddress_PortValue{ PortValue: uint32(outboundPort),
PortValue: uint32(outboundPort),
},
}, },
}, },
}, },
FilterChains: []*envoy_config_listener_v3.FilterChain{{
Name: "outbound-ingress",
Filters: []*envoy_config_listener_v3.Filter{filter},
}},
} }
li.FilterChains = []*envoy_config_listener_v3.FilterChain{{
Name: "outbound-ingress",
Filters: []*envoy_config_listener_v3.Filter{filter},
}}
return li, nil return li, nil
} }

View file

@ -7,6 +7,7 @@
"portValue": 9902 "portValue": 9902
} }
}, },
"enableReusePort": {{.EnableReusePort}},
"filterChains": [ "filterChains": [
{ {
"filters": [ "filters": [