Skip to content

Commit

Permalink
core: integration with Envoy's API listener (#616)
Browse files Browse the repository at this point in the history
Description: this PR integrates [Envoy's ApiListener](#9516) to replace Envoy Mobile's use of the AsyncClient. Doing so gives Envoy Mobile access to all L7 facilities provided by Envoy's Http Connection Manager; including but no limited to the L7 filters.
Risk Level: HIGH! This PR changes the underlying code for Envoy Mobile's core functionality
Testing: unit tests updated for the dispatcher, integration tests, and e2e tests with the example apps. Additionally, the ApiListener code has been unit and integration tested in Envoy.

Fixes #543

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
  • Loading branch information
junr03 authored and jpsim committed Nov 29, 2022
1 parent 3bc069c commit cec88b7
Show file tree
Hide file tree
Showing 23 changed files with 1,676 additions and 804 deletions.
6 changes: 3 additions & 3 deletions mobile/.github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: 'Install dependencies'
run: ./ci/mac_ci_setup.sh
- name: 'Run tests'
run: bazel test //test/common/...
run: bazel test --test_output=all //test/common/...
tsan:
name: tsan
runs-on: ubuntu-18.04
Expand All @@ -34,7 +34,7 @@ jobs:
export PATH=/usr/lib/llvm-8/bin:$PATH
export CC=clang
export CXX=clang++
bazel test --config=clang-tsan //test/common/...
bazel test --config=clang-tsan --test_output=all //test/common/...
asan:
name: asan
runs-on: ubuntu-18.04
Expand All @@ -50,4 +50,4 @@ jobs:
export PATH=/usr/lib/llvm-8/bin:$PATH
export CC=clang
export CXX=clang++
bazel test --config=clang-asan //test/common/...
bazel test --config=clang-asan --test_output=all //test/common/...
6 changes: 3 additions & 3 deletions mobile/.github/workflows/perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
sizecurrent:
name: size_current
runs-on: ubuntu-18.04
timeout-minutes: 45
timeout-minutes: 60
steps:
- uses: actions/checkout@v1
with:
Expand All @@ -26,7 +26,7 @@ jobs:
sizemaster:
name: size_master
runs-on: ubuntu-18.04
timeout-minutes: 45
timeout-minutes: 60
steps:
- uses: actions/checkout@v1
with:
Expand All @@ -45,7 +45,7 @@ jobs:
name: size_compare
needs: [sizecurrent, sizemaster]
runs-on: ubuntu-18.04
timeout-minutes: 45
timeout-minutes: 30
steps:
- uses: actions/checkout@v1
- name: 'Install dependencies'
Expand Down
93 changes: 65 additions & 28 deletions mobile/library/common/config_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,51 @@
*/
const char* config_template = R"(
static_resources:
listeners:
- name: base_api_listener
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 10000
api_listener:
api_listener:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: hcm
route_config:
name: api_router
virtual_hosts:
- name: api
domains:
- "*"
routes:
- match:
prefix: "/"
route:
cluster_header: x-envoy-mobile-cluster
http_filters:
- name: envoy.filters.http.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.FilterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: AUTO
dns_refresh_rate: {{ dns_refresh_rate_seconds }}s
- name: envoy.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: base # Note: the direct API depends on the existence of a cluster with this name.
- name: base
connect_timeout: {{ connect_timeout_seconds }}s
dns_refresh_rate: {{ dns_refresh_rate_seconds }}s
http2_protocol_options: {}
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: base
endpoints: &base_endpoints
- lb_endpoints:
- endpoint:
address:
socket_address: {address: {{ domain }}, port_value: 443}
lb_policy: CLUSTER_PROVIDED
cluster_type:
name: envoy.clusters.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: AUTO
dns_refresh_rate: {{ dns_refresh_rate_seconds }}s
transport_socket: &base_transport_socket
name: envoy.transport_sockets.tls
typed_config:
Expand All @@ -28,33 +60,38 @@ const char* config_template = R"(
#include "certificates.inc"
R"(
sni: {{ domain }}
type: LOGICAL_DNS
upstream_connection_options: &upstream_opts
tcp_keepalive:
keepalive_interval: 10
keepalive_probes: 1
keepalive_time: 5
- name: base_wlan # Note: the direct API depends on the existence of a cluster with this name.
transport_socket: *base_transport_socket
upstream_connection_options: *upstream_opts
- name: base_wlan
connect_timeout: {{ connect_timeout_seconds }}s
dns_refresh_rate: {{ dns_refresh_rate_seconds }}s
http2_protocol_options: {}
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: base_wlan
endpoints: *base_endpoints
lb_policy: CLUSTER_PROVIDED
cluster_type:
name: envoy.clusters.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: AUTO
dns_refresh_rate: {{ dns_refresh_rate_seconds }}s
transport_socket: *base_transport_socket
type: LOGICAL_DNS
upstream_connection_options: *upstream_opts
- name: base_wwan # Note: the direct API depends on the existence of a cluster with this name.
- name: base_wwan
connect_timeout: {{ connect_timeout_seconds }}s
dns_refresh_rate: {{ dns_refresh_rate_seconds }}s
http2_protocol_options: {}
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: base_wwan
endpoints: *base_endpoints
lb_policy: CLUSTER_PROVIDED
cluster_type:
name: envoy.clusters.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: AUTO
dns_refresh_rate: {{ dns_refresh_rate_seconds }}s
transport_socket: *base_transport_socket
type: LOGICAL_DNS
upstream_connection_options: *upstream_opts
- name: stats
connect_timeout: {{ connect_timeout_seconds }}s
Expand Down
4 changes: 3 additions & 1 deletion mobile/library/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ envoy_status_t Engine::run(std::string config, std::string log_level) {
postinit_callback_handler_ = main_common_->server()->lifecycleNotifier().registerCallback(
Envoy::Server::ServerLifecycleNotifier::Stage::PostInit, [this]() -> void {
Server::Instance* server = TS_UNCHECKED_READ(main_common_)->server();
http_dispatcher_->ready(server->dispatcher(), server->clusterManager());
auto api_listener = server->listenerManager().apiListener()->get().http();
ASSERT(api_listener.has_value());
http_dispatcher_->ready(server->dispatcher(), api_listener.value());
});
} // mutex_

Expand Down
6 changes: 5 additions & 1 deletion mobile/library/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ envoy_cc_library(
"//library/common/buffer:bridge_fragment_lib",
"//library/common/buffer:utility_lib",
"//library/common/http:header_utility_lib",
"//library/common/network:synthetic_address_lib",
"//library/common/thread:lock_guard_lib",
"//library/common/types:c_types_lib",
"@envoy//include/envoy/buffer:buffer_interface",
"@envoy//include/envoy/event:dispatcher_interface",
"@envoy//include/envoy/http:api_listener_interface",
"@envoy//include/envoy/http:async_client_interface",
"@envoy//include/envoy/http:header_map_interface",
"@envoy//include/envoy/upstream:cluster_manager_interface",
"@envoy//source/common/buffer:buffer_lib",
"@envoy//source/common/common:lock_guard_lib",
"@envoy//source/common/common:minimal_logger_lib",
"@envoy//source/common/common:thread_lib",
"@envoy//source/common/common:thread_synchronizer_lib",
"@envoy//source/common/http:codec_helper_lib",
"@envoy//source/common/http:headers_lib",
"@envoy//source/common/http:utility_lib",
],
Expand Down
Loading

0 comments on commit cec88b7

Please sign in to comment.