Skip to content

Add api gateway peering unit test cases.#23366

Merged
LordAbhishek merged 3 commits intoabhishek/api-gateway-peeringfrom
add_api_gw_peering_unit_test
Apr 13, 2026
Merged

Add api gateway peering unit test cases.#23366
LordAbhishek merged 3 commits intoabhishek/api-gateway-peeringfrom
add_api_gw_peering_unit_test

Conversation

@LordAbhishek
Copy link
Copy Markdown
Contributor

@LordAbhishek LordAbhishek commented Mar 24, 2026

Our existing Unit Test cases do not cover the scenario where the API Gateway routes requests to a service in a peered datacenter (DC).
Adding getAPIGatewayPeeringGoldenTestCases, which generates a set of golden test cases to verify that the API Gateway correctly produces xDS resources for peered Upstream (along with different mesh gateway mode combinations).

Test details:
Here, we create an API Gateway and configure its upstream service (paymentService) to exist in a peer cluster.
The test defines 4 cases using:
newTestCase := func(name string, mgwMode structs.MeshGatewayMode, upstreamAddr string, upstreamAddrIsHostname bool) goldenTestCase

Each case sets a different combination of mesh gateway mode (local/remote), upstream address type (IP/DNS), and a boolean to check if upstreamAddrIsHostname.
Local mesh gateway, Discovery chain, service resolver and peering trust bundle is required to configure upstreamService (paymentService) to tell API Gateway that upstream service is in peered DC, so that routes can be configured accordingly.

When the test runs, it creates the snapshot and then generate the API Gateway xDS configs from it and store them in golden files. We can verify with golden files that if API Gateway envoy configuration correctly routes to the upstream service that exists in a peer cluster for all combinations or not.

Test case combinations:

  1. newTestCase("api-gateway-with-peers-mesh-mode-local-and-upstream-is-hostname", structs.MeshGatewayModeLocal, "123.us-east-1.elb.notaws.com", true),
  2. newTestCase("api-gateway-with-peers-mesh-mode-local-and-upstream-is-static", structs.MeshGatewayModeLocal, "172.68.1.1", false),
  3. newTestCase("api-gateway-with-peers-mesh-mode-remote-and-upstream-is-hostname", structs.MeshGatewayModeRemote, "123.us-east-1.elb.notaws.com", true),
  4. newTestCase("api-gateway-with-peers-mesh-mode-remote-and-upstream-is-static", structs.MeshGatewayModeRemote, "172.68.1.1", false),

Test result:
We can verify the generated configs from the golden files.

Issues while verifying golden file (cluster and endpoints config):

  1. In test 1, in order to api-gateway route to upstream, it should have upstream endpoint. We will not find upstream endpoint in the config. Endpoints config is expected to have endpoints, but its null. Fix1 & Fix2
  2. In test 2, the test configured api-gateway mesh gw mode as local, so it should route to (upstream endpoint should be) local mesh gateway (10.45.1.1) instead of "172.68.1.1 -WAN address of remote paymentService". Fix1 & Fix2
  3. In test 3, in order to api-gateway route to upstream, it should have upstream endpoint. We will not find upstream endpoint in the config. Cluster config is expected to have endpoints, but it's missing. Fix3

@github-actions github-actions Bot added the theme/envoy/xds Related to Envoy support label Mar 24, 2026
@LordAbhishek LordAbhishek marked this pull request as ready for review March 26, 2026 05:30
@LordAbhishek LordAbhishek requested review from a team as code owners March 26, 2026 05:30
Copy link
Copy Markdown
Contributor

@anandmukul93 anandmukul93 left a comment

Choose a reason for hiding this comment

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

LGTM

#23369)

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway

- Fixed handleRouteConfigUpdate to properly propagate meshGatewayConfig to API gateway upstreams, which is required during XDS endpoint and cluster config generation.
- Added TestStateChangedAPIGateway test cases in state_test.go to validate API gateway update handling.
- Added API gateway-specific logging prefix (similar to mesh gateway) to help in debugging.

