]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg: Add dump() filters to async messenger/connection
authorMarcel Lauhoff <marcel.lauhoff@clyso.com>
Tue, 22 Oct 2024 11:30:25 +0000 (13:30 +0200)
committerMarcel Lauhoff <marcel.lauhoff@clyso.com>
Mon, 17 Feb 2025 17:41:18 +0000 (18:41 +0100)
Allow a caller to filter the dumped data at query time. Use filter()
function argument in Messenger to make future changes easy.
Add a tcp_info switch to the connection dump.

Signed-off-by: Marcel Lauhoff <marcel.lauhoff@clyso.com>
src/msg/Messenger.h
src/msg/async/AsyncConnection.cc
src/msg/async/AsyncConnection.h
src/msg/async/AsyncMessenger.cc
src/msg/async/AsyncMessenger.h

index a1a1c48d3dc5959fc1994b81447816b7a219fe2b..7c192dd24bfc9cd6f986d986c4692db2a43cc1a3 100644 (file)
@@ -298,13 +298,13 @@ public:
    * Get the number of Messages which the Messenger has received
    * but not yet dispatched.
    */
-  virtual int get_dispatch_queue_len() = 0;
+  virtual int get_dispatch_queue_len() const = 0;
 
   /**
    * Get age of oldest undelivered message
    * (0 if the queue is empty)
    */
-  virtual double get_dispatch_queue_max_age(utime_t now) = 0;
+  virtual double get_dispatch_queue_max_age(utime_t now) const = 0;
 
   /**
    * @} // Accessors
@@ -522,7 +522,9 @@ public:
    * @} // Startup/Shutdown
    */
 
