Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/proxy/ProxySession.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class ProxySession : public VConnection, public PluginUserArgs<TS_USER_ARGS_SSN>
// the new_vc may be an SSLNetVConnection object.
void _handle_if_ssl(NetVConnection *new_vc);

/// Update the client connection metric for the remote address family.
void _increment_total_client_connections_stat(NetVConnection *new_vc);

NetVConnection *_vc = nullptr; // The netvc associated with the concrete session class

private:
Expand Down
18 changes: 18 additions & 0 deletions src/proxy/ProxySession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ ProxySession::~ProxySession()
this->_ssl.reset();
}

void
ProxySession::_increment_total_client_connections_stat(NetVConnection *new_vc)
{
switch (new_vc->get_remote_addr()->sa_family) {
case AF_INET:
Metrics::Counter::increment(http_rsb.total_client_connections_ipv4);
break;
case AF_INET6:
Metrics::Counter::increment(http_rsb.total_client_connections_ipv6);
break;
case AF_UNIX:
Metrics::Counter::increment(http_rsb.total_client_connections_uds);
break;
default:
break;
}
}

void
ProxySession::set_session_active()
{
Expand Down
21 changes: 1 addition & 20 deletions src/proxy/http/Http1ClientSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,7 @@ Http1ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB
/* inbound requests stat should be incremented here, not after the
* header has been read */
Metrics::Counter::increment(http_rsb.total_incoming_connections);

// check what type of socket address we just accepted
// by looking at the address family value of sockaddr_storage
// and logging to stat system
switch (new_vc->get_remote_addr()->sa_family) {
case AF_INET:
Metrics::Counter::increment(http_rsb.total_client_connections_ipv4);
break;
case AF_INET6:
Metrics::Counter::increment(http_rsb.total_client_connections_ipv6);
break;
case AF_UNIX:
Metrics::Counter::increment(http_rsb.total_client_connections_uds);
break;
default:
// don't do anything if the address family is not ipv4, ipv6, or unix domain socket
// (there are many other address families in <sys/socket.h>
// but we don't have a need to report on all the others today)
break;
}
this->_increment_total_client_connections_stat(new_vc);

#ifdef USE_HTTP_DEBUG_LISTS
ink_mutex_acquire(&debug_cs_list_mutex);
Expand Down
1 change: 1 addition & 0 deletions src/proxy/http2/Http2ClientSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, MIOBuffer *iobuf, IOB
ink_assert(new_vc->mutex->thread_holding == this_ethread());
Metrics::Gauge::increment(http2_rsb.current_client_session_count);
Metrics::Counter::increment(http2_rsb.total_client_connection_count);
this->_increment_total_client_connections_stat(new_vc);
this->_milestones.mark(Http2SsnMilestone::OPEN);

// Unique client session identifier.
Expand Down
1 change: 1 addition & 0 deletions src/proxy/http3/Http3Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void
HQSession::new_connection(NetVConnection *new_vc, MIOBuffer * /* iobuf ATS_UNUSED */, IOBufferReader * /* reader ATS_UNUSED */)
{
this->con_id = new_vc->get_service<QUICSupport>()->get_quic_connection()->connection_id();
this->_increment_total_client_connections_stat(new_vc);
this->_handle_if_ssl(new_vc);

do_api_callout(TS_HTTP_SSN_START_HOOK);
Expand Down
20 changes: 20 additions & 0 deletions tests/gold_tests/h2/http2_client_connection_metric.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'''Verify that HTTP/2 client connections update the IP version metrics.'''
# 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.

Test.Summary = __doc__

Test.ATSReplayTest(replay_file="replay/http2_client_connection_metric.replay.yaml")
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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.

meta:
version: "1.0"

autest:
description: 'Verify HTTP/2 connections update the client IP version metrics'

server:
name: 'server'

client:
name: 'client'

ats:
name: 'ts'
process_config:
enable_cache: false
enable_tls: true

remap_config:
- from: 'https://http2-metrics.test/'
to: 'http://127.0.0.1:{SERVER_HTTP_PORT}/'

metric_checks:
- metric: 'proxy.process.http2.total_client_connections'
value: 1
- metric: 'proxy.process.http.total_client_connections_ipv4'
value: 1
- metric: 'proxy.process.http.total_client_connections_ipv6'
value: 0

sessions:
- protocol:
stack: http2
tls:
sni: http2-metrics.test
transactions:
- client-request:
headers:
fields:
- [':method', GET]
- [':scheme', https]
- [':authority', http2-metrics.test]
- [':path', /]
- [Content-Length, 0]
- [uuid, http2-client-connection-metric]

proxy-request:
headers:
fields:
- [uuid, {value: http2-client-connection-metric, as: equal}]

server-response:
status: 200
reason: OK
headers:
fields:
- [Content-Length, 0]

proxy-response:
status: 200
2 changes: 1 addition & 1 deletion tests/gold_tests/tls/gold/tls-tunnel-metrics.gold
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
proxy.process.http.total_incoming_connections 14
proxy.process.http.total_client_connections 14
proxy.process.http.total_client_connections_ipv4 14
proxy.process.http.total_client_connections_ipv4 16
proxy.process.http.total_client_connections_ipv6 0
proxy.process.http.total_server_connections 0
proxy.process.http2.total_client_connections 2
Expand Down