From 27a2b97f3376b32fc63b1f31a5b7fe6af3046b6c Mon Sep 17 00:00:00 2001 From: doujiang24 Date: Sun, 5 Oct 2025 13:01:47 +0800 Subject: [PATCH 1/3] doc: update doc for SetUpstreamOverrideHost in Envoy Golang. Signed-off-by: doujiang24 --- contrib/golang/common/go/api/filter.go | 27 +++++++----------- .../http/test/golang_integration_test.cc | 28 +++++++++---------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/contrib/golang/common/go/api/filter.go b/contrib/golang/common/go/api/filter.go index 02627a186f839..24c0708ecaaf8 100644 --- a/contrib/golang/common/go/api/filter.go +++ b/contrib/golang/common/go/api/filter.go @@ -210,29 +210,22 @@ type FilterProcessCallbacks interface { type DecoderFilterCallbacks interface { FilterProcessCallbacks - // Sets an upstream address override for the request. When the overridden host exists in the host list of the routed cluster - // and can be selected directly, the load balancer bypasses its algorithm and routes traffic directly to the specified host. - // - // Here are some cases: - // 1. Set a valid host(no matter in or not in the cluster), will route to the specified host directly and return 200. - // 2. Set a non-IP host, C++ side will return error and not route to cluster. - // 3. Set a unavaiable host, and the host is not in the cluster, will req the valid host in the cluster and rerurn 200. - // 4. Set a unavaiable host, and the host is in the cluster, but not available(can not connect to the host), will req the unavaiable hoat and rerurn 503. - // 5. Set a unavaiable host, and the host is in the cluster, but not available(can not connect to the host), and with retry. when first request with unavaiable host failed 503, the second request will retry with the valid host, then the second request will succeed and finally return 200. - // 6. Set a unavaiable host with strict mode, and the host is in the cluster, will req the unavaiable host and rerurn 503. - // 7. Set a unavaiable host with strict mode, and the host is not in the cluster, will req the unavaiable host and rerurn 503. - // 8. Set a unavaiable host with strict mode and retry. when first request with unavaiable host failed 503, the second request will retry with the valid host, then the second request will succeed and finally return 200. - // 9. Set a unavaiable host with strict mode and retry, and the host is not in the cluster, will req the unavaiable host and rerurn 503. + + // SetUpstreamOverrideHost sets an upstream address override for the request. + // When the overridden host is available and can be selected directly, the load balancer bypasses its algorithm + // and routes traffic directly to the specified host. The strict flag determines whether the HTTP request must + // strictly use the overridden destination. If the destination is unavailable and strict is set to true, Envoy + // responds with a 503 Service Unavailable error. // // The function takes two arguments: // - // host (string): The upstream host address to use for the request. This must be a valid IP address(with port); otherwise, the - // C++ side will throw an error. + // host (string): The upstream host address to use for the request. This must be a valid IP address(with port); + // otherwise, it will return an error. // // strict (boolean): Determines whether the HTTP request must be strictly routed to the requested - // host. When set to ``true``, if the requested host is invalid, Envoy will return a 503 status code. + // host. When set to ``true``, if the requested host is unavailable, Envoy will return a 503 status code. // The default value is ``false``, which allows Envoy to fall back to its load balancing mechanism. In this case, if the - // requested host is invalid, the request will be routed according to the load balancing algorithm and choose other hosts. + // requested host is not found, the request will be routed according to the load balancing algorithm. SetUpstreamOverrideHost(host string, strict bool) error } diff --git a/contrib/golang/filters/http/test/golang_integration_test.cc b/contrib/golang/filters/http/test/golang_integration_test.cc index aea3b97c3b941..2553f8be18653 100644 --- a/contrib/golang/filters/http/test/golang_integration_test.cc +++ b/contrib/golang/filters/http/test/golang_integration_test.cc @@ -1847,8 +1847,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_BadHost) { testUpstreamOverrideHost("403", "", "/test?upstreamOverrideHost=badhost", true); } -// Set a unavaiable host, and the host is not in the cluster, will req the valid host in the cluster -// and rerurn 200. +// Set a unavailable host, and the host is not in the cluster, will req the valid host in the cluster +// and return 200. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_NotFound) { const std::string expected_host = GetParam() == Network::Address::IpVersion::v4 ? "127.0.0.1" : "[::1]"; @@ -1857,8 +1857,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_NotFound) { testUpstreamOverrideHost("200", expected_host, "/test?upstreamOverrideHost=" + url_host, false); } -// Set a unavaiable host, and the host is in the cluster, but not available(can not connect to the -// host), will req the unavaiable hoat and rerurn 503. +// Set a unavailable host, and the host is in the cluster, but not available(can not connect to the +// host), will req the unavailable hoat and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable) { const std::string expected_host = GetParam() == Network::Address::IpVersion::v4 ? "127.0.0.1" : "[::1]"; @@ -1870,8 +1870,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable) { add_endpoint); } -// Set a unavaiable host, and the host is in the cluster, but not available(can not connect to the -// host), and with retry. when first request with unavaiable host failed 503, the second request +// Set a unavailable host, and the host is in the cluster, but not available(can not connect to the +// host), and with retry. when first request with unavailable host failed 503, the second request // will retry with the valid host, then the second request will succeed and finally return 200. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable_Retry) { const std::string expected_host = @@ -1884,8 +1884,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable_Re add_endpoint, true); } -// Set a unavaiable host with strict mode, and the host is in the cluster, will req the unavaiable -// host and rerurn 503. +// Set a unavailable host with strict mode, and the host is in the cluster, will req the unavailable +// host and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict) { const std::string expected_host = GetParam() == Network::Address::IpVersion::v4 ? "127.0.0.1" : "[::1]"; @@ -1899,8 +1899,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict) { false, add_endpoint); } -// Set a unavaiable host with strict mode, and the host is not in the cluster, will req the -// unavaiable host and rerurn 503. +// Set a unavailable host with strict mode, and the host is not in the cluster, will req the +// unavailable host and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_NotFound) { const std::string expected_host = GetParam() == Network::Address::IpVersion::v4 ? "127.0.0.1" : "[::1]"; @@ -1912,8 +1912,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_NotFoun false); } -// Set a unavaiable host with strict mode and retry, and the host is in the cluster. -// when first request with unavaiable host failed 503, the second request will retry with the valid +// Set a unavailable host with strict mode and retry, and the host is in the cluster. +// when first request with unavailable host failed 503, the second request will retry with the valid // host, then the second request will succeed and finally return 200. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_Retry) { const std::string expected_host = @@ -1928,8 +1928,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_Retry) false, add_endpoint, true); } -// Set a unavaiable host with strict mode and retry, and the host is not in the cluster, will req -// the unavaiable host and rerurn 503. +// Set a unavailable host with strict mode and retry, and the host is not in the cluster, will req +// the unavailable host and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_NotFound_Retry) { const std::string expected_host = GetParam() == Network::Address::IpVersion::v4 ? "127.0.0.1" : "[::1]"; From c5de89175878349ff1fa6f05ed163e1f690c8f74 Mon Sep 17 00:00:00 2001 From: doujiang24 Date: Sun, 5 Oct 2025 16:17:21 +0800 Subject: [PATCH 2/3] fix format Signed-off-by: doujiang24 --- contrib/golang/filters/http/test/golang_integration_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/golang/filters/http/test/golang_integration_test.cc b/contrib/golang/filters/http/test/golang_integration_test.cc index 2553f8be18653..a3ce37721c6cf 100644 --- a/contrib/golang/filters/http/test/golang_integration_test.cc +++ b/contrib/golang/filters/http/test/golang_integration_test.cc @@ -1847,8 +1847,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_BadHost) { testUpstreamOverrideHost("403", "", "/test?upstreamOverrideHost=badhost", true); } -// Set a unavailable host, and the host is not in the cluster, will req the valid host in the cluster -// and return 200. +// Set a unavailable host, and the host is not in the cluster, will req the valid host in the +// cluster and return 200. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_NotFound) { const std::string expected_host = GetParam() == Network::Address::IpVersion::v4 ? "127.0.0.1" : "[::1]"; From 50d31d15ef7a43e2acd2603f6088500c47ddf14b Mon Sep 17 00:00:00 2001 From: doujiang24 Date: Thu, 9 Oct 2025 15:31:29 +0800 Subject: [PATCH 3/3] more fix Signed-off-by: doujiang24 --- .../filters/http/test/golang_integration_test.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/golang/filters/http/test/golang_integration_test.cc b/contrib/golang/filters/http/test/golang_integration_test.cc index a3ce37721c6cf..6c9dd90e93e57 100644 --- a/contrib/golang/filters/http/test/golang_integration_test.cc +++ b/contrib/golang/filters/http/test/golang_integration_test.cc @@ -1847,7 +1847,7 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_BadHost) { testUpstreamOverrideHost("403", "", "/test?upstreamOverrideHost=badhost", true); } -// Set a unavailable host, and the host is not in the cluster, will req the valid host in the +// Set an unavailable host, and the host is not in the cluster, will req the valid host in the // cluster and return 200. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_NotFound) { const std::string expected_host = @@ -1857,7 +1857,7 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_NotFound) { testUpstreamOverrideHost("200", expected_host, "/test?upstreamOverrideHost=" + url_host, false); } -// Set a unavailable host, and the host is in the cluster, but not available(can not connect to the +// Set an unavailable host, and the host is in the cluster, but not available(can not connect to the // host), will req the unavailable hoat and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable) { const std::string expected_host = @@ -1870,7 +1870,7 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable) { add_endpoint); } -// Set a unavailable host, and the host is in the cluster, but not available(can not connect to the +// Set an unavailable host, and the host is in the cluster, but not available(can not connect to the // host), and with retry. when first request with unavailable host failed 503, the second request // will retry with the valid host, then the second request will succeed and finally return 200. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable_Retry) { @@ -1884,8 +1884,8 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Unavaliable_Re add_endpoint, true); } -// Set a unavailable host with strict mode, and the host is in the cluster, will req the unavailable -// host and return 503. +// Set an unavailable host with strict mode, and the host is in the cluster, will req the +// unavailable host and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict) { const std::string expected_host = GetParam() == Network::Address::IpVersion::v4 ? "127.0.0.1" : "[::1]"; @@ -1899,7 +1899,7 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict) { false, add_endpoint); } -// Set a unavailable host with strict mode, and the host is not in the cluster, will req the +// Set an unavailable host with strict mode, and the host is not in the cluster, will req the // unavailable host and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_NotFound) { const std::string expected_host = @@ -1912,7 +1912,7 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_NotFoun false); } -// Set a unavailable host with strict mode and retry, and the host is in the cluster. +// Set an unavailable host with strict mode and retry, and the host is in the cluster. // when first request with unavailable host failed 503, the second request will retry with the valid // host, then the second request will succeed and finally return 200. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_Retry) { @@ -1928,7 +1928,7 @@ TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_Retry) false, add_endpoint, true); } -// Set a unavailable host with strict mode and retry, and the host is not in the cluster, will req +// Set an unavailable host with strict mode and retry, and the host is not in the cluster, will req // the unavailable host and return 503. TEST_P(GolangIntegrationTest, SetUpstreamOverrideHost_InvalidHost_Strict_NotFound_Retry) { const std::string expected_host =