Skip to content

Commit 1b069fb

Browse files
masaori335cmcfarlen
authored andcommitted
Add AuTest for connect_attempts rr_retries and max_retries (#12932)
* Add AuTest for connect_attempts * Make error.log gold file platform neutral * Address issue on Docker env * Make Copilot happy (cherry picked from commit b5557e6)
1 parent e0e2589 commit 1b069fb

9 files changed

Lines changed: 503 additions & 2 deletions

src/proxy/http/HttpTransact.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,9 +3995,9 @@ HttpTransact::error_log_connection_failure(State *s, ServerState_t conn_state)
39953995
host_name = s->unmapped_url.host_get();
39963996
}
39973997
swoc::bwprint(error_bw_buffer,
3998-
"CONNECT: attempt fail [{}] to {} for host='{}' "
3998+
"CONNECT: attempt fail [{}] to {} for host='{}' sm_id={} "
39993999
"connection_result={::s} error={::s} retry_attempts={} url='{}'",
4000-
HttpDebugNames::get_server_state_name(conn_state), s->current.server->dst_addr, host_name,
4000+
HttpDebugNames::get_server_state_name(conn_state), s->current.server->dst_addr, host_name, s->state_machine_id(),
40014001
swoc::bwf::Errno(s->current.server->connect_result), swoc::bwf::Errno(s->cause_of_death_errno),
40024002
s->current.retry_attempts.get(), swoc::bwf::FirstOf(url_str, "<none>"));
40034003
Log::error("%s", error_bw_buffer.c_str());

tests/gold_tests/autest-site/ats_replay.test.ext

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ def configure_ats(obj: 'TestRun', server: 'Process', ats_config: dict, dns: Opti
119119
gold_file = diags_log['gold_file']
120120
ts.Disk.diags_log.Content += gold_file
121121

122+
# error_log validation.
123+
error_log = log_validation.get('error_log', {})
124+
for contains_entry in error_log.get('contains', []):
125+
expression = contains_entry['expression']
126+
description = contains_entry.get('description', f'Verify error_log contains: {expression}')
127+
ts.Disk.error_log.Content += Testers.ContainsExpression(expression, description)
128+
for excludes_entry in error_log.get('excludes', []):
129+
expression = excludes_entry['expression']
130+
description = excludes_entry.get('description', f'Verify error_log excludes: {expression}')
131+
ts.Disk.error_log.Content += Testers.ExcludesExpression(expression, description)
132+
# Gold file validation for error_log.
133+
if 'gold_file' in error_log:
134+
gold_file = error_log['gold_file']
135+
ts.Disk.error_log.Content += gold_file
136+
122137
# access_log validation.
123138
access_log = log_validation.get('access_log', {})
124139
if 'gold_file' in access_log:
@@ -182,6 +197,8 @@ def ATSReplayTest(obj, replay_file: str):
182197
dns = tr.MakeDNServer(name, **process_config)
183198
else:
184199
dns = tr.MakeDNServer(name, default='127.0.0.1')
200+
if 'records' in dns_config:
201+
dns.addRecords(dns_config['records'])
185202

186203
# Proxy Verifier Server configuration.
187204
if not 'server' in autest_config:
@@ -215,6 +232,7 @@ def ATSReplayTest(obj, replay_file: str):
215232
ats_config = autest_config['ats']
216233
enable_tls = ats_config.get('enable_tls', False)
217234
metric_checks = ats_config.get('metric_checks', [])
235+
log_validation = ats_config.get('log_validation', None)
218236

219237
ats_owner = obj if _requires_persistent_ats(ats_config) else tr
220238
ts = configure_ats(ats_owner, server=server, ats_config=ats_config, dns=dns)
@@ -272,6 +290,13 @@ def ATSReplayTest(obj, replay_file: str):
272290
f'^{re.escape(metric_name)}\\s+{expected_value}$', f'{metric_name} should be {expected_value}')
273291
check_tr.StillRunningAfter = ts
274292

293+
# wait for error log
294+
if log_validation and log_validation.get('error_log'):
295+
wait_for_log = obj.AddTestRun('Wait for logs of ' + ats_config.get('name', 'ts'))
296+
wait_for_log.Processes.Default.Command = (
297+
os.path.join(obj.Variables.AtsTestToolsDir, 'condwait') + ' 60 1 -f ' + os.path.join(ts.Variables.LOGDIR, 'error.log'))
298+
wait_for_log.Processes.Default.ReturnCode = 0
299+
275300
return tr
276301