* fix(xds): correct endpoint config generation for API gateway in peered setups (#23370)

* fix(xds): correct endpoint config generation for API gateway in peered setups

- Previously, API gateway XDS endpoint generation incorrectly relied on cfgSnap.ConnectProxy config (instead of cgfSnap.APIGateway), which caused wrong/no endpoint configuration for peered environments.
- Changes made:
- Updated makeUpstreamLoadAssignmentForPeerService to fetch localGatewayEndpoint based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Updated endpointsFromDiscoveryChain to derive meshGatewayMode based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Recompiled golden test file to reflect fix.

* removed comment

* fix(xds): correct cluster config generation for API gateway in peered setups (#23371)

* fix(xds): correct cluster config generation for API gateway in peered setups

- Updated makeUpstreamClustersForDiscoveryChain to generate cluster config based on upstream endpoint type. Before this fix, it always generated cluster configs without endpoints, which is incorrect when the upstream endpoint type is hostname and mesh-gateway mode is remote; in such cases, endpoints must also be included in the cluster config.

- Added recompiled golden test file to reflect the fix.

* fix lint error
@LordAbhishek LordAbhishek merged commit e61bd4b into abhishek/api-gateway-peering Apr 13, 2026
11 checks passed
LordAbhishek added a commit that referenced this pull request Apr 13, 2026
* add unit test cases for api gateway supporting consul peering

* add compiled xds config golden files after running api-gw golden testcases

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway (#23369)

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway

- Fixed handleRouteConfigUpdate to properly propagate meshGatewayConfig to API gateway upstreams, which is required during XDS endpoint and cluster config generation.
- Added TestStateChangedAPIGateway test cases in state_test.go to validate API gateway update handling.
- Added API gateway-specific logging prefix (similar to mesh gateway) to help in debugging.

* fix(xds): correct endpoint config generation for API gateway in peered setups (#23370)

* fix(xds): correct endpoint config generation for API gateway in peered setups

- Previously, API gateway XDS endpoint generation incorrectly relied on cfgSnap.ConnectProxy config (instead of cgfSnap.APIGateway), which caused wrong/no endpoint configuration for peered environments.
- Changes made:
- Updated makeUpstreamLoadAssignmentForPeerService to fetch localGatewayEndpoint based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Updated endpointsFromDiscoveryChain to derive meshGatewayMode based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Recompiled golden test file to reflect fix.

* removed comment

* fix(xds): correct cluster config generation for API gateway in peered setups (#23371)

* fix(xds): correct cluster config generation for API gateway in peered setups

- Updated makeUpstreamClustersForDiscoveryChain to generate cluster config based on upstream endpoint type. Before this fix, it always generated cluster configs without endpoints, which is incorrect when the upstream endpoint type is hostname and mesh-gateway mode is remote; in such cases, endpoints must also be included in the cluster config.

- Added recompiled golden test file to reflect the fix.

* fix lint error
LordAbhishek added a commit that referenced this pull request Apr 13, 2026
* add unit test cases for api gateway supporting consul peering

* add compiled xds config golden files after running api-gw golden testcases

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway (#23369)

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway

- Fixed handleRouteConfigUpdate to properly propagate meshGatewayConfig to API gateway upstreams, which is required during XDS endpoint and cluster config generation.
- Added TestStateChangedAPIGateway test cases in state_test.go to validate API gateway update handling.
- Added API gateway-specific logging prefix (similar to mesh gateway) to help in debugging.

* fix(xds): correct endpoint config generation for API gateway in peered setups (#23370)

* fix(xds): correct endpoint config generation for API gateway in peered setups

- Previously, API gateway XDS endpoint generation incorrectly relied on cfgSnap.ConnectProxy config (instead of cgfSnap.APIGateway), which caused wrong/no endpoint configuration for peered environments.
- Changes made:
- Updated makeUpstreamLoadAssignmentForPeerService to fetch localGatewayEndpoint based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Updated endpointsFromDiscoveryChain to derive meshGatewayMode based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Recompiled golden test file to reflect fix.

* removed comment

* fix(xds): correct cluster config generation for API gateway in peered setups (#23371)

* fix(xds): correct cluster config generation for API gateway in peered setups

- Updated makeUpstreamClustersForDiscoveryChain to generate cluster config based on upstream endpoint type. Before this fix, it always generated cluster configs without endpoints, which is incorrect when the upstream endpoint type is hostname and mesh-gateway mode is remote; in such cases, endpoints must also be included in the cluster config.

- Added recompiled golden test file to reflect the fix.

* fix lint error
LordAbhishek added a commit that referenced this pull request Apr 22, 2026
* add unit test cases for api gateway supporting consul peering

* add compiled xds config golden files after running api-gw golden testcases

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway (#23369)

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway

- Fixed handleRouteConfigUpdate to properly propagate meshGatewayConfig to API gateway upstreams, which is required during XDS endpoint and cluster config generation.
- Added TestStateChangedAPIGateway test cases in state_test.go to validate API gateway update handling.
- Added API gateway-specific logging prefix (similar to mesh gateway) to help in debugging.

* fix(xds): correct endpoint config generation for API gateway in peered setups (#23370)

* fix(xds): correct endpoint config generation for API gateway in peered setups

- Previously, API gateway XDS endpoint generation incorrectly relied on cfgSnap.ConnectProxy config (instead of cgfSnap.APIGateway), which caused wrong/no endpoint configuration for peered environments.
- Changes made:
- Updated makeUpstreamLoadAssignmentForPeerService to fetch localGatewayEndpoint based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Updated endpointsFromDiscoveryChain to derive meshGatewayMode based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Recompiled golden test file to reflect fix.

* removed comment

* fix(xds): correct cluster config generation for API gateway in peered setups (#23371)

* fix(xds): correct cluster config generation for API gateway in peered setups

- Updated makeUpstreamClustersForDiscoveryChain to generate cluster config based on upstream endpoint type. Before this fix, it always generated cluster configs without endpoints, which is incorrect when the upstream endpoint type is hostname and mesh-gateway mode is remote; in such cases, endpoints must also be included in the cluster config.

- Added recompiled golden test file to reflect the fix.

* fix lint error
LordAbhishek added a commit that referenced this pull request Apr 22, 2026
* add unit test cases for api gateway supporting consul peering

* add compiled xds config golden files after running api-gw golden testcases

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway (#23369)

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway

- Fixed handleRouteConfigUpdate to properly propagate meshGatewayConfig to API gateway upstreams, which is required during XDS endpoint and cluster config generation.
- Added TestStateChangedAPIGateway test cases in state_test.go to validate API gateway update handling.
- Added API gateway-specific logging prefix (similar to mesh gateway) to help in debugging.

* fix(xds): correct endpoint config generation for API gateway in peered setups (#23370)

* fix(xds): correct endpoint config generation for API gateway in peered setups

- Previously, API gateway XDS endpoint generation incorrectly relied on cfgSnap.ConnectProxy config (instead of cgfSnap.APIGateway), which caused wrong/no endpoint configuration for peered environments.
- Changes made:
- Updated makeUpstreamLoadAssignmentForPeerService to fetch localGatewayEndpoint based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Updated endpointsFromDiscoveryChain to derive meshGatewayMode based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Recompiled golden test file to reflect fix.

* removed comment

* fix(xds): correct cluster config generation for API gateway in peered setups (#23371)

* fix(xds): correct cluster config generation for API gateway in peered setups

- Updated makeUpstreamClustersForDiscoveryChain to generate cluster config based on upstream endpoint type. Before this fix, it always generated cluster configs without endpoints, which is incorrect when the upstream endpoint type is hostname and mesh-gateway mode is remote; in such cases, endpoints must also be included in the cluster config.

- Added recompiled golden test file to reflect the fix.

* fix lint error
LordAbhishek added a commit that referenced this pull request Apr 22, 2026
* add unit test cases for api gateway supporting consul peering

* add compiled xds config golden files after running api-gw golden testcases

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway (#23369)

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway

- Fixed handleRouteConfigUpdate to properly propagate meshGatewayConfig to API gateway upstreams, which is required during XDS endpoint and cluster config generation.
- Added TestStateChangedAPIGateway test cases in state_test.go to validate API gateway update handling.
- Added API gateway-specific logging prefix (similar to mesh gateway) to help in debugging.

* fix(xds): correct endpoint config generation for API gateway in peered setups (#23370)

* fix(xds): correct endpoint config generation for API gateway in peered setups

- Previously, API gateway XDS endpoint generation incorrectly relied on cfgSnap.ConnectProxy config (instead of cgfSnap.APIGateway), which caused wrong/no endpoint configuration for peered environments.
- Changes made:
- Updated makeUpstreamLoadAssignmentForPeerService to fetch localGatewayEndpoint based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Updated endpointsFromDiscoveryChain to derive meshGatewayMode based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Recompiled golden test file to reflect fix.

* removed comment

* fix(xds): correct cluster config generation for API gateway in peered setups (#23371)

* fix(xds): correct cluster config generation for API gateway in peered setups

- Updated makeUpstreamClustersForDiscoveryChain to generate cluster config based on upstream endpoint type. Before this fix, it always generated cluster configs without endpoints, which is incorrect when the upstream endpoint type is hostname and mesh-gateway mode is remote; in such cases, endpoints must also be included in the cluster config.

- Added recompiled golden test file to reflect the fix.

* fix lint error
LordAbhishek added a commit that referenced this pull request Apr 22, 2026
…r API Gateways when peered and updated the API Gateway updateHandler to propagate mesh gateway config to its upstreams. (#23454)

* Add api gateway peering unit test cases. (#23366)

* add unit test cases for api gateway supporting consul peering

* add compiled xds config golden files after running api-gw golden testcases

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway (#23369)

* fix(proxyCfg): propogate meshGatewayConfig to upstreams of API gateway

- Fixed handleRouteConfigUpdate to properly propagate meshGatewayConfig to API gateway upstreams, which is required during XDS endpoint and cluster config generation.
- Added TestStateChangedAPIGateway test cases in state_test.go to validate API gateway update handling.
- Added API gateway-specific logging prefix (similar to mesh gateway) to help in debugging.

* fix(xds): correct endpoint config generation for API gateway in peered setups (#23370)

* fix(xds): correct endpoint config generation for API gateway in peered setups

- Previously, API gateway XDS endpoint generation incorrectly relied on cfgSnap.ConnectProxy config (instead of cgfSnap.APIGateway), which caused wrong/no endpoint configuration for peered environments.
- Changes made:
- Updated makeUpstreamLoadAssignmentForPeerService to fetch localGatewayEndpoint based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Updated endpointsFromDiscoveryChain to derive meshGatewayMode based on cfgSnap kind instead of always using cfgSnap.ConnectProxy.
- Recompiled golden test file to reflect fix.

* removed comment

* fix(xds): correct cluster config generation for API gateway in peered setups (#23371)

* fix(xds): correct cluster config generation for API gateway in peered setups

- Updated makeUpstreamClustersForDiscoveryChain to generate cluster config based on upstream endpoint type. Before this fix, it always generated cluster configs without endpoints, which is incorrect when the upstream endpoint type is hostname and mesh-gateway mode is remote; in such cases, endpoints must also be included in the cluster config.

- Added recompiled golden test file to reflect the fix.

* fix lint error

* add changelog

* refresh golden file to remove regexRewrite from route configs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme/envoy/xds Related to Envoy support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants