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

shinrich pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new d8c814a  Add configuration for per-client IP debugging
d8c814a is described below

commit d8c814ad57bccd8362e59bb6f22babf0ec094965
Author: shinrich <shinr...@yahoo-inc.com>
AuthorDate: Wed Jan 25 17:55:23 2017 -0600

    Add configuration for per-client IP debugging
---
 doc/admin-guide/files/records.config.en.rst |  8 +++++++-
 iocore/cache/Cache.cc                       |  1 +
 iocore/net/P_UnixNetVConnection.h           |  1 +
 iocore/net/UnixNet.cc                       |  4 ++--
 lib/ts/ContFlags.cc                         | 32 +++++------------------------
 lib/ts/ContFlags.h                          | 10 ++++++---
 lib/ts/Diags.cc                             |  4 ++--
 lib/ts/Diags.h                              | 14 ++++++++++---
 mgmt/RecordsConfig.cc                       |  2 ++
 proxy/Main.cc                               | 24 ++++++++++++++++++++++
 proxy/http/HttpSM.cc                        |  2 +-
 proxy/http/HttpServerSession.cc             |  2 ++
 proxy/shared/DiagsConfig.cc                 |  2 +-
 13 files changed, 66 insertions(+), 40 deletions(-)

diff --git a/doc/admin-guide/files/records.config.en.rst 
b/doc/admin-guide/files/records.config.en.rst
index 0dfec5a..24310a8 100644
--- a/doc/admin-guide/files/records.config.en.rst
+++ b/doc/admin-guide/files/records.config.en.rst
@@ -2967,7 +2967,13 @@ Diagnostic Logging Configuration
 .. ts:cv:: CONFIG proxy.config.diags.debug.enabled INT 0
    :reloadable:
 
-   Enables logging for diagnostic messages whose log level is `diag` or 
`debug`.
+   When set to 1, enables logging for diagnostic messages whose log level is 
`diag` or `debug`.
+
+   When set to 2, interprets the :ts:cv:`proxy.config.diags.debug.client_ip` 
setting determine whether diagnostic messages are logged.
+
+.. ts:cv:: CONFIG proxy.config.diags.debug.client_ip STRING NULL
+
+   if :ts:cv:`proxy.config.diags.debug.enabled` is set to 2, this value is 
tested against the source IP of the incoming connection.  If there is a match, 
all the diagnostic messages for that connection and the related outgoing 
connection will be logged.
 
 .. ts:cv:: CONFIG proxy.config.diags.debug.tags STRING http|dns
 
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index c39a0d8..23c362c 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -1004,6 +1004,7 @@ CacheProcessor::cacheInitialized()
           vol = gvol[i];
           double factor;
           if (gvol[i]->cache == theCache) {
+            ink_assert(gvol[i]->cache != nullptr);
             factor = (double)(int64_t)(gvol[i]->len >> STORE_BLOCK_SHIFT) / 
(int64_t)theCache->cache_size;
             Debug("cache_init", "CacheProcessor::cacheInitialized - factor = 
%f", factor);
             gvol[i]->ram_cache->init((int64_t)(http_ram_cache_size * factor), 
vol);
diff --git a/iocore/net/P_UnixNetVConnection.h 
b/iocore/net/P_UnixNetVConnection.h
index c6ad45e..06a2d79 100644
--- a/iocore/net/P_UnixNetVConnection.h
+++ b/iocore/net/P_UnixNetVConnection.h
@@ -317,6 +317,7 @@ TS_INLINE void
 UnixNetVConnection::set_remote_addr()
 {
   ats_ip_copy(&remote_addr, &con.addr);
+  this->control_flags.set_flag(ContFlags::DEBUG_OVERRIDE, 
diags->test_override_ip(remote_addr));
 }
 
 TS_INLINE void
diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc
index 2b7476d..831c21f 100644
--- a/iocore/net/UnixNet.cc
+++ b/iocore/net/UnixNet.cc
@@ -432,7 +432,7 @@ NetHandler::process_ready_list()
   }
 #else  /* !USE_EDGE_TRIGGER */
   while ((vc = read_ready_list.dequeue())) {
-    diags->set_override(vc->control.debug_override);
+    set_cont_flags(vc->control_flags);
     if (vc->closed)
       free_netvc(vc);
     else if (vc->read.enabled && vc->read.triggered)
@@ -441,7 +441,7 @@ NetHandler::process_ready_list()
       vc->ep.modify(-EVENTIO_READ);
   }
   while ((vc = write_ready_list.dequeue())) {
-    diags->set_override(vc->control.debug_override);
+    set_cont_flags(vc->control_flags);
     if (vc->closed)
       free_netvc(vc);
     else if (vc->write.enabled && vc->write.triggered)
diff --git a/lib/ts/ContFlags.cc b/lib/ts/ContFlags.cc
index ef84768..ba5e0bf 100644
--- a/lib/ts/ContFlags.cc
+++ b/lib/ts/ContFlags.cc
@@ -23,50 +23,28 @@
 
 #include "ContFlags.h"
 
-static ink_thread_key init_thread_key();
-static inkcoreapi ink_thread_key flags_data_key = init_thread_key();
-
-static ink_thread_key
-init_thread_key()
-{
-  ink_thread_key_create(&flags_data_key, nullptr);
-  return flags_data_key;
-}
-
-/* Set up a cont_flags entry for this threa */
-void
-init_cont_flags()
-{
-  ContFlags new_flags;
-  void *val = reinterpret_cast<void 
*>(static_cast<intptr_t>((new_flags.get_flags())));
-  ink_thread_setspecific(flags_data_key, val);
-}
+thread_local ContFlags local_flags;
 
 void
 set_cont_flags(const ContFlags &flags)
 {
-  void *val = reinterpret_cast<void 
*>(static_cast<intptr_t>((flags.get_flags())));
-  ink_thread_setspecific(flags_data_key, val);
+  local_flags.set_flags(flags.get_flags());
 }
 
 void
 set_cont_flag(ContFlags::flags flag_bit, bool value)
 {
-  ContFlags 
new_flags(reinterpret_cast<intptr_t>(ink_thread_getspecific(flags_data_key)));
-  new_flags.set_flag(flag_bit, value);
-  void *val = reinterpret_cast<void 
*>(static_cast<intptr_t>((new_flags.get_flags())));
-  ink_thread_setspecific(flags_data_key, val);
+  local_flags.set_flag(flag_bit, value);
 }
 
 ContFlags
 get_cont_flags()
 {
-  return 
ContFlags(reinterpret_cast<intptr_t>(ink_thread_getspecific(flags_data_key)));
+  return local_flags;
 }
 
 bool
 get_cont_flag(ContFlags::flags flag_bit)
 {
-  ContFlags 
flags(reinterpret_cast<intptr_t>(ink_thread_getspecific(flags_data_key)));
-  return flags.get_flag(flag_bit);
+  return local_flags.get_flag(flag_bit);
 }
diff --git a/lib/ts/ContFlags.h b/lib/ts/ContFlags.h
index 21dff75..eb75016 100644
--- a/lib/ts/ContFlags.h
+++ b/lib/ts/ContFlags.h
@@ -42,7 +42,7 @@ class ContFlags
 public:
   enum flags { DEBUG_OVERRIDE = 0, DISABLE_PLUGINS = 1, LAST_FLAG };
 
-  ContFlags() : raw_flags(0) {}
+  ContFlags() {}
   ContFlags(uint32_t in_flags) : raw_flags(in_flags) {}
   void
   set_flags(uint32_t new_flags)
@@ -80,12 +80,16 @@ public:
       return false;
     }
   }
+  bool
+  is_set() const
+  {
+    return raw_flags != 0;
+  }
 
 private:
-  uint32_t raw_flags;
+  uint32_t raw_flags = 0;
 };
 
-void init_cont_flags();
 void set_cont_flags(const ContFlags &flags);
 void set_cont_flag(ContFlags::flags flag_bit, bool value);
 ContFlags get_cont_flags();
diff --git a/lib/ts/Diags.cc b/lib/ts/Diags.cc
index 70095d1..04ca6e2 100644
--- a/lib/ts/Diags.cc
+++ b/lib/ts/Diags.cc
@@ -44,8 +44,8 @@
 #include "ts/ink_thread.h"
 #include "ts/Diags.h"
 
-int diags_on_for_plugins          = 0;
-bool DiagsConfigState::enabled[2] = {false, false};
+int diags_on_for_plugins         = 0;
+int DiagsConfigState::enabled[2] = {0, 0};
 
 // Global, used for all diagnostics
 inkcoreapi Diags *diags = nullptr;
diff --git a/lib/ts/Diags.h b/lib/ts/Diags.h
index fbed231..8b220cb 100644
--- a/lib/ts/Diags.h
+++ b/lib/ts/Diags.h
@@ -90,7 +90,7 @@ typedef void (*DiagsCleanupFunc)();
 
 struct DiagsConfigState {
   // this is static to eliminate many loads from the critical path
-  static bool enabled[2];                    // one debug, one action
+  static int enabled[2];                     // one debug, one action
   DiagsModeOutput outputs[DiagsLevel_Count]; // where each level prints
 };
 
@@ -136,15 +136,21 @@ public:
   }
 
   bool
+  test_override_ip(IpEndpoint const &test_ip)
+  {
+    return this->debug_client_ip == test_ip;
+  }
+
+  bool
   on(DiagsTagType mode = DiagsTagType_Debug) const
   {
-    return (config.enabled[mode]);
+    return ((config.enabled[mode] == 1) || (config.enabled[mode] == 2 && 
this->get_override()));
   }
 
   bool
   on(const char *tag, DiagsTagType mode = DiagsTagType_Debug) const
   {
-    return (config.enabled[mode] && tag_activated(tag, mode));
+    return this->on(mode) && tag_activated(tag, mode);
   }
 
   /////////////////////////////////////
