Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,13 @@ func (t *Translator) addHCMToXDSListener(
}

// HTTP filter configuration
var statPrefix string
if irListener.TLS != nil {
statPrefix = "https"
} else {
statPrefix = "http"
}

// Append port to the statPrefix.
statPrefix = strings.Join([]string{statPrefix, strconv.Itoa(int(irListener.Port))}, "-")

// Client IP detection
useRemoteAddress := true
originalIPDetectionExtensions := originalIPDetectionExtensions(irListener.ClientIPDetection)
if originalIPDetectionExtensions != nil {
useRemoteAddress = false
}

statPrefix := hcmStatPrefix(irListener, t.xdsNameSchemeV2())
mgr := &hcmv3.HttpConnectionManager{
AccessLog: al,
CodecType: hcmv3.HttpConnectionManager_AUTO,
Expand All @@ -360,7 +350,7 @@ func (t *Translator) addHCMToXDSListener(
Rds: &hcmv3.Rds{
ConfigSource: makeConfigSource(),
// Configure route name to be found via RDS.
RouteConfigName: routeConfigName(irListener),
RouteConfigName: routeConfigName(irListener, t.xdsNameSchemeV2()),
},
},
HttpProtocolOptions: http1ProtocolOptions(irListener.HTTP1),
Expand Down Expand Up @@ -500,9 +490,24 @@ func (t *Translator) addHCMToXDSListener(
return nil
}

func routeConfigName(irListener *ir.HTTPListener) string {
// TODO(zhaohuabing): change the routeConfig name for HTTP listeners because they are merged into one route config
return irListener.Name
func hcmStatPrefix(irListener *ir.HTTPListener, nameSchemeV2 bool) string {
statPrefix := "http"
if irListener.TLS != nil {
statPrefix = "https"
}

if nameSchemeV2 {
return fmt.Sprintf("%s-%d", statPrefix, irListener.ExternalPort)
}
return fmt.Sprintf("%s-%d", statPrefix, irListener.Port)
}

// use the same name for the route config as the filter chain name, as they're 1:1 mapping.
func routeConfigName(irListener *ir.HTTPListener, nameSchemeV2 bool) string {
if irListener.TLS != nil {
return httpsListenerFilterChainName(irListener)
}
return httpListenerDefaultFilterChainName(irListener, nameSchemeV2)
}

// port value is used for the default filter chain name for HTTP listeners, as multiple HTTP listeners are merged into
Expand All @@ -515,7 +520,7 @@ func httpListenerDefaultFilterChainName(irListener *ir.HTTPListener, nameSchemeV
return irListener.Name
}

// irListener name is used as the filter chain name for HTTPS listener, as Listener is 1:1 mapping to the filter chain
// irListener name is used as the filter chain name for HTTPS listener, as HTTPS Listener is 1:1 mapping to the filter chain.
// The Gateway API layer ensures that each listener has a unique combination of hostname and port.
func httpsListenerFilterChainName(irListener *ir.HTTPListener) string {
return irListener.Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
configSource:
ads: {}
resourceApiVersion: V3
routeConfigName: envoy-gateway/gateway-1/http1
routeConfigName: http-80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause any issues for merged gateways?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a common route config for all http only listeners (with and without merged gateway enabled) on the same port (80 in this case), its linked to the default filter chain in the listener which is the fallback

serverHeaderTransformation: PASS_THROUGH
statPrefix: http-10080
statPrefix: http-80
useRemoteAddress: true
name: http-80
maxConnectionsToAcceptPerSocketEvent: 1
Expand Down Expand Up @@ -65,7 +65,7 @@
resourceApiVersion: V3
routeConfigName: envoy-gateway/gateway-1/https1
serverHeaderTransformation: PASS_THROUGH
statPrefix: https-10443
statPrefix: https-443
useRemoteAddress: true
name: envoy-gateway/gateway-1/https1
transportSocket:
Expand Down Expand Up @@ -110,7 +110,7 @@
resourceApiVersion: V3
routeConfigName: envoy-gateway/gateway-1/https2
serverHeaderTransformation: PASS_THROUGH
statPrefix: https-10443
statPrefix: https-443
useRemoteAddress: true
name: envoy-gateway/gateway-1/https2
transportSocket:
Expand Down Expand Up @@ -168,7 +168,7 @@
resourceApiVersion: V3
routeConfigName: envoy-gateway/gateway-2/https-http3
serverHeaderTransformation: PASS_THROUGH
statPrefix: https-11443
statPrefix: https-1443
useRemoteAddress: true
name: envoy-gateway/gateway-2/https-http3
transportSocket:
Expand Down Expand Up @@ -222,7 +222,7 @@
resourceApiVersion: V3
routeConfigName: envoy-gateway/gateway-2/https-http3
serverHeaderTransformation: PASS_THROUGH
statPrefix: https-11443
statPrefix: https-1443
useRemoteAddress: true
name: envoy-gateway/gateway-2/https-http3
transportSocket:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- ignorePortInHostMatching: true
name: envoy-gateway/gateway-1/http1
name: http-80
virtualHosts:
- domains:
- foo.net
name: envoy-gateway/gateway-1/http1/foo_net
name: foo_net
routes:
- match:
prefix: /
Expand All @@ -14,7 +14,7 @@
- upgradeType: websocket
- domains:
- bar.net
name: envoy-gateway/gateway-1/http2/bar_net
name: bar_net
routes:
- match:
prefix: /
Expand All @@ -28,7 +28,7 @@
virtualHosts:
- domains:
- foo.com
name: envoy-gateway/gateway-1/https1/foo_com
name: foo_com
routes:
- match:
prefix: /
Expand All @@ -42,7 +42,7 @@
virtualHosts:
- domains:
- bar.com
name: envoy-gateway/gateway-1/https2/bar_com
name: bar_com
routes:
- match:
prefix: /
Expand All @@ -56,7 +56,7 @@
virtualHosts:
- domains:
- '*'
name: envoy-gateway/gateway-2/https-http3/*
name: '*'
routes:
- match:
prefix: /
Expand Down
9 changes: 6 additions & 3 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (t *Translator) processHTTPListenerXdsTranslation(
routeCfgName = findXdsHTTPRouteConfigName(tcpXDSListener)
// If the route config name is not found, we use the current ir Listener name as the route config name to create a new route config.
if routeCfgName == "" {
routeCfgName = routeConfigName(httpListener)
routeCfgName = routeConfigName(httpListener, t.xdsNameSchemeV2())
}

// Create a route config if we have not found one yet
Expand Down Expand Up @@ -504,7 +504,7 @@ func (t *Translator) addRouteToRouteConfig(
underscoredHostname := strings.ReplaceAll(httpRoute.Hostname, ".", "_")
// Allocate virtual host for this httpRoute.
vHost = &routev3.VirtualHost{
Name: virtualHostName(httpListener, underscoredHostname),
Name: virtualHostName(httpListener, underscoredHostname, t.xdsNameSchemeV2()),
Domains: []string{httpRoute.Hostname},
Metadata: buildXdsMetadata(httpListener.Metadata),
}
Expand Down Expand Up @@ -656,7 +656,10 @@ func (t *Translator) addRouteToRouteConfig(
return errs
}

func virtualHostName(httpListener *ir.HTTPListener, underscoredHostname string) string {
func virtualHostName(httpListener *ir.HTTPListener, underscoredHostname string, xdsNameSchemeV2 bool) string {
if xdsNameSchemeV2 {
return underscoredHostname
}
return fmt.Sprintf("%s/%s", httpListener.Name, underscoredHostname)
}

Expand Down
3 changes: 3 additions & 0 deletions test/e2e/tests/connection_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ var ConnectionLimitTest = suite.ConformanceTest{
}

prefix := "http-10080"
if XDSNameSchemeV2() {
prefix = "http-80"
}
gtwName := "connection-limit-gateway"
promQL := fmt.Sprintf(`envoy_connection_limit_limited_connections{envoy_connection_limit_prefix="%s",gateway_envoyproxy_io_owning_gateway_name="%s"}`, prefix, gtwName)

Expand Down