Skip to content

Commit fc3f12e

Browse files
authored
HttpConnectionCount move to iocore/net (#10696)
* HttpConnectionCount move to iocore/net This moves HttpConnectionCount to iocore/net from proxy/http in anticipation to using its functionality on the client accept connection side. While doing so, this also renames HttpConnectionCount to ConnectionTracker because it is no longer HTTP transaction specific. * Build updates for test_net Moving ConnectionTracker to iocore/net induced linking behavior differences that required these changes to fix test_net. * Fix tls_bridge to use Regex from tscore tls_bridge had previously linked to tscore, but had copied in its own version of Regex. This removes the duplicated code and logic which, with these changes, caused duplicate definitions errors.
1 parent 1157fc4 commit fc3f12e

25 files changed

+202
-488
lines changed
Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,21 @@
4040
#include "swoc/bwf_fwd.h"
4141
#include "swoc/TextView.h"
4242
#include <tscore/MgmtDefs.h>
43-
#include "proxy/http/HttpProxyAPIEnums.h"
44-
#include "proxy/Show.h"
43+
#include "iocore/net/SessionSharingAPIEnums.h"
4544

4645
/**
4746
* Singleton class to keep track of the number of outbound connections.
4847
*
4948
* Outbound connections are divided in to equivalence classes (called "groups" here) based on the
5049
* session matching setting. Tracking data is stored for each group.
5150
*/
52-
class OutboundConnTrack
51+
class ConnectionTracker
5352
{
54-
using self_type = OutboundConnTrack; ///< Self reference type.
53+
using self_type = ConnectionTracker; ///< Self reference type.
5554

5655
public:
5756
// Non-copyable.
58-
OutboundConnTrack(const self_type &) = delete;
57+
ConnectionTracker(const self_type &) = delete;
5958
self_type &operator=(const self_type &) = delete;
6059

6160
/// Definition of an upstream server group equivalence class.
@@ -71,23 +70,23 @@ class OutboundConnTrack
7170

7271
/// Per transaction configuration values.
7372
struct TxnConfig {
74-
int max{0}; ///< Maximum concurrent connections.
75-
int min{0}; ///< Minimum keepalive connections.
76-
MatchType match{MATCH_IP}; ///< Match type.
73+
int server_max{0}; ///< Maximum concurrent server connections.
74+
int server_min{0}; ///< Minimum keepalive server connections.
75+
MatchType server_match{MATCH_IP}; ///< Server match type.
7776
};
7877

7978
/** Static configuration values. */
8079
struct GlobalConfig {
81-
std::chrono::seconds alert_delay{60}; ///< Alert delay in seconds.
80+
std::chrono::seconds server_alert_delay{60}; ///< Alert delay in seconds.
8281
};
8382

8483
// The names of the configuration values.
8584
// Unfortunately these are not used in RecordsConfig.cc so that must be made consistent by hand.
8685
// Note: These need to be @c constexpr or there are static initialization ordering risks.
87-
static constexpr std::string_view CONFIG_VAR_MAX{"proxy.config.http.per_server.connection.max"};
88-
static constexpr std::string_view CONFIG_VAR_MIN{"proxy.config.http.per_server.connection.min"};
89-
static constexpr std::string_view CONFIG_VAR_MATCH{"proxy.config.http.per_server.connection.match"};
90-
static constexpr std::string_view CONFIG_VAR_ALERT_DELAY{"proxy.config.http.per_server.connection.alert_delay"};
86+
static constexpr std::string_view CONFIG_SERVER_VAR_MAX{"proxy.config.http.per_server.connection.max"};
87+
static constexpr std::string_view CONFIG_SERVER_VAR_MIN{"proxy.config.http.per_server.connection.min"};
88+
static constexpr std::string_view CONFIG_SERVER_VAR_MATCH{"proxy.config.http.per_server.connection.match"};
89+
static constexpr std::string_view CONFIG_SERVER_VAR_ALERT_DELAY{"proxy.config.http.per_server.connection.alert_delay"};
9190

9291
/// A record for the outbound connection count.
9392
/// These are stored per outbound session equivalence class, as determined by the session matching.
@@ -118,7 +117,7 @@ class OutboundConnTrack
118117
// Counting data.
119118
std::atomic<int> _count{0}; ///< Number of outbound connections.
120119
std::atomic<int> _count_max{0}; ///< largest observed @a count value.
121-
std::atomic<int> _blocked{0}; ///< Number of outbound connections blocked since last alert.
120+
std::atomic<int> _blocked{0}; ///< Number of connections blocked since last alert.
122121
std::atomic<int> _in_queue{0}; ///< # of connections queued, waiting for a connection.
123122
std::atomic<Ticker> _last_alert{0}; ///< Absolute time of the last alert.
124123

@@ -130,6 +129,7 @@ class OutboundConnTrack
130129
* Construct from @c Key because the use cases do a table lookup first so the @c Key is already constructed.
131130
* @param key A populated @c Key structure - values are copied to the @c Group.
132131
* @param fqdn The full FQDN.
132+
* @param min_keep_alive The minimum number of origin keep alive connections to maintain.
133133
*/
134134
Group(Key const &key, std::string_view fqdn, int min_keep_alive);
135135
/// Key equality checker.
@@ -182,22 +182,22 @@ class OutboundConnTrack
182182

183183
/** Generate a Warning that a connection was blocked.
184184
*
185-
* @param config Transaction local configuration.
186-
* @param sm_id State machine ID to display in Warning.
185+
* @param max_connections The maximum configured number of connections for the group.
186+
* @param sm_id ID to display in Warning.
187187
* @param count Count value to display in Warning.
188188
* @param addr IP address of the upstream.
189189
* @param debug_tag Tag to use for the debug message. If no debug message should be generated set this to @c nullptr.
190190
*/
191-
void Warn_Blocked(const TxnConfig *config, int64_t sm_id, int count, const sockaddr *addr, const char *debug_tag = nullptr);
191+
void Warn_Blocked(int max_connections, int64_t id, int count, const sockaddr *addr, const char *debug_tag = nullptr);
192192
};
193193

194-
/** Get or create the @c Group for the specified session properties.
194+
/** Get or create the @c Group for the specified outbound session properties.
195195
* @param txn_cnf The transaction local configuration.
196196
* @param fqdn The fully qualified domain name of the upstream.
197197
* @param addr The IP address of the upstream.
198198
* @return A @c Group for the arguments, existing if possible and created if not.
199199
*/
200-
static TxnState obtain(TxnConfig const &txn_cnf, std::string_view fqdn, const IpEndpoint &addr);
200+
static TxnState obtain_outbound(TxnConfig const &txn_cnf, std::string_view fqdn, IpEndpoint const &addr);
201201

202202
/** Get the currently existing groups.
203203
* @param [out] groups parameter - pointers to the groups are pushed in to this container.
@@ -244,9 +244,9 @@ class OutboundConnTrack
244244
static void Warning_Bad_Match_Type(std::string_view tag);
245245

246246
// Converters for overridable values for use in the TS API.
247-
static const MgmtConverter MIN_CONV;
248-
static const MgmtConverter MAX_CONV;
249-
static const MgmtConverter MATCH_CONV;
247+
static const MgmtConverter MIN_SERVER_CONV;
248+
static const MgmtConverter MAX_SERVER_CONV;
249+
static const MgmtConverter SERVER_MATCH_CONV;
250250

251251
protected:
252252
static GlobalConfig *_global_config; ///< Global configuration data.
@@ -278,13 +278,13 @@ class OutboundConnTrack
278278
Imp &instance();
279279
};
280280

281-
inline OutboundConnTrack::Imp &
282-
OutboundConnTrack::instance()
281+
inline ConnectionTracker::Imp &
282+
ConnectionTracker::instance()
283283
{
284284
return _imp;
285285
}
286286

287-
inline OutboundConnTrack::Group::Group(Key const &key, std::string_view fqdn, int min_keep_alive)
287+
inline ConnectionTracker::Group::Group(Key const &key, std::string_view fqdn, int min_keep_alive)
288288
: _hash(key._hash), _match_type(key._match_type), min_keep_alive_conns(min_keep_alive), _key{_addr, _hash, _match_type}
289289
{
290290
// store the host name if relevant.
@@ -300,7 +300,7 @@ inline OutboundConnTrack::Group::Group(Key const &key, std::string_view fqdn, in
300300
}
301301

302302
inline uint64_t
303-
OutboundConnTrack::Group::hash(const Key &key)
303+
ConnectionTracker::Group::hash(const Key &key)
304304
{
305305
switch (key._match_type) {
306306
case MATCH_IP:
@@ -317,43 +317,43 @@ OutboundConnTrack::Group::hash(const Key &key)
317317
}
318318

319319
inline bool
320-
OutboundConnTrack::TxnState::is_active()
320+
ConnectionTracker::TxnState::is_active()
321321
{
322322
return nullptr != _g;
323323
}
324324

325325
inline int
326-
OutboundConnTrack::TxnState::reserve()
326+
ConnectionTracker::TxnState::reserve()
327327
{
328328
_reserved_p = true;
329329
return ++_g->_count;
330330
}
331331

332332
inline void
333-
OutboundConnTrack::TxnState::release()
333+
ConnectionTracker::TxnState::release()
334334
{
335335
if (_reserved_p) {
336336
_reserved_p = false;
337337
--_g->_count;
338338
}
339339
}
340340

341-
inline OutboundConnTrack::Group *
342-
OutboundConnTrack::TxnState::drop()
341+
inline ConnectionTracker::Group *
342+
ConnectionTracker::TxnState::drop()
343343
{
344344
_reserved_p = false;
345345
return _g;
346346
}
347347

348348
inline int
349-
OutboundConnTrack::TxnState::enqueue()
349+
ConnectionTracker::TxnState::enqueue()
350350
{
351351
_queued_p = true;
352352
return ++_g->_in_queue;
353353
}
354354

355355
inline void
356-
OutboundConnTrack::TxnState::dequeue()
356+
ConnectionTracker::TxnState::dequeue()
357357
{
358358
if (_queued_p) {
359359
_queued_p = false;
@@ -362,7 +362,7 @@ OutboundConnTrack::TxnState::dequeue()
362362
}
363363

364364
inline void
365-
OutboundConnTrack::TxnState::clear()
365+
ConnectionTracker::TxnState::clear()
366366
{
367367
if (_g) {
368368
this->dequeue();
@@ -372,7 +372,7 @@ OutboundConnTrack::TxnState::clear()
372372
}
373373

374374
inline void
375-
OutboundConnTrack::TxnState::update_max_count(int count)
375+
ConnectionTracker::TxnState::update_max_count(int count)
376376
{
377377
auto cmax = _g->_count_max.load();
378378
if (count > cmax) {
@@ -381,48 +381,46 @@ OutboundConnTrack::TxnState::update_max_count(int count)
381381
}
382382

383383
inline void
384-
OutboundConnTrack::TxnState::blocked()
384+
ConnectionTracker::TxnState::blocked()
385385
{
386386
++_g->_blocked;
387387
}
388388

389389
/* === Linkage === */
390390
inline auto
391-
OutboundConnTrack::Linkage::next_ptr(value_type *value) -> value_type *&
391+
ConnectionTracker::Linkage::next_ptr(value_type *value) -> value_type *&
392392
{
393393
return value->_next;
394394
}
395395

396396
inline auto
397-
OutboundConnTrack::Linkage::prev_ptr(value_type *value) -> value_type *&
397+
ConnectionTracker::Linkage::prev_ptr(value_type *value) -> value_type *&
398398
{
399399
return value->_prev;
400400
}
401401

402402
inline uint64_t
403-
OutboundConnTrack::Linkage::hash_of(key_type key)
403+
ConnectionTracker::Linkage::hash_of(key_type key)
404404
{
405405
return Group::hash(key);
406406
}
407407

408408
inline auto
409-
OutboundConnTrack::Linkage::key_of(value_type *value) -> key_type
409+
ConnectionTracker::Linkage::key_of(value_type *value) -> key_type
410410
{
411411
return value->_key;
412412
}
413413

414414
inline bool
415-
OutboundConnTrack::Linkage::equal(key_type lhs, key_type rhs)
415+
ConnectionTracker::Linkage::equal(key_type lhs, key_type rhs)
416416
{
417417
return Group::equal(lhs, rhs);
418418
}
419419
/* === */
420420

421-
Action *register_ShowConnectionCount(Continuation *, HTTPHdr *);
422-
423421
namespace swoc
424422
{
425-
BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, OutboundConnTrack::MatchType type);
426-
BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, OutboundConnTrack::Group::Key const &key);
427-
BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, OutboundConnTrack::Group const &g);
423+
BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, ConnectionTracker::MatchType type);
424+
BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, ConnectionTracker::Group::Key const &key);
425+
BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, ConnectionTracker::Group const &g);
428426
} // namespace swoc
File renamed without changes.

