You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2022/02/17 00:22:48 UTC

[trafficserver] 01/02: Adds two overridable config variables to control parent mark downs. (#8595)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 1dada123bcca0bfbefb9a81560a4db99afe29b24
Author: John J. Rushford <jr...@apache.org>
AuthorDate: Tue Jan 18 10:30:17 2022 -0700

    Adds two overridable config variables to control parent mark downs. (#8595)
    
    These configs may be overridden by the header_rewrite plugin on a
    per remap basis.
    
    - proxy.config.http.parent_proxy.enable_parent_timeout_markdowns is
      used to enable parent markdowns when an inactivity timeout triggers
      on a parent proxy.  The default is disabled or '0'.
    
    - proxy.config.http.parent_proxy.disable_parent_markdowns  is used to
      disable all parent proxy markdowns.  The default is disabled or '0'.
    
    (cherry picked from commit 427c42fc7e94991bcea47198780643a13d4b85d8)
---
 doc/admin-guide/files/records.config.en.rst | 26 ++++++++++++++++++++++++++
 include/ts/apidefs.h.in                     |  2 ++
 mgmt/RecordsConfig.cc                       |  4 ++++
 plugins/lua/ts_lua_http_config.c            |  4 ++++
 proxy/http/HttpConfig.cc                    | 25 +++++++++++++++----------
 proxy/http/HttpConfig.h                     | 12 +++++++-----
 proxy/http/HttpTransact.cc                  | 16 ++++++++++++++--
 src/shared/overridable_txn_vars.cc          |  6 +++++-
 src/traffic_server/InkAPI.cc                |  6 ++++++
 src/traffic_server/InkAPITest.cc            |  4 +++-
 10 files changed, 86 insertions(+), 19 deletions(-)

diff --git a/doc/admin-guide/files/records.config.en.rst b/doc/admin-guide/files/records.config.en.rst
index b3dab3e..de01a6b 100644
--- a/doc/admin-guide/files/records.config.en.rst
+++ b/doc/admin-guide/files/records.config.en.rst
@@ -1347,6 +1347,32 @@ Parent Proxy Configuration
    ``2`` Mark the host down. This is the default.
    ===== ======================================================================
 
+.. ts:cv:: CONFIG proxy.config.http.parent_proxy.enable_parent_timeout_markdowns INT 0
+   :reloadable:
+   :overridable:
+
+   Enables (``1``) or disables (``0``) parent proxy mark downs due to inactivity
+   timeouts.  By default parent proxies are not marked down due to inactivity
+   timeouts, the transaction will retry using another parent instead.  The
+   default for this configuration keeps this behavior and is disabled (``0``).
+   This setting is overridable using one of the two plugins ``header_rewrite``
+   or ``conf_remap`` to enable inactivity timeout markdowns and should be done
+   so rather than enabling this globally. This setting should not be used in
+   conjunction with ``proxy.config.http.parent_proxy.disable_parent_markdowns``
+
+.. ts:cv:: CONFIG proxy.config.http.parent_proxy.disable_parent_markdowns INT 0
+   :reloadable:
+   :overridable:
+
+   Enables (``1``) or disables (``0``) parent proxy markdowns.  This is useful
+   if parent entries in a parent.config line are VIP's and one doesn't wish
+   to mark down a VIP which may have several origin or parent proxies behind
+   the load balancer.  This setting is overridable using one of the
+   ``header_rewrite`` or the ``conf_remap`` plugins to override the default
+   setting and this method should be used rather than disabling markdowns
+   globally.  This setting should not be used in conjunction with
+   ``proxy.config.http.parent_proxy.enable_parent_timeout_markdowns``
+
 HTTP Connection Timeouts
 ========================
 
diff --git a/include/ts/apidefs.h.in b/include/ts/apidefs.h.in
index bf5b314..e3ebe46 100644
--- a/include/ts/apidefs.h.in
+++ b/include/ts/apidefs.h.in
@@ -867,6 +867,8 @@ typedef enum {
   TS_CONFIG_PLUGIN_VC_DEFAULT_BUFFER_WATER_MARK,
   TS_CONFIG_NET_SOCK_NOTSENT_LOWAT,
   TS_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE,
+  TS_CONFIG_HTTP_ENABLE_PARENT_TIMEOUT_MARKDOWNS,
+  TS_CONFIG_HTTP_DISABLE_PARENT_MARKDOWNS,
   TS_CONFIG_LAST_ENTRY
 } TSOverridableConfigKey;
 
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index f78cde7..7153690 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -451,6 +451,10 @@ static const RecordElement RecordsConfig[] =
   ,
   {RECT_CONFIG, "proxy.config.http.parent_proxy.self_detect", RECD_INT, "2", RECU_DYNAMIC, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.http.parent_proxy.enable_parent_timeout_markdowns", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.http.parent_proxy.disable_parent_markdowns", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
+  ,
   {RECT_CONFIG, "proxy.config.http.forward.proxy_auth_to_parent", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
   ,
 
diff --git a/plugins/lua/ts_lua_http_config.c b/plugins/lua/ts_lua_http_config.c
index 310b068..9d5463a 100644
--- a/plugins/lua/ts_lua_http_config.c
+++ b/plugins/lua/ts_lua_http_config.c
@@ -143,6 +143,8 @@ typedef enum {
   TS_LUA_CONFIG_PLUGIN_VC_DEFAULT_BUFFER_WATER_MARK           = TS_CONFIG_PLUGIN_VC_DEFAULT_BUFFER_WATER_MARK,
   TS_LUA_CONFIG_NET_SOCK_NOTSENT_LOWAT                        = TS_CONFIG_NET_SOCK_NOTSENT_LOWAT,
   TS_LUA_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE        = TS_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE,
+  TS_LUA_CONFIG_ENABLE_PARENT_TIMEOUT_MARKDOWNS               = TS_CONFIG_HTTP_ENABLE_PARENT_TIMEOUT_MARKDOWNS,
+  TS_LUA_CONFIG_DISABLE_PARENT_MARKDOWNS                      = TS_CONFIG_HTTP_DISABLE_PARENT_MARKDOWNS,
   TS_LUA_CONFIG_LAST_ENTRY                                    = TS_CONFIG_LAST_ENTRY,
 } TSLuaOverridableConfigKey;
 
@@ -278,6 +280,8 @@ ts_lua_var_item ts_lua_http_config_vars[] = {
   TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_PLUGIN_VC_DEFAULT_BUFFER_WATER_MARK),
   TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_NET_SOCK_NOTSENT_LOWAT),
   TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE),
+  TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_ENABLE_PARENT_TIMEOUT_MARKDOWNS),
+  TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_DISABLE_PARENT_MARKDOWNS),
   TS_LUA_MAKE_VAR_ITEM(TS_LUA_CONFIG_LAST_ENTRY),
 };
 
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index 07ed442..c1d8c46 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -1250,6 +1250,9 @@ HttpConfig::startup()
                                     "proxy.config.http.parent_proxy.per_parent_connect_attempts");
   HttpEstablishStaticConfigLongLong(c.oride.parent_connect_timeout, "proxy.config.http.parent_proxy.connect_attempts_timeout");
   HttpEstablishStaticConfigByte(c.oride.parent_failures_update_hostdb, "proxy.config.http.parent_proxy.mark_down_hostdb");