277302

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''
2+
Verify Origin Server Connect Attempts Behavior
3+
'''
4+
# Licensed to the Apache Software Foundation (ASF) under one
5+
# or more contributor license agreements. See the NOTICE file
6+
# distributed with this work for additional information
7+
# regarding copyright ownership. The ASF licenses this file
8+
# to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance
10+
# with the License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
Test.Summary = '''
21+
Verify Origin Server Connect Attempts Behavior
22+
'''
23+
24+
# No retry
25+
Test.ATSReplayTest(replay_file="replay/connect_attempts_rr_no_retry.replay.yaml")
26+
27+
# max_retries
28+
Test.ATSReplayTest(replay_file="replay/connect_attempts_rr_max_retries.replay.yaml")
29+
30+
# rr_retries
31+
Test.ATSReplayTest(replay_file="replay/connect_attempts_rr_retries.replay.yaml")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' sm_id=0 `` retry_attempts=0 url='http://backend.example.com:``/path/'
2+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' sm_id=0 `` retry_attempts=1 url='http://backend.example.com:``/path/'
3+
`` CONNECT : `` connecting to 0.0.0.1:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
4+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' sm_id=1 `` retry_attempts=0 url='http://backend.example.com:``/path/'
5+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' sm_id=1 `` retry_attempts=1 url='http://backend.example.com:``/path/'
6+
`` CONNECT : `` connecting to 0.0.0.2:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
7+
`` DNS Error: no valid server http://backend.example.com:``/path/
8+
``
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' sm_id=0 `` retry_attempts=0 url='http://backend.example.com:``/path/'
2+
`` CONNECT : `` connecting to 0.0.0.1:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
3+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' sm_id=1 `` retry_attempts=0 url='http://backend.example.com:``/path/'
4+
`` CONNECT : `` connecting to 0.0.0.2:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
5+
`` DNS Error: no valid server http://backend.example.com:``/path/
6+
``
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' sm_id=0 connection_result=`` error=`` retry_attempts=0 url='http://backend.example.com:``/path/'
2+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' sm_id=1 connection_result=`` error=`` retry_attempts=0 url='http://backend.example.com:``/path/'
3+
`` CONNECT : `` connecting to 0.0.0.1:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='2' marking down
4+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' sm_id=2 connection_result=`` error=`` retry_attempts=0 url='http://backend.example.com:``/path/'
5+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' sm_id=3 connection_result=`` error=`` retry_attempts=0 url='http://backend.example.com:``/path/'
6+
`` CONNECT : `` connecting to 0.0.0.2:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='2' marking down
7+
`` DNS Error: no valid server http://backend.example.com:``/path/
8+
``
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
meta:
18+
version: "1.0"
19+
20+
# Configuration section for autest integration
21+
autest:
22+
description: 'Verify connect attempts behavior - round robin'
23+
24+
dns:
25+
name: 'dns-rr'
26+
records: {"backend.example.com": ["0.0.0.1", "0.0.0.2"]}
27+
28+
server:
29+
name: 'server-rr'
30+
31+
client:
32+
name: 'client-rr'
33+
34+
ats:
35+
name: 'ts-rr'
36+
process_config:
37+
enable_cache: false
38+
39+
records_config:
40+
proxy.config.diags.debug.enabled: 1
41+
proxy.config.diags.debug.tags: 'http|hostdb|dns'
42+
proxy.config.http.connect_attempts_rr_retries: 0
43+
proxy.config.http.connect_attempts_max_retries: 1
44+
proxy.config.http.connect_attempts_max_retries_down_server: 0
45+
proxy.config.http.connect_attempts_timeout: 1
46+
proxy.config.http.down_server.cache_time: 10
47+
48+
remap_config:
49+
- from: "http://example.com/"
50+
to: "http://backend.example.com:{SERVER_HTTP_PORT}/"
51+
52+
log_validation:
53+
error_log:
54+
gold_file: "gold/connect_attempts_rr_max_retries_error_log.gold"
55+
56+
sessions:
57+
- transactions:
58+
# try 0.0.0.1
59+
- client-request:
60+
method: GET
61+
url: /path/
62+
version: '1.1'
63+
headers:
64+
fields:
65+
- [Host, example.com]
66+
- [uuid, 1]
67+
68+
# should not hit
69+
server-response:
70+
status: 200
71+
reason: OK
72+
73+
proxy-response:
74+
status: 502
75+
76+
# try 0.0.0.2
77+
- client-request:
78+
method: GET
79+
url: /path/
80+
version: '1.1'
81+
headers:
82+
fields:
83+
- [Host, example.com]
84+
- [uuid, 2]
85+
86+
# should not hit
87+
server-response:
88+
status: 200
89+
reason: OK
90+
91+
proxy-response:
92+
status: 502
93+
94+
# The request is expected to hit the down_server cache and immediately receive a 500 response.
95+
- client-request:
96+
method: GET
97+
url: /path/
98+
version: '1.1'
99+
headers:
100+
fields:
101+
- [Host, example.com]
102+
- [uuid, 10]
103+
104+
# should not hit
105+
server-response:
106+
status: 200
107+
reason: OK
108+
109+
proxy-response:
110+
status: 500
111+
112+
# when down_server.cache_time is expired, try connect attempts
113+
- client-request:
114+
method: GET
115+
url: /path/
116+
version: '1.1'
117+
headers:
118+
fields:
119+
- [Host, example.com]
120+
- [uuid, 20]
121+
delay: 10s
122+
123+
# should not hit
124+
server-response:
125+
status: 200
126+
reason: OK
127+
128+
proxy-response:
129+
status: 502
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
meta:
18+
version: "1.0"
19+
20+
# Configuration section for autest integration
21+
autest:
22+
description: 'Verify connect attempts behavior - no retry'
23+
24+
dns:
25+
name: 'dns-no'
26+
records: {"backend.example.com": ["0.0.0.1", "0.0.0.2"]}
27+
28+
server:
29+
name: 'server-no'
30+
31+
client:
32+
name: 'client-no'
33+
34+
ats:
35+
name: 'ts-no'
36+
process_config:
37+
enable_cache: false
38+
39+
records_config:
40+
proxy.config.diags.debug.enabled: 1
41+
proxy.config.diags.debug.tags: 'http|hostdb|dns'
42+
proxy.config.http.connect_attempts_rr_retries: 0
43+
proxy.config.http.connect_attempts_max_retries: 0
44+
proxy.config.http.connect_attempts_max_retries_down_server: 0
45+
proxy.config.http.connect_attempts_timeout: 1
46+
proxy.config.http.down_server.cache_time: 5
47+
48+
remap_config:
49+
- from: "http://example.com/"
50+
to: "http://backend.example.com:{SERVER_HTTP_PORT}/"
51+
52+
log_validation:
53+
error_log:
54+
gold_file: "gold/connect_attempts_rr_no_error_log.gold"
55+
56+
sessions:
57+
- transactions:
58+
# try 0.0.0.1
59+
- client-request:
60+
method: GET
61+
url: /path/
62+
version: '1.1'
63+
headers:
64+
fields:
65+
- [Host, example.com]
66+
- [uuid, 1]
67+
68+
# should not hit
69+
server-response:
70+
status: 200
71+
reason: OK
72+
73+
proxy-response:
74+
status: 502
75+
76+
# try 0.0.0.2
77+
- client-request:
78+
method: GET
79+
url: /path/
80+
version: '1.1'
81+
headers:
82+
fields:
83+
- [Host, example.com]
84+
- [uuid, 2]
85+
86+
# should not hit
87+
server-response:
88+
status: 200
89+
reason: OK
90+
91+
proxy-response:
92+
status: 502
93+
94+
# This request is expected to hit the down_server cache and immediately receive a 500 response.
95+
- client-request:
96+
method: GET
97+
url: /path/
98+
version: '1.1'
99+
headers:
100+
fields:
101+
- [Host, example.com]
102+
- [uuid, 10]
103+
104+
# should not hit
105+
server-response:
106+
status: 200
107+
reason: OK
108+
109+
proxy-response:
110+
status: 500
111+
112+
# when down_server.cache_time is expired, try connect attempts
113+
- client-request:
114+
method: GET
115+
url: /path/
116+
version: '1.1'
117+
headers:
118+
fields:
119+
- [Host, example.com]
120+
- [uuid, 20]
121+
delay: 10s
122+
123+
# should not hit
124+
server-response:
125+
status: 200
126+
reason: OK
127+
128+
proxy-response:
129+
status: 502

0 commit comments

Comments
 (0)