diff --git a/internal/xds/translator/listener.go b/internal/xds/translator/listener.go index f02784e29d..943e46cc5e 100644 --- a/internal/xds/translator/listener.go +++ b/internal/xds/translator/listener.go @@ -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, @@ -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), @@ -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 @@ -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 diff --git a/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.listeners.yaml b/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.listeners.yaml index b1b39aa28e..51f8b8f0e9 100644 --- a/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.listeners.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.listeners.yaml @@ -25,9 +25,9 @@ configSource: ads: {} resourceApiVersion: V3 - routeConfigName: envoy-gateway/gateway-1/http1 + routeConfigName: http-80 serverHeaderTransformation: PASS_THROUGH - statPrefix: http-10080 + statPrefix: http-80 useRemoteAddress: true name: http-80 maxConnectionsToAcceptPerSocketEvent: 1 @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.routes.yaml index 01d3a93d1b..5c5dbe25f6 100644 --- a/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.routes.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/xds-name-scheme-v2.routes.yaml @@ -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: / @@ -14,7 +14,7 @@ - upgradeType: websocket - domains: - bar.net - name: envoy-gateway/gateway-1/http2/bar_net + name: bar_net routes: - match: prefix: / @@ -28,7 +28,7 @@ virtualHosts: - domains: - foo.com - name: envoy-gateway/gateway-1/https1/foo_com + name: foo_com routes: - match: prefix: / @@ -42,7 +42,7 @@ virtualHosts: - domains: - bar.com - name: envoy-gateway/gateway-1/https2/bar_com + name: bar_com routes: - match: prefix: / @@ -56,7 +56,7 @@ virtualHosts: - domains: - '*' - name: envoy-gateway/gateway-2/https-http3/* + name: '*' routes: - match: prefix: / diff --git a/internal/xds/translator/translator.go b/internal/xds/translator/translator.go index d04b7d965c..f79bbd6618 100644 --- a/internal/xds/translator/translator.go +++ b/internal/xds/translator/translator.go @@ -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 @@ -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), } @@ -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) } diff --git a/test/e2e/tests/connection_limit.go b/test/e2e/tests/connection_limit.go index 15e316fec4..c60dfaf2ce 100644 --- a/test/e2e/tests/connection_limit.go +++ b/test/e2e/tests/connection_limit.go @@ -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)