@@ -222,6 +228,8 @@ public:
   const char *base_debug_tags;  // internal copy of default debug tags
   const char *base_action_tags; // internal copy of default action tags
 
+  IpAddr debug_client_ip;
+
 private:
   const char *prefix_str;
   mutable ink_mutex tag_table_lock; // prevents reconfig/read races
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index fdc5b8a..e6037e9 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -199,6 +199,8 @@ static const RecordElement RecordsConfig[] =
   ,
   {RECT_CONFIG, "proxy.config.diags.debug.tags", RECD_STRING, "http|dns", 
RECU_DYNAMIC, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.diags.debug.client_ip", RECD_STRING, NULL, 
RECU_DYNAMIC, RR_NULL, RECC_NULL, NULL, RECA_NULL} 
+  ,
   {RECT_CONFIG, "proxy.config.diags.action.enabled", RECD_INT, "0", 
RECU_DYNAMIC, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
   ,
   {RECT_CONFIG, "proxy.config.diags.action.tags", RECD_STRING, nullptr, 
RECU_DYNAMIC, RR_NULL, RECC_NULL, nullptr, RECA_NULL}
diff --git a/proxy/Main.cc b/proxy/Main.cc
index 5348726..1269f82 100644
--- a/proxy/Main.cc
+++ b/proxy/Main.cc
@@ -433,6 +433,23 @@ private:
   struct rusage _usage;
 };
 
+void
+set_debug_ip(const char *ip_string)
+{
+  if (ip_string)
+    diags->debug_client_ip.load(ip_string);
+  else
+    diags->debug_client_ip.invalidate();
+}
+
+static int
+update_debug_client_ip(const char * /*name ATS_UNUSED */, RecDataT /* 
data_type ATS_UNUSED */, RecData data,
+                       void * /* data_type ATS_UNUSED */)
+{
+  set_debug_ip(data.rec_string);
+  return 0;
+}
+
 static int
 init_memory_tracker(const char *config_var, RecDataT /* type ATS_UNUSED */, 
RecData data, void * /* cookie ATS_UNUSED */)
 {
@@ -1793,6 +1810,13 @@ main(int /* argc ATS_UNUSED */, const char **argv)
   REC_RegisterConfigUpdateFunc("proxy.config.dump_mem_info_frequency", 
init_memory_tracker, nullptr);
   init_memory_tracker(nullptr, RECD_NULL, RecData(), nullptr);
 
+  char *p = REC_ConfigReadString("proxy.config.diags.debug.client_ip");
+  if (p) {
+    // Translate string to IpAddr
+    set_debug_ip(p);
+  }
+  REC_RegisterConfigUpdateFunc("proxy.config.diags.debug.client_ip", 
update_debug_client_ip, NULL);
+
   // log initialization moved down
 
   if (command_flag) {
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index c471520..c83f516 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -5837,7 +5837,7 @@ HttpSM::attach_server_session(HttpServerSession *s)
   server_transact_count = server_session->transact_count++;
   // Propagate the per client IP debugging
   if (ua_session) {
-    s->get_netvc()->control_flags = get_cont_flags();
+    s->get_netvc()->control_flags.set_flags(get_cont_flags().get_flags());
   } else { // If there is no ua_session no sense in continuing to attach the 
server session
     return;
   }
diff --git a/proxy/http/HttpServerSession.cc b/proxy/http/HttpServerSession.cc
index e7db34d..c70cf44 100644
--- a/proxy/http/HttpServerSession.cc
+++ b/proxy/http/HttpServerSession.cc
@@ -170,6 +170,8 @@ HttpServerSession::release()
   // Set our state to KA for stat issues
   state = HSS_KA_SHARED;
 
+  server_vc->control_flags.set_flags(0);
+
   // Private sessions are never released back to the shared pool
   if (private_session || TS_SERVER_SESSION_SHARING_MATCH_NONE == 
sharing_match) {
     this->do_io_close();
diff --git a/proxy/shared/DiagsConfig.cc b/proxy/shared/DiagsConfig.cc
index bbf3f63..96445f2 100644
--- a/proxy/shared/DiagsConfig.cc
+++ b/proxy/shared/DiagsConfig.cc
@@ -73,7 +73,7 @@ DiagsConfig::reconfigure_diags()
 
   e = (int)REC_readInteger("proxy.config.diags.debug.enabled", &found);
   if (e && found) {
-    c.enabled[DiagsTagType_Debug] = true; // implement OR logic
+    c.enabled[DiagsTagType_Debug] = e; // implement OR logic
   }
   all_found = all_found && found;
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Reply via email to