+  HttpEstablishStaticConfigByte(c.oride.enable_parent_timeout_markdowns,
+                                "proxy.config.http.parent_proxy.enable_parent_timeout_markdowns");
+  HttpEstablishStaticConfigByte(c.oride.disable_parent_markdowns, "proxy.config.http.parent_proxy.disable_parent_markdowns");
 
   HttpEstablishStaticConfigLongLong(c.oride.sock_recv_buffer_size_out, "proxy.config.net.sock_recv_buffer_size_out");
   HttpEstablishStaticConfigLongLong(c.oride.sock_send_buffer_size_out, "proxy.config.net.sock_send_buffer_size_out");
@@ -1535,16 +1538,18 @@ HttpConfig::reconfigure()
             "will never redispatch to another server",
             m_master.oride.connect_attempts_rr_retries, params->oride.connect_attempts_max_retries);
   }
-  params->oride.connect_attempts_rr_retries   = m_master.oride.connect_attempts_rr_retries;
-  params->oride.connect_attempts_timeout      = m_master.oride.connect_attempts_timeout;
-  params->oride.connect_dead_policy           = m_master.oride.connect_dead_policy;
-  params->oride.post_connect_attempts_timeout = m_master.oride.post_connect_attempts_timeout;
-  params->oride.parent_connect_attempts       = m_master.oride.parent_connect_attempts;
-  params->oride.parent_retry_time             = m_master.oride.parent_retry_time;
-  params->oride.parent_fail_threshold         = m_master.oride.parent_fail_threshold;
-  params->oride.per_parent_connect_attempts   = m_master.oride.per_parent_connect_attempts;
-  params->oride.parent_connect_timeout        = m_master.oride.parent_connect_timeout;
-  params->oride.parent_failures_update_hostdb = m_master.oride.parent_failures_update_hostdb;
+  params->oride.connect_attempts_rr_retries     = m_master.oride.connect_attempts_rr_retries;
+  params->oride.connect_attempts_timeout        = m_master.oride.connect_attempts_timeout;
+  params->oride.connect_dead_policy             = m_master.oride.connect_dead_policy;
+  params->oride.post_connect_attempts_timeout   = m_master.oride.post_connect_attempts_timeout;
+  params->oride.parent_connect_attempts         = m_master.oride.parent_connect_attempts;
+  params->oride.parent_retry_time               = m_master.oride.parent_retry_time;
+  params->oride.parent_fail_threshold           = m_master.oride.parent_fail_threshold;
+  params->oride.per_parent_connect_attempts     = m_master.oride.per_parent_connect_attempts;
+  params->oride.parent_connect_timeout          = m_master.oride.parent_connect_timeout;
+  params->oride.parent_failures_update_hostdb   = m_master.oride.parent_failures_update_hostdb;
+  params->oride.enable_parent_timeout_markdowns = m_master.oride.enable_parent_timeout_markdowns;
+  params->oride.disable_parent_markdowns        = m_master.oride.disable_parent_markdowns;
 
   params->oride.sock_recv_buffer_size_out = m_master.oride.sock_recv_buffer_size_out;
   params->oride.sock_send_buffer_size_out = m_master.oride.sock_send_buffer_size_out;
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index 2b6ea37..145fffe 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -678,11 +678,13 @@ struct OverridableHttpConfigParams {
   ////////////////////////////////////
   // parent proxy connect attempts //
   ///////////////////////////////////
-  MgmtInt parent_connect_attempts     = 4;
-  MgmtInt parent_retry_time           = 300;
-  MgmtInt parent_fail_threshold       = 10;
-  MgmtInt per_parent_connect_attempts = 2;
-  MgmtInt parent_connect_timeout      = 30;
+  MgmtInt parent_connect_attempts          = 4;
+  MgmtInt parent_retry_time                = 300;
+  MgmtInt parent_fail_threshold            = 10;
+  MgmtInt per_parent_connect_attempts      = 2;
+  MgmtInt parent_connect_timeout           = 30;
+  MgmtByte enable_parent_timeout_markdowns = 0;
+  MgmtByte disable_parent_markdowns        = 0;
 
   MgmtInt down_server_timeout    = 300;
   MgmtInt client_abort_threshold = 1000;
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index b0a794b..f4f51d8 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -214,6 +214,18 @@ markParentDown(HttpTransact::State *s)
   HTTP_INCREMENT_DYN_STAT(http_total_parent_marked_down_count);
   url_mapping *mp = s->url_map.getMapping();
 
+  TxnDebug("http_trans", "sm_id[%" PRId64 "] enable_parent_timeout_markdowns: %d, disable_parent_markdowns: %d",
+           s->state_machine->sm_id, s->txn_conf->enable_parent_timeout_markdowns, s->txn_conf->disable_parent_markdowns);
+
+  if (s->txn_conf->disable_parent_markdowns == 1) {
+    TxnDebug("http_trans", "parent markdowns are disabled for this request");
+    return;
+  }
+
+  if (s->current.state == HttpTransact::INACTIVE_TIMEOUT && s->txn_conf->enable_parent_timeout_markdowns == 0) {
+    return;
+  }
+
   if (s->response_action.handled) {
     // Do nothing. If a plugin handled the response, let it handle markdown.
   } else if (mp && mp->strategy) {
@@ -3727,7 +3739,7 @@ HttpTransact::handle_response_from_parent(State *s)
         // Only mark the parent down if we failed to connect
         //  to the parent otherwise slow origin servers cause
         //  us to mark the parent down
-        if (s->current.state == CONNECTION_ERROR) {
+        if (s->current.state == CONNECTION_ERROR || s->current.state == INACTIVE_TIMEOUT) {
           markParentDown(s);
         }
         // We are done so look for another parent if any
@@ -3738,7 +3750,7 @@ HttpTransact::handle_response_from_parent(State *s)
       //   appropriate
       HTTP_INCREMENT_DYN_STAT(http_total_parent_retries_exhausted_stat);
       TxnDebug("http_trans", "[handle_response_from_parent] Error. No more retries.");
-      if (s->current.state == CONNECTION_ERROR) {
+      if (s->current.state == CONNECTION_ERROR || s->current.state == INACTIVE_TIMEOUT) {
         markParentDown(s);
       }
       s->parent_result.result = PARENT_FAIL;
diff --git a/src/shared/overridable_txn_vars.cc b/src/shared/overridable_txn_vars.cc
index 906de8e..5b6f3db 100644
--- a/src/shared/overridable_txn_vars.cc
+++ b/src/shared/overridable_txn_vars.cc
@@ -168,4 +168,8 @@ const std::unordered_map<std::string_view, std::tuple<const TSOverridableConfigK
      {"proxy.config.plugin.vc.default_buffer_water_mark", {TS_CONFIG_PLUGIN_VC_DEFAULT_BUFFER_WATER_MARK, TS_RECORDDATATYPE_INT}},
      {"proxy.config.net.sock_notsent_lowat", {TS_CONFIG_NET_SOCK_NOTSENT_LOWAT, TS_RECORDDATATYPE_INT}},
      {"proxy.config.body_factory.response_suppression_mode",
-      {TS_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE, TS_RECORDDATATYPE_INT}}});
+      {TS_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE, TS_RECORDDATATYPE_INT}},
+     {"proxy.config.http.parent_proxy.enable_parent_timeout_markdowns",
+      {TS_CONFIG_HTTP_ENABLE_PARENT_TIMEOUT_MARKDOWNS, TS_RECORDDATATYPE_INT}},
+     {"proxy.config.http.parent_proxy.disable_parent_markdowns",
+      {TS_CONFIG_HTTP_DISABLE_PARENT_MARKDOWNS, TS_RECORDDATATYPE_INT}}});
diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc
index da3331e..5ac59e4 100644
--- a/src/traffic_server/InkAPI.cc
+++ b/src/traffic_server/InkAPI.cc
@@ -8979,6 +8979,12 @@ _conf_to_memberp(TSOverridableConfigKey conf, OverridableHttpConfigParams *overr
   case TS_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE:
     ret = _memberp_to_generic(&overridableHttpConfig->response_suppression_mode, conv);
     break;
+  case TS_CONFIG_HTTP_ENABLE_PARENT_TIMEOUT_MARKDOWNS:
+    ret = _memberp_to_generic(&overridableHttpConfig->enable_parent_timeout_markdowns, conv);
+    break;
+  case TS_CONFIG_HTTP_DISABLE_PARENT_MARKDOWNS:
+    ret = _memberp_to_generic(&overridableHttpConfig->disable_parent_markdowns, conv);
+    break;
 
   // This helps avoiding compiler warnings, yet detect unhandled enum members.
   case TS_CONFIG_NULL:
diff --git a/src/traffic_server/InkAPITest.cc b/src/traffic_server/InkAPITest.cc
index 5fc5a10..e1d547e 100644
--- a/src/traffic_server/InkAPITest.cc
+++ b/src/traffic_server/InkAPITest.cc
@@ -8700,7 +8700,9 @@ std::array<std::string_view, TS_CONFIG_LAST_ENTRY> SDK_Overridable_Configs = {
    "proxy.config.plugin.vc.default_buffer_index",
    "proxy.config.plugin.vc.default_buffer_water_mark",
    "proxy.config.net.sock_notsent_lowat",
-   "proxy.config.body_factory.response_suppression_mode"}};
+   "proxy.config.body_factory.response_suppression_mode",
+   "proxy.config.http.parent_proxy.enable_parent_timeout_markdowns",
+   "proxy.config.http.parent_proxy.disable_parent_markdowns"}};
 
 extern ClassAllocator<HttpSM> httpSMAllocator;