-
Notifications
You must be signed in to change notification settings - Fork 875
Add origin server tcp_info logging #13667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
|
|
||
| #include "iocore/net/NetVCOptions.h" | ||
| #include "iocore/net/ProxyProtocol.h" | ||
| #include "iocore/net/TcpInfoSnapshot.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <string_view> | ||
|
|
@@ -381,6 +382,21 @@ class NetVConnection : public VConnection, public PluginUserArgs<TS_USER_ARGS_VC | |
| /** Set the MPTCP state for this connection */ | ||
| virtual void set_mptcp_state() = 0; | ||
|
|
||
| /** Read @c TCP_INFO from the underlying socket. | ||
| * | ||
| * @param info Filled in only when this returns @c true. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| * @return @c true if the kernel supplied the information. | ||
| * | ||
| * The default reports no information, which covers every connection that is | ||
| * not carried over TCP. Call this while the connection is still open; the | ||
| * caller keeps the copy it needs. | ||
| */ | ||
| virtual bool | ||
| get_tcp_info(TcpInfoSnapshot & /* info */) const | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // for InkAPI | ||
| bool | ||
| get_is_internal_request() const | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** @file | ||
|
|
||
| A snapshot of the TCP_INFO fields that ATS reports. | ||
|
|
||
| @section license License | ||
|
|
||
| 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| /** The subset of @c TCP_INFO that ATS reports. | ||
| * | ||
| * Sampling a connection copies these out of the kernel, so the values stay | ||
| * available after the connection itself is gone. The kernel smooths both times | ||
| * over the life of the connection, so they describe the path rather than any | ||
| * single segment. | ||
| * | ||
| * This lives in its own header so that consumers which only report the values, | ||
| * such as logging, do not have to include the network stack. | ||
| */ | ||
| struct TcpInfoSnapshot { | ||
| int64_t rtt = 0; ///< Smoothed round trip time, microseconds. | ||
| int64_t rttvar = 0; ///< Round trip time variance, microseconds. | ||
| int64_t retrans = 0; ///< Segments retransmitted since connection open, up to sampling time. | ||
| int64_t snd_cwnd = 0; ///< Send congestion window: segments on Linux, bytes on FreeBSD. | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2139,6 +2139,19 @@ HttpSM::state_read_server_response_header(int event, void *data) | |
| ATS_PROBE1(milestone_server_read_header_done, sm_id); | ||
| milestones[TS_MILESTONE_SERVER_READ_HEADER_DONE] = ink_get_hrtime(); | ||
|
|
||
| // Sample while this transaction still owns the origin connection. By log time, | ||
| // the connection may have been closed or released for reuse. | ||
| if (state == ParseResult::DONE && t_state.http_config_param->log_server_tcp_info && Log::transaction_logging_enabled() && | ||
| t_state.api_info.logging_enabled) { | ||
| NetVConnection *server_vc = server_txn->get_netvc(); | ||
| if (server_vc != nullptr) { | ||
| TcpInfoSnapshot info; | ||
| if (server_vc->get_tcp_info(info)) { | ||
| server_tcp_info = info; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Any other events to the end | ||
| if (server_entry->vc_type == HttpVC_t::SERVER_VC) { | ||
| server_entry->vc_read_handler = &HttpSM::tunnel_handler; | ||
|
|
@@ -5650,6 +5663,9 @@ HttpSM::open_prewarmed_connection() | |
| void | ||
| HttpSM::do_http_server_open(bool raw, bool only_direct) | ||
| { | ||
| // A failed new attempt must not report a previous origin's TCP_INFO. | ||
| server_tcp_info.reset(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Clear the sample when following a redirect to a cached response The reset points miss an internally followed redirect whose target is already fresh in cache. With number_of_redirections enabled and redirect_use_orig_cache_key=0, an origin 302 populates server_tcp_info and do_redirect() logs that response, then redirect_request() reuses the same HttpSM. HandleRequest() can proceed directly to CACHE_LOOKUP and serve the target without DNS_LOOKUP, do_http_server_open(), or setup_server_read_response_header(), so the final cache-hit log incorrectly repeats the redirect origin's srtt/srtv/sret/scwn instead of -1. Please clear the snapshot when beginning the redirected request, after logging the redirect response, and add a replay case that primes the target in cache before following an origin redirect to it. |
||
|
|
||
| int ip_family = t_state.current.server->dst_addr.sa.sa_family; | ||
| auto fam_name = ats_ip_family_name(ip_family); | ||
| SMDbg(dbg_ctl_http_track, "[%.*s]", static_cast<int>(fam_name.size()), fam_name.data()); | ||
|
|
@@ -7098,6 +7114,7 @@ HttpSM::setup_server_read_response_header() | |
| http_parser_clear(&http_parser); | ||
| server_response_hdr_bytes = 0; | ||
| milestones[TS_MILESTONE_SERVER_READ_HEADER_DONE] = 0; | ||
| server_tcp_info.reset(); | ||
|
|
||
| // The tunnel from OS to UA is now setup. Ready to read the response | ||
| server_entry->read_vio = server_txn->do_io_read(this, INT64_MAX, server_txn->get_remote_reader()->mbuf); | ||
|
|
@@ -8304,6 +8321,9 @@ HttpSM::set_next_state() | |
| } | ||
|
|
||
| case HttpTransact::StateMachineAction_t::DNS_LOOKUP: { | ||
| // A retry can fail during resolution, before opening its connection. | ||
| server_tcp_info.reset(); | ||
|
|
||
| if (sockaddr const *addr; t_state.http_config_param->use_client_target_addr == 2 && // no CTA verification | ||
| !t_state.url_remap_success && // wasn't remapped | ||
| t_state.parent_result.result != ParentResultType::SPECIFIED && // no parent. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the sample rate? Maybe I'm missing it, but I don't see the rate explained here.