include/proxy/PoolableSession.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#pragma once
2525

26+
#include "iocore/net/ConnectionTracker.h"
2627
#include "proxy/ProxySession.h"
2728

2829
class PoolableSession : public ProxySession
@@ -74,7 +75,7 @@ class PoolableSession : public ProxySession
7475
TSServerSessionSharingMatchMask sharing_match = TS_SERVER_SESSION_SHARING_MATCH_MASK_NONE;
7576
TSServerSessionSharingPoolType sharing_pool = TS_SERVER_SESSION_SHARING_POOL_GLOBAL;
7677

77-
void enable_outbound_connection_tracking(OutboundConnTrack::Group *group);
78+
void enable_outbound_connection_tracking(ConnectionTracker::Group *group);
7879
void release_outbound_connection_tracking();
7980

8081
void attach_hostname(const char *hostname);
@@ -89,7 +90,7 @@ class PoolableSession : public ProxySession
8990

9091
// Keep track of connection limiting and a pointer to the
9192
// singleton that keeps track of the connection counts.
92-
OutboundConnTrack::Group *conn_track_group = nullptr;
93+
ConnectionTracker::Group *conn_track_group = nullptr;
9394

9495
virtual IOBufferReader *get_remote_reader() = 0;
9596

@@ -209,7 +210,7 @@ PoolableSession::FQDNLinkage::equal(CryptoHash const &lhs, CryptoHash const &rhs
209210
}
210211