-  virtual void dump(Formatter* f) = 0;
+  virtual void dump(
+      Formatter* f, std::function<bool(const std::string&)> filter =
+                        [](const std::string&) { return true; }) const = 0;
 
   /**
    * @defgroup Messaging
index 49a41b4892864e868046544fc70f62b5c60d4ecb..2f247535dea9f36aa08566af41a3733b9b4dfef9 100644 (file)
@@ -817,7 +817,7 @@ void AsyncConnection::tick(uint64_t id)
   }
 }
 
-void AsyncConnection::dump(Formatter *f) {
+void AsyncConnection::dump(Formatter *f, bool tcp_info) {
   std::lock_guard<std::mutex> l(lock);
 
   f->open_object_section("async_connection");
@@ -831,7 +831,7 @@ void AsyncConnection::dump(Formatter *f) {
 
   if (cs) {
     f->dump_int("socket_fd", cs.fd());
-    if (!dump_tcp_info(cs.fd(), f)) {
+    if (!tcp_info || !dump_tcp_info(cs.fd(), f)) {
       f->dump_null("tcp_info");
     }
   } else {
index 614af9189c242b6af37c9a6797dc796470ace092..553c6a1bff1322305c9f805a98bad93bcb63b441 100644 (file)
@@ -243,7 +243,7 @@ private:
 
   bool is_msgr2() const override;
 
-  void dump(Formatter* f);
+  void dump(Formatter* f, bool tcp_info);
 
   friend class Protocol;
   friend class ProtocolV1;
index 2533128d6d1f9880076eeff5a10cd411952d3d78..34c7f6477871e52901107464377ec0fe392bd3fa 100644 (file)
@@ -360,7 +360,9 @@ int AsyncMessenger::shutdown()
   return 0;
 }
 
-void AsyncMessenger::dump(Formatter* f) {
+void AsyncMessenger::dump(
+    Formatter* f, std::function<bool(const std::string&)> filter) const {
+  const bool tcp_info = filter("tcp_info");
   std::lock_guard l{lock};
   f->dump_unsigned("nonce", nonce);
   f->open_object_section("my_name");
@@ -370,17 +372,19 @@ void AsyncMessenger::dump(Formatter* f) {
   my_addrs->dump(f);
   f->close_section();  // my_addrs
 
-  f->open_array_section("listen_sockets");
-  for (const auto& proc : processors) {
-    for (const auto& sock : proc->listen_sockets) {
-      f->open_object_section("socket");
-      f->dump_int("socket_fd", sock.fd());
+  if (filter("listen_sockets")) {
+    f->open_array_section("listen_sockets");
+    for (const auto& proc : processors) {
+      for (const auto& sock : proc->listen_sockets) {
+        f->open_object_section("socket");
+        f->dump_int("socket_fd", sock.fd());
 
-      f->dump_int("worker_id", proc->worker ? proc->worker->id : -1);
-      f->close_section();  // socket
+        f->dump_int("worker_id", proc->worker ? proc->worker->id : -1);
+        f->close_section();  // socket
+      }
     }
+    f->close_section();  // listen_sockets
   }
-  f->close_section();  // listen_sockets
 
   f->open_object_section("dispatch_queue");
   f->dump_int("length", get_dispatch_queue_len());
@@ -392,36 +396,44 @@ void AsyncMessenger::dump(Formatter* f) {
 
   f->dump_int("connections_count", conns.size());
 
-  f->open_array_section("connections");
-  for (const auto& [e, c] : conns) {
-    f->open_object_section("connection");
-    e.dump(f);
-    c->dump(f);
-    f->close_section();  // connection
+  if (filter("connections")) {
+    f->open_array_section("connections");
+    for (const auto& [e, c] : conns) {
+      f->open_object_section("connection");
+      e.dump(f);
+      c->dump(f, tcp_info);
+      f->close_section();  // connection
+    }
+    f->close_section();  // connections
   }
-  f->close_section();  // connections
 
-  f->open_array_section("anon_conns");
-  for (const auto& c : anon_conns) {
-    c->dump(f);
+  if (filter("anon_conns")) {
+    f->open_array_section("anon_conns");
+    for (const auto& c : anon_conns) {
+      c->dump(f, tcp_info);
+    }
+    f->close_section();  // anon_conns
   }
-  f->close_section();  // anon_conns
 
-  f->open_array_section("accepting_conns");
-  for (const auto& c : accepting_conns) {
-    c->dump(f);
+  if (filter("accepting_conns")) {
+    f->open_array_section("accepting_conns");
+    for (const auto& c : accepting_conns) {
+      c->dump(f, tcp_info);
+    }
+    f->close_section();  // accepting_conns
   }
-  f->close_section();
 
-  f->open_array_section("deleted_conns");
-  for (const auto& c : deleted_conns) {
-    c->dump(f);
+  if (filter("deleted_conns")) {
+    f->open_array_section("deleted_conns");
+    for (const auto& c : deleted_conns) {
+      c->dump(f, tcp_info);
+    }
+    f->close_section();  // deleted_conns
   }
-  f->close_section();  // deleted_conns
 
   if (local_connection) {
     f->open_array_section("local_connection");
-    local_connection->dump(f);
+    local_connection->dump(f, tcp_info);
     f->close_section();  // local_connection
   }
 }
index 469399e8c74b8d5ce235e7f42d816392c652c5b6..cbc580b8d9b7da45167ebc5a124210e34ab2c743 100644 (file)
@@ -97,11 +97,11 @@ public:
    */
   bool set_addr_unknowns(const entity_addrvec_t &addr) override;
 
-  int get_dispatch_queue_len() override {
+  int get_dispatch_queue_len() const override {
     return dispatch_queue.get_queue_len();
   }
 
-  double get_dispatch_queue_max_age(utime_t now) override {
+  double get_dispatch_queue_max_age(utime_t now) const override {
     return dispatch_queue.get_max_age(now);
   }
   /** @} Accessors */
@@ -137,7 +137,9 @@ public:
   void wait() override;
   int shutdown() override;
 
-  void dump(Formatter* f) override;
+  void dump(
+      Formatter* f, std::function<bool(const std::string&)> filter =
+      [](const std::string&) { return true; }) const override;
 
   /** @} // Startup/Shutdown */
 
@@ -225,7 +227,7 @@ private:
   std::string ms_type;
 
   /// overall lock used for AsyncMessenger data structures
-  ceph::mutex lock = ceph::make_mutex("AsyncMessenger::lock");
+  mutable ceph::mutex lock = ceph::make_mutex("AsyncMessenger::lock");
   // AsyncMessenger stuff
   /// approximately unique ID set by the Constructor for use in entity_addr_t
   uint64_t nonce;