]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: runtime adjustment of perf counter threshold
authorJohn Spray <john.spray@redhat.com>
Thu, 31 Aug 2017 16:13:23 +0000 (12:13 -0400)
committerJohn Spray <john.spray@redhat.com>
Wed, 1 Nov 2017 23:03:22 +0000 (23:03 +0000)
ceph-mgr has missed out on the `config set` command
that the other daemons got recently: add it here
and hook it all up to the stats period and threshold
settings.

Signed-off-by: John Spray <john.spray@redhat.com>
(cherry picked from commit 057b73d641decb9403aba50caae9d139f3a34dd4)

src/mgr/DaemonServer.cc
src/mgr/DaemonServer.h
src/mgr/MgrCommands.h

index 74c43d7ac6467eac7c8abe85ce72417c129a0c09..298ed4413f6ef8b3e2e955a3de1b8089eeb58d19 100644 (file)
@@ -74,10 +74,13 @@ DaemonServer::DaemonServer(MonClient *monc_,
                       g_conf->auth_cluster_required :
                       g_conf->auth_supported),
       lock("DaemonServer")
-{}
+{
+  g_conf->add_observer(this);
+}
 
 DaemonServer::~DaemonServer() {
   delete msgr;
+  g_conf->remove_observer(this);
 }
 
 int DaemonServer::init(uint64_t gid, entity_addr_t client_addr)
@@ -232,6 +235,11 @@ bool DaemonServer::ms_handle_reset(Connection *con)
     dout(10) << "unregistering osd." << session->osd_id
             << "  session " << session << " con " << con << dendl;
     osd_cons[session->osd_id].erase(con);
+
+    auto iter = daemon_connections.find(con);
+    if (iter != daemon_connections.end()) {
+      daemon_connections.erase(iter);
+    }
   }
   return false;
 }
@@ -315,10 +323,7 @@ bool DaemonServer::handle_open(MMgrOpen *m)
 
   dout(4) << "from " << m->get_connection() << "  " << key << dendl;
 
-  auto configure = new MMgrConfigure();
-  configure->stats_period = g_conf->mgr_stats_period;
-  configure->stats_threshold = g_conf->get_val<int64_t>("mgr_stats_threshold");
-  m->get_connection()->send_message(configure);
+  _send_configure(m->get_connection());
 
   DaemonStatePtr daemon;
   if (daemon_state.exists(key)) {
@@ -359,6 +364,15 @@ bool DaemonServer::handle_open(MMgrOpen *m)
     }
   }
 
+  if (m->get_connection()->get_peer_type() != entity_name_t::TYPE_CLIENT &&
+      m->service_name.empty())
+  {
+    // Store in set of the daemon/service connections, i.e. those
+    // connections that require an update in the event of stats
+    // configuration changes.
+    daemon_connections.insert(m->get_connection());
+  }
+
   m->put();
   return true;
 }
@@ -706,6 +720,19 @@ bool DaemonServer::handle_command(MCommand *m)
     return true;
   }
 
+  if (prefix == "config set") {
+    std::string key;
+    std::string val;
+    cmd_getval(cct, cmdctx->cmdmap, "key", key);
+    cmd_getval(cct, cmdctx->cmdmap, "value", val);
+    r = cct->_conf->set_val(key, val, true, &ss);
+    if (r == 0) {
+      cct->_conf->apply_changes(nullptr);
+    }
+    cmdctx->reply(0, ss);
+    return true;
+  }
+
   // -----------
   // PG commands
 
@@ -1405,3 +1432,48 @@ void DaemonServer::got_service_map()
     daemon_state.cull(p.first, names);
   }
 }
+
+
+const char** DaemonServer::get_tracked_conf_keys() const
+{
+  static const char *KEYS[] = {
+    "mgr_stats_threshold",
+    "mgr_stats_period",
+    nullptr
+  };
+
+  return KEYS;
+}
+
+void DaemonServer::handle_conf_change(const struct md_config_t *conf,
+                                              const std::set <std::string> &changed)
+{
+  dout(4) << "ohai" << dendl;
+  // We may be called within lock (via MCommand `config set`) or outwith the
+  // lock (via admin socket `config set`), so handle either case.
+  const bool initially_locked = lock.is_locked_by_me();
+  if (!initially_locked) {
+    lock.Lock();
+  }
+
+  if (changed.count("mgr_stats_threshold") || changed.count("mgr_stats_period")) {
+    dout(4) << "Updating stats threshold/period on "
+            << daemon_connections.size() << " clients" << dendl;
+    // Send a fresh MMgrConfigure to all clients, so that they can follow
+    // the new policy for transmitting stats
+    for (auto &c : daemon_connections) {
+      _send_configure(c);
+    }
+  }
+}
+
+void DaemonServer::_send_configure(ConnectionRef c)
+{
+  assert(lock.is_locked_by_me());
+
+  auto configure = new MMgrConfigure();
+  configure->stats_period = g_conf->get_val<int64_t>("mgr_stats_period");
+  configure->stats_threshold = g_conf->get_val<int64_t>("mgr_stats_threshold");
+  c->send_message(configure);
+}
+
index 6e44832021510462107eb2e02b7df18c884c54d1..d29e3752f8612ad5d8a33909f62772bed7f207ab 100644 (file)
@@ -42,7 +42,7 @@ struct MonCommand;
  * Server used in ceph-mgr to communicate with Ceph daemons like
  * MDSs and OSDs.
  */
-class DaemonServer : public Dispatcher
+class DaemonServer : public Dispatcher, public md_config_obs_t
 {
 protected:
   boost::scoped_ptr<Throttle> client_byte_throttler;
@@ -64,10 +64,15 @@ protected:
 
   AuthAuthorizeHandlerRegistry auth_registry;
 
+  // Connections for daemons, and clients with service names set
+  // (i.e. those MgrClients that are allowed to send MMgrReports)
+  std::set<ConnectionRef> daemon_connections;
+
   /// connections for osds
   ceph::unordered_map<int,set<ConnectionRef>> osd_cons;
 
   ServiceMap pending_service_map;  // uncommitted
+
   epoch_t pending_service_map_dirty = 0;
 
   Mutex lock;
@@ -128,6 +133,12 @@ public:
   bool handle_command(MCommand *m);
   void send_report();
   void got_service_map();
+
+  void _send_configure(ConnectionRef c);
+
+  virtual const char** get_tracked_conf_keys() const override;
+  virtual void handle_conf_change(const struct md_config_t *conf,
+                          const std::set <std::string> &changed) override;
 };
 
 #endif
index 1818454e1fcc47df9a5ded7323c5a9c59d5cd55d..79766fafed93acdc1a36b6edb710ece131a3526a 100644 (file)
@@ -131,3 +131,8 @@ COMMAND("service dump",
         "dump service map", "service", "r", "cli,rest")
 COMMAND("service status",
         "dump service state", "service", "r", "cli,rest")
+
+COMMAND("config set " \
+       "name=key,type=CephString name=value,type=CephString",
+       "Set a configuration option at runtime (not persistent)",
+       "mgr", "rw", "cli,rest")