@@ -49,13 +49,29 @@ def _configure_trafficserver(self) -> None:
4949 'proxy.config.dns.nameservers' : f"127.0.0.1:{ self ._dns .Variables .Port } " ,
5050 'proxy.config.dns.resolv_conf' : 'NULL' ,
5151 'proxy.config.diags.debug.enabled' : 1 ,
52- 'proxy.config.diags.debug.tags' : 'http' ,
52+ 'proxy.config.diags.debug.tags' : 'http|conn_track ' ,
5353 'proxy.config.http.per_server.connection.max' : self ._origin_max_connections ,
54+ 'proxy.config.http.per_server.connection.metric_enabled' : 1 ,
55+ 'proxy.config.http.per_server.connection.metric_prefix' : 'foo' ,
56+ 'proxy.config.http.per_server.connection.match' : 'port' ,
5457 })
5558 self ._ts .Disk .diags_log .Content += Testers .ContainsExpression (
5659 f'WARNING:.*too many connections:.*limit={ self ._origin_max_connections } ' ,
5760 'Verify the user is warned about the connection limit being hit.' )
5861
62+ def _test_metrics (self ) -> None :
63+ """Use traffic_ctl to test metrics."""
64+ tr = Test .AddTestRun ("Check connection metrics" )
65+ tr .Processes .Default .Command = 'traffic_ctl metric match per_server'
66+ tr .Processes .Default .ReturnCode = 0
67+ tr .Processes .Default .Env = self ._ts .Env
68+ tr .Processes .Default .Streams .All = Testers .ContainsExpression (
69+ f'per_server.total_connection.foo.127.0.0.1:{ self ._server .Variables .http_port } 4' ,
70+ 'incorrect statistic return, or possible error.' )
71+ tr .Processes .Default .Streams .All = Testers .ContainsExpression (
72+ f'per_server.blocked_connection.foo.127.0.0.1:{ self ._server .Variables .http_port } 1' ,
73+ 'incorrect statistic return, or possible error.' )
74+
5975 def run (self ) -> None :
6076 """Configure the TestRun."""
6177 tr = Test .AddTestRun ('Verify we enforce proxy.config.http.per_server.connection.max' )
@@ -65,18 +81,19 @@ def run(self) -> None:
6581
6682 tr .AddVerifierClientProcess ('client' , self ._replay_file , http_ports = [self ._ts .Variables .port ])
6783
84+ self ._test_metrics ()
85+
6886
6987class ConnectMethodTest :
7088 """Test our max origin connection behavior with CONNECT traffic."""
7189
7290 _client_counter : int = 0
73- _origin_max_connections : int = 3
7491
75- def __init__ (self ) -> None :
92+ def __init__ (self , max_conn ) -> None :
7693 """Configure the server processes in preparation for the TestRun."""
7794 self ._configure_dns ()
7895 self ._configure_origin_server ()
79- self ._configure_trafficserver ()
96+ self ._configure_trafficserver (max_conn )
8097
8198 def _configure_dns (self ) -> None :
8299 """Configure a nameserver for the test."""
@@ -86,18 +103,19 @@ def _configure_origin_server(self) -> None:
86103 """Configure the httpbin origin server."""
87104 self ._server = Test .MakeHttpBinServer ("server2" )
88105
89- def _configure_trafficserver (self ) -> None :
90- self ._ts = Test .MakeATSProcess ("ts2" )
106+ def _configure_trafficserver (self , max_conn ) -> None :
107+ self ._ts = Test .MakeATSProcess ("ts2_" + str ( max_conn ) )
91108
92109 self ._ts .Disk .records_config .update (
93110 {
94111 'proxy.config.dns.nameservers' : f"127.0.0.1:{ self ._dns .Variables .Port } " ,
95112 'proxy.config.dns.resolv_conf' : 'NULL' ,
96113 'proxy.config.diags.debug.enabled' : 1 ,
97- 'proxy.config.diags.debug.tags' : 'http|dns|hostdb' ,
114+ 'proxy.config.diags.debug.tags' : 'http|dns|hostdb|conn_track ' ,
98115 'proxy.config.http.server_ports' : f"{ self ._ts .Variables .port } " ,
99116 'proxy.config.http.connect_ports' : f"{ self ._server .Variables .Port } " ,
100- 'proxy.config.http.per_server.connection.max' : self ._origin_max_connections ,
117+ 'proxy.config.http.per_server.connection.metric_enabled' : 1 ,
118+ 'proxy.config.http.per_server.connection.max' : max_conn ,
101119 })
102120
103121 self ._ts .Disk .remap_config .AddLines ([
@@ -111,7 +129,20 @@ def _configure_client_with_slow_response(self, tr) -> 'Test.Process':
111129 tr .MakeCurlCommand (f"-v --fail -s -p -x 127.0.0.1:{ self ._ts .Variables .port } 'http://foo.com/delay/2'" , p = p )
112130 return p
113131
114- def run (self ) -> None :
132+ def _test_metrics (self , blocked ) -> None :
133+ """Use traffic_ctl to test metrics."""
134+ tr = Test .AddTestRun ("Check connection metrics" )
135+ tr .Processes .Default .Command = 'traffic_ctl metric match per_server'
136+ tr .Processes .Default .ReturnCode = 0
137+ tr .Processes .Default .Env = self ._ts .Env
138+ tr .Processes .Default .Streams .All = Testers .ContainsExpression (
139+ f'per_server.total_connection.www.this.origin.com.127.0.0.1:{ self ._server .Variables .Port } 5' ,
140+ 'incorrect statistic return, or possible error.' )
141+ tr .Processes .Default .Streams .All = Testers .ContainsExpression (
142+ f'per_server.blocked_connection.www.this.origin.com.127.0.0.1:{ self ._server .Variables .Port } { blocked } ' ,
143+ 'incorrect statistic return, or possible error.' )
144+
145+ def run (self , blocked , gold_file ) -> None :
115146 """Verify per_server.connection.max with CONNECT traffic."""
116147 tr = Test .AddTestRun ()
117148 tr .Processes .Default .StartBefore (self ._dns )
@@ -134,10 +165,13 @@ def run(self) -> None:
134165 f"--next -v --fail -s -p -x 127.0.0.1:{ self ._ts .Variables .port } 'http://foo.com/get'" )
135166 # Curl will have a 22 exit code if it receives a 5XX response (and we
136167 # expect a 503).
137- tr .Processes .Default .ReturnCode = 22
138- tr .Processes .Default .Streams .stderr = "gold/two_503_congested.gold"
168+ tr .Processes .Default .ReturnCode = 22 if blocked else 0
169+ tr .Processes .Default .Streams .stderr = gold_file
139170 tr .Processes .Default .TimeOut = 3
140171
172+ self ._test_metrics (blocked )
173+
141174
142175PerServerConnectionMaxTest ().run ()
143- ConnectMethodTest ().run ()
176+ ConnectMethodTest (3 ).run (blocked = 2 , gold_file = "gold/two_503_congested.gold" )
177+ ConnectMethodTest (0 ).run (blocked = 0 , gold_file = "gold/two_200_ok.gold" )
0 commit comments