211212
inline void
212-
PoolableSession::enable_outbound_connection_tracking(OutboundConnTrack::Group *group)
213+
PoolableSession::enable_outbound_connection_tracking(ConnectionTracker::Group *group)
213214
{
214215
ink_assert(nullptr == conn_track_group);
215216
conn_track_group = group;

include/proxy/http/Http1ServerSession.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
#pragma once
3434

35-
#include "proxy/http/HttpConnectionCount.h"
36-
#include "proxy/http/HttpProxyAPIEnums.h"
35+
#include "iocore/net/ConnectionTracker.h"
36+
#include "iocore/net/SessionSharingAPIEnums.h"
3737
#include "proxy/PoolableSession.h"
3838
#include "proxy/http/Http1ServerTransaction.h"
3939

include/proxy/http/HttpConfig.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
#include "tscore/ink_resolver.h"
4949
#include "tscore/Regex.h"
5050
#include "tscpp/util/ts_bw.h"
51-
#include "proxy/http/HttpProxyAPIEnums.h"
5251
#include "iocore/eventsystem/ConfigProcessor.h"
52+
#include "iocore/net/ConnectionTracker.h"
53+
#include "iocore/net/SessionSharingAPIEnums.h"
5354
#include "records/RecProcess.h"
54-
#include "proxy/http/HttpConnectionCount.h"
5555
#include "tscpp/util/ts_ip.h"
5656
#include "api/Metrics.h"
5757

@@ -638,7 +638,7 @@ struct OverridableHttpConfigParams {
638638
MgmtInt default_buffer_water_mark = 32768;
639639
MgmtInt slow_log_threshold = 0;
640640

641-
OutboundConnTrack::TxnConfig outbound_conntrack;
641+
ConnectionTracker::TxnConfig connection_tracker_config;
642642

643643
MgmtInt plugin_vc_default_buffer_index = BUFFER_SIZE_INDEX_32K;
644644
MgmtInt plugin_vc_default_buffer_water_mark = DEFAULT_PLUGIN_VC_BUFFER_WATER_MARK;
@@ -771,7 +771,7 @@ struct HttpConfigParams : public ConfigInfo {
771771

772772
MgmtByte server_session_sharing_pool = TS_SERVER_SESSION_SHARING_POOL_THREAD;
773773

774-
OutboundConnTrack::GlobalConfig global_outbound_conntrack;
774+
ConnectionTracker::GlobalConfig global_connection_tracker_config;
775775

776776
// bitset to hold the status codes that will BE cached with negative caching enabled
777777
HttpStatusBitset negative_caching_list;

include/proxy/http/HttpTransact.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ using ink_time_t = time_t;
7676
struct HttpConfigParams;
7777
class HttpSM;
7878

79+
#include "iocore/net/ConnectionTracker.h"
7980
#include "tscore/InkErrno.h"
80-
#include "proxy/http/HttpConnectionCount.h"
8181

8282
#define UNKNOWN_INTERNAL_ERROR (INK_START_ERRNO - 1)
8383

@@ -717,7 +717,7 @@ class HttpTransact
717717
CacheLookupInfo cache_info;
718718
ResolveInfo dns_info;
719719
RedirectInfo redirect_info;
720-
OutboundConnTrack::TxnState outbound_conn_track_state;
720+
ConnectionTracker::TxnState outbound_conn_track_state;
721721
ConnectionAttributes client_info;
722722
ConnectionAttributes parent_info;
723723
ConnectionAttributes server_info;

include/shared/overridable_txn_vars.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
#pragma once
2525

2626
#include <unordered_map>
27+
#include "iocore/net/ConnectionTracker.h"
2728
#include "proxy/hdrs/HTTP.h"
28-
#include "proxy/http/HttpConnectionCount.h"
2929

3030
namespace ts
3131
{

plugins/experimental/tls_bridge/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
#
1616
#######################
1717

18-
add_atsplugin(tls_bridge regex.cc tls_bridge.cc)
18+
add_atsplugin(tls_bridge tls_bridge.cc)
1919

2020
target_link_libraries(tls_bridge PRIVATE libswoc ts::tscpputil)

0 commit comments

Comments
 (0)