Skip to content

Commit 3be2fbb

Browse files
committed
Another messy commit
1 parent 0f260b5 commit 3be2fbb

File tree

11 files changed

+143
-74
lines changed

11 files changed

+143
-74
lines changed

config/schema.cue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ import "path"
146146
size: string | *"256M"
147147
}
148148
records: {
149+
http: {
150+
keep_alive_no_activity_timeout_out: uint | *120
151+
}
149152
cache: {
150153
ram_cache: {
151154
size: string | *"-1"
@@ -408,7 +411,6 @@ import "path"
408411

409412
router: {
410413
api_backends: {
411-
keepalive_connections: uint | *20
412414
keepalive_idle_timeout: uint | *120
413415
}
414416
trusted_proxies: [...string] | *[]

src/api-umbrella/utils/active_config_store/set_envoy_config.lua

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,16 @@ local function build_cluster_resource(cluster_name, options)
8585
local resource = {
8686
["@type"] = "type.googleapis.com/envoy.config.cluster.v3.Cluster",
8787
name = cluster_name,
88-
type = "STRICT_DNS",
88+
cluster_type = {
89+
name = "envoy.clusters.strict_dns",
90+
typed_config = {
91+
["@type"] = "type.googleapis.com/envoy.extensions.clusters.dns.v3.DnsCluster",
92+
typed_dns_resolver_config = dns_resolver_config,
93+
respect_dns_ttl = true,
94+
},
95+
},
8996
wait_for_warm_on_init = false,
90-
typed_dns_resolver_config = dns_resolver_config,
9197
dns_lookup_family = dns_lookup_family,
92-
respect_dns_ttl = true,
9398
ignore_health_on_host_removal = true,
9499
load_assignment = {
95100
cluster_name = cluster_name,
@@ -102,11 +107,22 @@ local function build_cluster_resource(cluster_name, options)
102107
typed_extension_protocol_options = {
103108
["envoy.extensions.upstreams.http.v3.HttpProtocolOptions"] = {
104109
["@type"] = "type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions",
105-
upstream_http_protocol_options = {
106-
auto_sni = true,
110+
-- Make all API backend requests over HTTP 1.1 (instead of HTTP 2 or
111+
-- 3). Since our nginx layer already downgraded any proxied requests to
112+
-- HTTP 1.1 (since nginx doesn't currently support proxying via other
113+
-- versions), it seems simplest to stick with that approach (even
114+
-- though Envoy could proxy using a different version).
115+
explicit_http_config = {
116+
http_protocol_options = {},
107117
},
108118
common_http_protocol_options = {
109-
idle_timeout = "1s",
119+
-- Idle timeout for keepalive connections to upstream servers (API
120+
-- backends).
121+
--
122+
-- Since API backends can be remote, keepalive connections can be
123+
-- important to improving performance by keeping pre-established
124+
-- connections around.
125+
idle_timeout = file_config["router"]["api_backends"]["keepalive_idle_timeout"] .. "s",
110126
},
111127
},
112128
},
@@ -120,19 +136,16 @@ local function build_cluster_resource(cluster_name, options)
120136
},
121137
}
122138

123-
-- Use the "negative_ttl" time as Envoy's DNS refresh rate. Since we have
124-
-- "respect_dns_ttl" enabled, successful DNS requests will use that refresh
125-
-- rate instead of this one. So effectively the "dns_refresh_rate" should
126-
-- only be used in failure situations, so we can use this to provide a TTL
127-
-- for negative responses.
128-
--
129-
-- Envoy also supports the more explicit "dns_failure_refresh_rate" option,
130-
-- but that includes an exponential backoff algorithm, with random jitter,
131-
-- making it harder to test against. So to replicate how our "negative_ttl"
132-
-- has worked under other DNS situations, we will use this "dns_refresh_rate"
133-
-- (which doesn't do backoff or jitter).
139+
-- Use the "negative_ttl" time as Envoy's DNS refresh rate when failures
140+
-- occur. Since we have "respect_dns_ttl" enabled, successful DNS requests
141+
-- will use that refresh rate instead of this one. Since this is only used in
142+
-- failure situations we can use this to provide a TTL for negative
143+
-- responses.
134144
if file_config["dns_resolver"]["negative_ttl"] then
135-
resource["dns_refresh_rate"] = file_config["dns_resolver"]["negative_ttl"] .. "s"
145+
resource["cluster_type"]["typed_config"]["dns_failure_refresh_rate"] = {
146+
base_interval = file_config["dns_resolver"]["negative_ttl"] .. "s",
147+
max_interval = file_config["dns_resolver"]["negative_ttl"] .. "s",
148+
}
136149
end
137150

138151
local servers
@@ -300,7 +313,17 @@ local function build_listener()
300313
stat_prefix = "router",
301314
common_http_protocol_options = {
302315
max_headers_count = 200,
303-
idle_timeout = "15s",
316+
-- Idle timeout for keepalive connections to downstream server
317+
-- (Traffic Server).
318+
--
319+
-- We will buffer Traffic Server's own idle timeout, since
320+
-- Traffic Server should really be responsible for closing its
321+
-- own connections, so this shouldn't necessarily kick in.
322+
-- However, we will still add a timeout here since we've seen
323+
-- cases where Traffic Server doesn't close idle connections as
324+
-- expected (like if Traffic Server's
325+
-- `http.per_server.connection.min` setting is set).
326+
-- idle_timeout = file_config["trafficserver"]["records"]["http"]["keep_alive_no_activity_timeout_out"] + 5 .. "s"
304327
},
305328
generate_request_id = false,
306329
server_header_transformation = "PASS_THROUGH",

src/api-umbrella/utils/generate_runtime_config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ local function set_computed_config(config)
387387
config["envoy"]["_connect_timeout"] = config["nginx"]["proxy_connect_timeout"] .. "s"
388388
config["envoy"]["_stream_idle_timeout"] = math.max(config["nginx"]["proxy_send_timeout"], config["nginx"]["proxy_read_timeout"]) + 2 .. "s"
389389
-- Disable default 15 second timeout on the entire response being returned,
390-
-- since we will allow long-running streaming responses..
390+
-- since we will allow long-running streaming responses.
391391
config["envoy"]["_route_timeout"] = "0s"
392392
config["trafficserver"]["_connect_attempts_timeout"] = math.min(5, config["nginx"]["proxy_connect_timeout"])
393393
config["trafficserver"]["_transaction_no_activity_timeout_out"] = config["nginx"]["proxy_read_timeout"]

tasks/deps/envoy-control-plane

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
set -e -u -x
44
source ./tasks/helpers.sh
55

6-
envoy_control_plane_version="1.2.0"
7-
envoy_control_plane_hash="7add91783b597da5302aa2eb03f9e589227b9406be5f0ace087eaa62f3f5ddc2"
6+
envoy_control_plane_version="1.3.0"
7+
envoy_control_plane_hash="4f2fe25e0f5e3b6d7beaf69480e1a1882cb0c8a2e94ce649d1bce8b53fff2be3"
88
if [ "$TARGETARCH" == "arm64" ]; then
9-
envoy_control_plane_hash="6aec5ed0f25b22c781eeeb1901b19d524a4b4c6eb20695b5069ee7d412d1be8b"
9+
envoy_control_plane_hash="01553e98c4abafd108fa77f70d5a79f41acf46f5ca590a6dd193170edc3eb12d"
1010
fi
1111

1212
task_working_dir

tasks/outdated.thor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Outdated < Thor
2626
},
2727
"envoy_control_plane" => {
2828
:git => "https://github.com/GUI/envoy-control-plane.git",
29+
:github_release => "GUI/envoy-control-plane",
2930
},
3031
"fluent_bit" => {
3132
:git => "https://github.com/fluent/fluent-bit.git",

templates/etc/envoy/envoy.yaml.etlua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ typed_dns_resolver_config:
1313
static_resources:
1414
clusters:
1515
- name: api-umbrella-cluster
16-
type: LOGICAL_DNS
16+
cluster_type:
17+
name: envoy.clusters.logical_dns
18+
typed_config:
19+
"@type": type.googleapis.com/envoy.extensions.clusters.dns.v3.DnsCluster
20+
respect_dns_ttl: true
1721
dns_lookup_family: V4_PREFERRED
18-
respect_dns_ttl: true
1922
ignore_health_on_host_removal: true
2023
load_assignment:
2124
cluster_name: api-umbrella-cluster

templates/etc/nginx/router.conf.etlua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ http {
263263
}
264264
<% end %>
265265

266+
<% if config["_test_env?"] then %>
267+
location = /_nginx_status {
268+
add_header Content-Type application/json;
269+
return 200 '{
270+
"connection": $connection,
271+
"connection_requests": $connection_requests,
272+
"connections_active": $connections_active,
273+
"connections_reading": $connections_reading,
274+
"connections_waiting": $connections_waiting,
275+
"connections_writing": $connections_writing
276+
}';
277+
}
278+
<% end %>
279+
266280
location / {
267281
include ./gatekeeper.conf;
268282
}

templates/etc/trafficserver/plugin.config.etlua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ header_rewrite.so "<%- config["etc_dir"] %>/trafficserver/header_rewrite.conf"
1111
# the same URL: https://issues.apache.org/jira/browse/TS-3431
1212
cachekey.so --include-headers=Host,X-Api-Umbrella-Backend-Host,X-Api-Umbrella-Cache-Request-Method
1313

14-
stats_over_http.so
15-
1614
<% if config["_strip_response_cookies_regex"] then %>
1715
tslua.so "<%- config["etc_dir"] %>/trafficserver/strip_response_cookies.lua" "<%- config["etc_dir"] %>/trafficserver/strip_response_cookies_regex.txt"
1816
<% end %>
17+
18+
# Provide endpoint for Traffic Server stats.
19+
stats_over_http.so

templates/etc/trafficserver/records.yaml.etlua

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ records:
3131
warning: E
3232

3333
# Enable for debug logging.
34-
debug:
35-
enabled: 1
36-
tags: ".*"
34+
# debug:
35+
# enabled: 1
36+
# tags: ".*"
3737

3838
error:
3939
logfile:
@@ -120,22 +120,16 @@ records:
120120
# Don't override the "Server" response header with the TrafficServer signature.
121121
response_server_enabled: 0
122122

123-
# Keepalive connections to backend Envoy server. Retain some idle
124-
# connections open to improve performance.
125-
keep_alive_no_activity_timeout_out: 99 # <%= json_encode(config["router"]["api_backends"]["keepalive_idle_timeout"]) %>
126-
# transaction_no_activity_timeout_out: 1
127-
per_server:
128-
connection:
129-
min: 1 # <%= json_encode(config["router"]["api_backends"]["keepalive_connections"]) %>
130-
match: ip
123+
# How long to keep idle keepalive connections to backend Envoy server
124+
# around.
125+
keep_alive_no_activity_timeout_out: <%- json_encode(config["trafficserver"]["records"]["http"]["keep_alive_no_activity_timeout_out"]) %>
131126

132127
# Since we're only connecting to our backend Envoy server, we can significantly
133128
# reduce connections TrafficServer tries to open by ignoring the Host for
134129
# session reuse (since Envoy will be responsible for actually connecting to the
135130
# backend servers).
136131
server_session_sharing:
137132
match: ip
138-
pool: global_locked
139133

140134
# For read_while_writer configuration in the `cache` section.
141135
background_fill_active_timeout: 0
@@ -185,12 +179,12 @@ records:
185179
# Requires enabling redirect following, which we don't want for other
186180
# responses:
187181
# https://lists.apache.org/thread.html/0eff5d9a53ef8fdf28be341f648c708bd651ad1208cddf71d532d78d@%3Cusers.trafficserver.apache.org%3E
188-
# max_doc_size: 0
189-
# enable_read_while_writer: 1
190-
# read_while_writer:
191-
# max_retries: 21
192-
# read_while_writer_retry:
193-
# delay: 50
182+
max_doc_size: 0
183+
enable_read_while_writer: 1
184+
read_while_writer:
185+
max_retries: 21
186+
read_while_writer_retry:
187+
delay: 50
194188

195189
dns:
196190
# Set the DNS nameservers used to potentially resolve a remote envoy layer.

0 commit comments

Comments
 (0)