This is an automated email from the ASF dual-hosted git repository.
wkaras pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new b419f60208 Fix, add metrics testing to tls_tunnel Au test. (#9518)
b419f60208 is described below
commit b419f602086653d71dc089b289f809ea7e6ba116
Author: Walt Karas <[email protected]>
AuthorDate: Mon Jun 26 18:20:22 2023 -0500
Fix, add metrics testing to tls_tunnel Au test. (#9518)
* Add metrics testing to tls_tunnel Au test.
* For request method metrics, avoid re-counting same transaction.
proxy.process.http.connect_requests is an example of a method metric.
* Add code comment to address review comment.
* Change to reflect two new successful test runs in tls_tunnel.test.py.
Changes to Au test in commit:
f0cdd4a84c22f96bd3d73fc81027dcceba796536
---
proxy/http/HttpTransact.cc | 11 ++-
proxy/http/HttpTransact.h | 4 ++
tests/gold_tests/tls/gold/tls-tunnel-metrics.gold | 7 ++
tests/gold_tests/tls/tls_tunnel.test.py | 20 ++++++
tests/tools/stdout_wait | 82 +++++++++++++++++++++++
5 files changed, 123 insertions(+), 1 deletion(-)
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index f2e6dfae5b..d2a1ba1c9a 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -5731,9 +5731,18 @@
HttpTransact::initialize_state_variables_from_request(State *s, HTTPHdr *obsolet
s->cache_info.action = CACHE_DO_NO_ACTION;
}
+ // This function, HttpTransact::initialize_state_variables_from_request(),
may be called multiple times for the same
+ // HTTP request. But we only want to increment the per-method request count
the first time this function is called
+ // for each request. 0 is the value that the State class constructor
initializes 'method' to, it means unset, so
+ // method should only be 0 if it's the first call to this function.
+ //
+ bool do_increment_stat = (0 == s->method);
+
s->method = incoming_request->method_get_wksidx();
- if (s->method == HTTP_WKSIDX_GET) {
+ if (!do_increment_stat) {
+ ;
+ } else if (s->method == HTTP_WKSIDX_GET) {
HTTP_INCREMENT_DYN_STAT(http_get_requests_stat);
} else if (s->method == HTTP_WKSIDX_HEAD) {
HTTP_INCREMENT_DYN_STAT(http_head_requests_stat);
diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h
index e30a811465..c8b7cf1bb2 100644
--- a/proxy/http/HttpTransact.h
+++ b/proxy/http/HttpTransact.h
@@ -1049,7 +1049,11 @@ public:
static bool handle_internal_request(State *s, HTTPHdr *incoming_hdr);
static bool handle_trace_and_options_requests(State *s, HTTPHdr
*incoming_hdr);
static void bootstrap_state_variables_from_request(State *s, HTTPHdr
*incoming_request);
+
+ // WARNING: this function may be called multiple times for the same
transaction.
+ //
static void initialize_state_variables_from_request(State *s, HTTPHdr
*obsolete_incoming_request);
+
static void initialize_state_variables_from_response(State *s, HTTPHdr
*incoming_response);
static bool is_server_negative_cached(State *s);
static bool is_cache_response_returnable(State *s);
diff --git a/tests/gold_tests/tls/gold/tls-tunnel-metrics.gold
b/tests/gold_tests/tls/gold/tls-tunnel-metrics.gold
new file mode 100644
index 0000000000..081b4cfad7
--- /dev/null
+++ b/tests/gold_tests/tls/gold/tls-tunnel-metrics.gold
@@ -0,0 +1,7 @@
+proxy.process.http.total_incoming_connections 11
+proxy.process.http.total_client_connections 11
+proxy.process.http.total_client_connections_ipv4 11
+proxy.process.http.total_client_connections_ipv6 0
+proxy.process.http.total_server_connections 0
+proxy.process.http2.total_client_connections 2
+proxy.process.http.connect_requests 10
diff --git a/tests/gold_tests/tls/tls_tunnel.test.py
b/tests/gold_tests/tls/tls_tunnel.test.py
index fd14c3fe77..321302d535 100644
--- a/tests/gold_tests/tls/tls_tunnel.test.py
+++ b/tests/gold_tests/tls/tls_tunnel.test.py
@@ -220,6 +220,8 @@ tr.Processes.Default.Streams.All +=
Testers.ContainsExpression(
"HTTP/1.1 200 OK",
"Verify a successful response is received")
+# This test run causes an exception in proxy_protocol_client.py
+#
tr = Test.AddTestRun("test proxy_protocol_port - not in connect_ports")
tr.Processes.Default.StartBefore(server_forbidden)
tr.Setup.Copy('proxy_protocol_client.py')
@@ -322,3 +324,21 @@ tr.Processes.Default.Streams.All +=
Testers.ExcludesExpression("Could Not Connec
tr.Processes.Default.Streams.All += Testers.ExcludesExpression("Not Found on
Accelerato", "Terminates on on Traffic Server")
tr.Processes.Default.Streams.All += Testers.ExcludesExpression("ATS",
"Terminate on Traffic Server")
tr.Processes.Default.Streams.All += Testers.ContainsExpression("bar ok",
"Should get a response from bar")
+
+tr = Test.AddTestRun("Test Metrics")
+tr.Processes.Default.Command = (
+ f"{Test.Variables.AtsTestToolsDir}/stdout_wait" +
+ " 'traffic_ctl metric get" +
+ " proxy.process.http.total_incoming_connections" +
+ " proxy.process.http.total_client_connections" +
+ " proxy.process.http.total_client_connections_ipv4" +
+ " proxy.process.http.total_client_connections_ipv6" +
+ " proxy.process.http.total_server_connections" +
+ " proxy.process.http2.total_client_connections" +
+ " proxy.process.http.connect_requests'" +
+ f" {Test.TestDirectory}/gold/tls-tunnel-metrics.gold"
+)
+# Need to copy over the environment so traffic_ctl knows where to find the
unix domain socket
+tr.Processes.Default.Env = ts.Env
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts
diff --git a/tests/tools/stdout_wait b/tests/tools/stdout_wait
new file mode 100755
index 0000000000..059eb1fdf2
--- /dev/null
+++ b/tests/tools/stdout_wait
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A bash script to repeatedly run a command until its standard output matches
a gold file.
+#
+# usage:
+# stdout_wait [ MAX-WAIT [ POST-WAIT ] ] COMMAND GOLD-FILE-SPEC
+#
+# (COMMAND may contain white space.)
+#
+# MAX-WAIT is the maximum number of seconds to wait for the condition. If it
is omitted, it defaults to 60.
+#
+# POST-WAIT is the number of seconds to wait after the condition is true. If
it is omitted, it defaults to 0.
+#
+# The script exits with status 0 when the command's standard output matches
the gold file. It exits with status 1 if the
+# output never matche the gold file, and the maximum wait has expired.
+
+WAIT=60
+POST_WAIT=0
+
+USAGE="usage: stdout_wait [ MAX-WAIT [ POST-WAIT ] ] COMMAND GOLD-FILE-SPEC"
+
+if [[ "$1" = "" ]] ; then
+ echo $USAGE >&2
+ exit 1
+fi
+
+X=$( echo "$1" | sed 's/x/yy/g' | sed 's/[^0-9]/x/g' )
+if [[ "$X" = "$1" ]] ; then
+ WAIT=$1
+ shift
+ if [[ "$1" = "" ]] ; then
+ echo $USAGE >&2
+ exit 1
+ fi
+ X=$( echo "$1" | sed 's/x/yy/g' | sed 's/[^0-9]/x/g' )
+ if [[ "$X" = "$1" ]] ; then
+ POST_WAIT=$1
+ shift
+ fi
+fi
+
+if [[ "$1" = "" ]] ; then
+ echo $USAGE >&2
+ exit 1
+fi
+
+if [[ ! -f "$2" ]] ; then
+ echo $USAGE >&2
+ exit 1
+fi
+
+while (( WAIT > 0 ))
+do
+ if $1 | diff - $2 >| /dev/null 2> /dev/null
+ then
+ if (( POST_WAIT > 0 ))
+ then
+ sleep $POST_WAIT
+ fi
+ exit 0
+ fi
+ sleep 1
+ let WAIT=WAIT-1
+done
+$1 | diff - $2
+exit 1