envoy
envoy copied to clipboard
golang: support Golang TCP Upstream Extension for http2tcp on Envoy
As mentioned in the proposal: https://github.com/envoyproxy/envoy/issues/35749 , this PR is to support using Golang to extend TCP upstream proxy, to make changes to connections and data messages in the http2tcp situation of envoy. (this PR does)
Here is my thought about Golang extension function points:
- Support encoding message processing for upstream TCP requests (route and cluster have been determined, and targeted message processing can be performed for route and cluster)
- Support the handling of conn connection status during the encoding stage of upstream TCP requests (for example, by setting end_stream=false to avoid envoy semi connected status)
- Support decoding message processing and aggregation for upstream TCP response in onUpstreamData.(for example, by setting end_stream=true to indicate that the message is encapsulated and can be passed to downstream)
- Aggregate the tcp messages received multiple times by onUpstreamData of tcp response.
- Support obtaining route and cluster information, which can be referenced for targeted processing in the above stages.
What we can do with this Golang extension:
With this golang extension, developers can quickly get started with envoy and use golang to implement http2tcp such as http2dubbo、http2rpc.
Commit Message: support Golang TCP Upstream Extension for http2tcp on Envoy Additional Description: Risk Level: Testing: Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional API Considerations:]
As a reminder, PRs marked as draft will not be automatically assigned reviewers, or be handled by maintainer-oncall triage.
Please mark your PR as ready when you want it to be reviewed!
I will add unit tests for these codes and fix errors related to unit tests.
@doujiang24 could you take a look and check if the direction looks good? thanks!
/assign @doujiang24
Per discussion in https://github.com/envoyproxy/envoy/issues/35749
@duxin40 cannot be assigned to this issue.
Better add a simple example that use Golang to implement http => TCP protocol, to show how it could be for users for easier understanding. It do not need to be runable, just a demo.
Done. in the dir: contrib/upstreams/http/tcp/test_data/http2dubbo-examples
PTAL @doujiang24 . Thank you
@doujiang24 friendly maintainer-on-call ping
@duxin40 @RyanTheOptimist Sorry for the late, thanks for the reminder, will take another look this weekend.
/docs
Docs for this Pull Request will be rendered here:
https://storage.googleapis.com/envoy-pr/36667/docs/index.html
The docs are (re-)rendered each time the CI envoy-presubmit (precheck docs) job completes.
Docs for this Pull Request will be rendered here:
https://storage.googleapis.com/envoy-pr/36667/docs/index.html
The docs are (re-)rendered each time the CI envoy-presubmit (precheck docs) job completes.
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @mattklein123
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).
/retest
I don't have time to review this giant PR. Will merge once @doujiang24 and @phlax give the ok.
/wait-any
Please run the tests in the asan mode,
Get it, here is the success result for asan mode:
vscode@docker-desktop:/workspaces/envoy$ bash -x ci/do_ci.sh asan
+ set -e
+ export SRCDIR=/workspaces/envoy
+ SRCDIR=/workspaces/envoy
+ export ENVOY_SRCDIR=/workspaces/envoy
+ ENVOY_SRCDIR=/workspaces/envoy
+++ dirname ci/do_ci.sh
++ realpath ci
+ CURRENT_SCRIPT_DIR=/workspaces/envoy/ci
+ . /workspaces/envoy/ci/build_setup.sh
++ set -e
++ [[ -n '' ]]
++++ dirname /workspaces/envoy/ci/build_setup.sh
+++ realpath /workspaces/envoy/ci
++ CURRENT_SCRIPT_DIR=/workspaces/envoy/ci
++ export PPROF_PATH=/thirdparty_build/bin/pprof
++ PPROF_PATH=/thirdparty_build/bin/pprof
++ [[ -z '' ]]
++ [[ linux-gnu == darwin* ]]
+++ grep -c '^processor' /proc/cpuinfo
++ NUM_CPUS=14
++ '[' -z /workspaces/envoy ']'
++ '[' -z '' ']'
++ export ENVOY_BUILD_TARGET=//source/exe:envoy-static
++ ENVOY_BUILD_TARGET=//source/exe:envoy-static
++ '[' -z '' ']'
++ export ENVOY_BUILD_DEBUG_INFORMATION=//source/exe:envoy-static.dwp
++ ENVOY_BUILD_DEBUG_INFORMATION=//source/exe:envoy-static.dwp
++ '[' -z '' ']'
++ export ENVOY_CONTRIB_BUILD_TARGET=//contrib/exe:envoy-static
++ ENVOY_CONTRIB_BUILD_TARGET=//contrib/exe:envoy-static
++ '[' -z '' ']'
++ export ENVOY_CONTRIB_BUILD_DEBUG_INFORMATION=//contrib/exe:envoy-static.dwp
++ ENVOY_CONTRIB_BUILD_DEBUG_INFORMATION=//contrib/exe:envoy-static.dwp
++ '[' -z '' ']'
+++ uname -m
++ ENVOY_BUILD_ARCH=aarch64
++ export ENVOY_BUILD_ARCH
++ read -ra BAZEL_BUILD_EXTRA_OPTIONS
++ read -ra BAZEL_EXTRA_TEST_OPTIONS
++ read -ra BAZEL_STARTUP_EXTRA_OPTIONS
++ read -ra BAZEL_OPTIONS
++ echo ENVOY_SRCDIR=/workspaces/envoy
ENVOY_SRCDIR=/workspaces/envoy
++ echo ENVOY_BUILD_TARGET=//source/exe:envoy-static
ENVOY_BUILD_TARGET=//source/exe:envoy-static
++ echo ENVOY_BUILD_ARCH=aarch64
ENVOY_BUILD_ARCH=aarch64
++ [[ -z /build ]]
++ [[ ! -d /build ]]
++ export BUILD_DIR
++ export ENVOY_TEST_TMPDIR=/build/tmp
++ ENVOY_TEST_TMPDIR=/build/tmp
++ export LLVM_ROOT=/opt/llvm
++ LLVM_ROOT=/opt/llvm
++ export PATH=/opt/llvm/bin:/opt/llvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/build/.local/bin:/usr/local/go/bin
++ PATH=/opt/llvm/bin:/opt/llvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/build/.local/bin:/usr/local/go/bin
++ [[ -f /etc/redhat-release ]]
++ cleanup
++ rm -rf '/workspaces/envoy/bazel-*' clang.bazelrc
++ trap cleanup EXIT
+++ which bazel
++ _bazel=/usr/local/bin/bazel
++ BAZEL_STARTUP_OPTIONS=("${BAZEL_STARTUP_EXTRA_OPTIONS[@]}" "--output_user_root=${BUILD_DIR}/bazel_root" "--output_base=${BUILD_DIR}/bazel_root/base")
++ export _bazel
++ export -f bazel
++ BAZEL_GLOBAL_OPTIONS=("--repository_cache=${BUILD_DIR}/repository_cache" "--experimental_repository_cache_hardlinks")
++ BAZEL_BUILD_OPTIONS=("${BAZEL_OPTIONS[@]}" "${BAZEL_GLOBAL_OPTIONS[@]}" "--verbose_failures" "--experimental_generate_json_trace_profile" "${BAZEL_BUILD_EXTRA_OPTIONS[@]}" "${BAZEL_EXTRA_TEST_OPTIONS[@]}")
++ [[ aarch64 == \a\a\r\c\h\6\4 ]]
++ BAZEL_BUILD_OPTIONS+=("--test_env=HEAPCHECK=")
++ [[ -z '' ]]
++ BAZEL_BUILD_OPTIONS+=("--test_tmpdir=${ENVOY_TEST_TMPDIR}")
++ echo 'Setting test_tmpdir to /build/tmp.'
Setting test_tmpdir to /build/tmp.
++ BAZEL_STARTUP_OPTION_LIST='--output_user_root=/build/bazel_root --output_base=/build/bazel_root/base'
++ BAZEL_BUILD_OPTION_LIST='--repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks --verbose_failures --experimental_generate_json_trace_profile --test_env=HEAPCHECK= --test_tmpdir=/build/tmp'
++ BAZEL_GLOBAL_OPTION_LIST='--repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks'
++ export BAZEL_STARTUP_OPTION_LIST
++ export BAZEL_BUILD_OPTION_LIST
++ export BAZEL_GLOBAL_OPTION_LIST
++ [[ -z '' ]]
++ [[ -e /opt/llvm ]]
++ /workspaces/envoy/ci/../bazel/setup_clang.sh /opt/llvm
++ [[ '' == \1 ]]
++ [[ aarch64 == \x\8\6\_\6\4 ]]
++ ENVOY_BUILD_DIR=/build/envoy/arm64
++ export ENVOY_BUILD_DIR
++ mkdir -p /build/envoy/arm64
++ export ENVOY_DELIVERY_DIR=/build/envoy/arm64/source/exe
++ ENVOY_DELIVERY_DIR=/build/envoy/arm64/source/exe
++ mkdir -p /build/envoy/arm64/source/exe
++ export ENVOY_COVERAGE_ARTIFACT=/build/envoy/arm64/generated/coverage.tar.zst
++ ENVOY_COVERAGE_ARTIFACT=/build/envoy/arm64/generated/coverage.tar.zst
++ export ENVOY_FUZZ_COVERAGE_ARTIFACT=/build/envoy/arm64/generated/fuzz_coverage.tar.zst
++ ENVOY_FUZZ_COVERAGE_ARTIFACT=/build/envoy/arm64/generated/fuzz_coverage.tar.zst
++ export ENVOY_FAILED_TEST_LOGS=/build/envoy/arm64/generated/failed-testlogs
++ ENVOY_FAILED_TEST_LOGS=/build/envoy/arm64/generated/failed-testlogs
++ mkdir -p /build/envoy/arm64/generated/failed-testlogs
++ export ENVOY_BUILD_PROFILE=/build/envoy/arm64/generated/build-profile
++ ENVOY_BUILD_PROFILE=/build/envoy/arm64/generated/build-profile
++ mkdir -p /build/envoy/arm64/generated/build-profile
++ export NO_BUILD_SETUP=1
++ NO_BUILD_SETUP=1
+ echo 'building using 14 CPUs'
building using 14 CPUs
+ echo 'building for aarch64'
building for aarch64
+ cd /workspaces/envoy
+ [[ aarch64 == \x\8\6\_\6\4 ]]
+ [[ aarch64 == \a\a\r\c\h\6\4 ]]
+ BUILD_ARCH_DIR=/linux/arm64
+ CI_TARGET=asan
+ shift
+ [[ asan =~ bazel.* ]]
+ [[ 0 -ge 1 ]]
+ COVERAGE_TEST_TARGETS=("//test/...")
+ [[ asan == \r\e\l\e\a\s\e ]]
+ [[ asan == \r\e\l\e\a\s\e\.\t\e\s\t\_\o\n\l\y ]]
+ [[ asan == \m\s\a\n ]]
+ TEST_TARGETS=("${COVERAGE_TEST_TARGETS[@]}" "@com_github_google_quiche//:ci_tests")
+ case $CI_TARGET in
+ setup_clang_toolchain
+ CONFIG_PARTS=()
+ [[ -n '' ]]
+ CONFIG_PARTS+=("clang")
+ ENVOY_STDLIB=libc++
+ [[ libc++ == \l\i\b\c\+\+ ]]
+ CONFIG_PARTS+=("libc++")
++ IFS=-
++ echo clang-libc++
+ CONFIG=clang-libc++
+ BAZEL_BUILD_OPTIONS+=("--config=${CONFIG}")
+ BAZEL_BUILD_OPTION_LIST='--repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks --verbose_failures --experimental_generate_json_trace_profile --test_env=HEAPCHECK= --test_tmpdir=/build/tmp --config=clang-libc++'
+ export BAZEL_BUILD_OPTION_LIST
+ echo 'clang toolchain with libc++ configured: clang-libc++'
clang toolchain with libc++ configured: clang-libc++
+ [[ -n '' ]]
+ ASAN_CONFIG=--config=clang-asan
+ BAZEL_BUILD_OPTIONS+=(-c dbg "${ASAN_CONFIG}" "--build_tests_only" "--remote_download_minimal")
+ echo 'bazel ASAN/UBSAN debug build with tests'
bazel ASAN/UBSAN debug build with tests
+ echo 'Building and testing envoy tests //test/... @com_github_google_quiche//:ci_tests'
Building and testing envoy tests //test/... @com_github_google_quiche//:ci_tests
+ bazel_with_collection test --repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks --verbose_failures --experimental_generate_json_trace_profile --test_env=HEAPCHECK= --test_tmpdir=/build/tmp --config=clang-libc++ -c dbg --config=clang-asan --build_tests_only --remote_download_minimal //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test
+ local failed_logs
+ declare -r BAZEL_OUTPUT=/workspaces/envoy/bazel.output.txt
+ bazel test --repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks --verbose_failures --experimental_generate_json_trace_profile --test_env=HEAPCHECK= --test_tmpdir=/build/tmp --config=clang-libc++ -c dbg --config=clang-asan --build_tests_only --remote_download_minimal //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test
+ local startup_options
+ read -ra startup_options
+ tee /workspaces/envoy/bazel.output.txt
+ /usr/local/bin/bazel --output_user_root=/build/bazel_root --output_base=/build/bazel_root/base test --repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks --verbose_failures --experimental_generate_json_trace_profile --test_env=HEAPCHECK= --test_tmpdir=/build/tmp --config=clang-libc++ -c dbg --config=clang-asan --build_tests_only --remote_download_minimal //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test
WARNING: The following configs were expanded more than once: [clang]. For repeatable flags, repeats are counted twice and may lead to unexpected behavior.
Computing main repo mapping:
WARNING: The following configs were expanded more than once: [clang]. For repeatable flags, repeats are counted twice and may lead to unexpected behavior.
Loading:
Loading: 0 packages loaded
WARNING: Build option --run_under has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
Analyzing: target //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (0 packages loaded, 0 targets configured)
Analyzing: target //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (0 packages loaded, 0 targets configured)
INFO: Analyzed target //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (0 packages loaded, 31025 targets configured).
[7,437 / 7,467] [Prepa] Testing //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (shard 1 of 30) ... (8 actions, 0 running)
[7,437 / 7,467] Testing //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (shard 12 of 30); 1s processwrapper-sandbox ... (13 actions, 8 running)
[7,442 / 7,467] [Sched] Testing //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (shard 1 of 30) ... (13 actions, 6 running)
[7,449 / 7,467] Testing //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (shard 13 of 30); 1s processwrapper-sandbox ... (13 actions, 6 running)
[7,457 / 7,467] [Sched] Testing //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (shard 26 of 30) ... (10 actions, 5 running)
[7,462 / 7,467] Testing //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test (shard 26 of 30); 0s processwrapper-sandbox ... (5 actions running)
INFO: Found 1 test target...
Target //contrib/golang/upstreams/http/tcp/test:golang_bridge_integration_test up-to-date:
bazel-bin/contrib/golang/upstreams/http/tcp/test/golang_bridge_integration_test
INFO: Elapsed time: 7.867s, Critical Path: 3.66s
INFO: 34 processes: 4 internal, 30 processwrapper-sandbox.
INFO: Build completed successfully, 34 total actions
Executed 1 out of 1 test: 1 test passes.
+ declare BAZEL_STATUS=0
+ '[' 0 '!=' 0 ']'
+ collect_build_profile test
+ local output_base
+ declare -g build_profile_count=1
++ bazel info --repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks --verbose_failures --experimental_generate_json_trace_profile --test_env=HEAPCHECK= --test_tmpdir=/build/tmp --config=clang-libc++ -c dbg --config=clang-asan --build_tests_only --remote_download_minimal output_base
++ local startup_options
++ read -ra startup_options
++ /usr/local/bin/bazel --output_user_root=/build/bazel_root --output_base=/build/bazel_root/base info --repository_cache=/build/repository_cache --experimental_repository_cache_hardlinks --verbose_failures --experimental_generate_json_trace_profile --test_env=HEAPCHECK= --test_tmpdir=/build/tmp --config=clang-libc++ -c dbg --config=clang-asan --build_tests_only --remote_download_minimal output_base
WARNING: The following configs were expanded more than once: [clang]. For repeatable flags, repeats are counted twice and may lead to unexpected behavior.
+ output_base=/build/bazel_root/base
+ mv -f /build/bazel_root/base/command.profile.gz /build/envoy/arm64/generated/build-profile/1-test.profile.gz
+ (( build_profile_count++ ))
+ cleanup
+ rm -rf /workspaces/envoy/bazel-bin /workspaces/envoy/bazel-envoy /workspaces/envoy/bazel-out /workspaces/envoy/bazel-testlogs clang.bazelrc
@duxin40 if you can merge main i will land this
/retest
@doujiang24 @phlax thanks so much for your patience and review for the gaint PR in the past three months !!!