You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/06/16 22:00:29 UTC

[4/4] mesos git commit: Added a metric to replicated log.

Added a metric to replicated log.

This is a gauge indicating if the replicated log has recovered or not.

Review: https://reviews.apache.org/r/48801


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7b1ff0be
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7b1ff0be
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7b1ff0be

Branch: refs/heads/master
Commit: 7b1ff0bedb363ab1cd153a71ac9df5f3e764f389
Parents: 27630c4
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Jun 15 22:28:02 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jun 16 15:00:06 2016 -0700

----------------------------------------------------------------------
 include/mesos/log/log.hpp |  6 +++--
 src/log/log.cpp           | 50 +++++++++++++++++++++++++++++++++++-------
 src/log/log.hpp           | 22 +++++++++++++++++--
 3 files changed, 66 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7b1ff0be/include/mesos/log/log.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/log/log.hpp b/include/mesos/log/log.hpp
index 9c86349..0f69848 100644
--- a/include/mesos/log/log.hpp
+++ b/include/mesos/log/log.hpp
@@ -192,7 +192,8 @@ public:
   Log(int quorum,
       const std::string& path,
       const std::set<process::UPID>& pids,
-      bool autoInitialize = false);
+      bool autoInitialize = false,
+      const Option<std::string>& metricsPrefix = None());
 
   // Creates a new replicated log that assumes the specified quorum
   // size, is backed by a file at the specified path, and coordinates
@@ -204,7 +205,8 @@ public:
       const Duration& timeout,
       const std::string& znode,
       const Option<zookeeper::Authentication>& auth = None(),
-      bool autoInitialize = false);
+      bool autoInitialize = false,
+      const Option<std::string>& metricsPrefix = None());
 
   ~Log();
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/7b1ff0be/src/log/log.cpp
----------------------------------------------------------------------
diff --git a/src/log/log.cpp b/src/log/log.cpp
index c0f1cb3..f8e439f 100644
--- a/src/log/log.cpp
+++ b/src/log/log.cpp
@@ -28,6 +28,8 @@
 #include <process/process.hpp>
 #include <process/shared.hpp>
 
+#include <process/metrics/metrics.hpp>
+
 #include <stout/check.hpp>
 #include <stout/foreach.hpp>
 #include <stout/lambda.hpp>
@@ -64,13 +66,15 @@ LogProcess::LogProcess(
     size_t _quorum,
     const string& path,
     const set<UPID>& pids,
-    bool _autoInitialize)
+    bool _autoInitialize,
+    const Option<string>& metricsPrefix)
   : ProcessBase(ID::generate("log")),
     quorum(_quorum),
     replica(new Replica(path)),
     network(new Network(pids + (UPID) replica->pid())),
     autoInitialize(_autoInitialize),
-    group(nullptr) {}
+    group(nullptr),
+    metrics(*this, metricsPrefix) {}
 
 
 LogProcess::LogProcess(
@@ -80,7 +84,8 @@ LogProcess::LogProcess(
     const Duration& timeout,
     const string& znode,
     const Option<zookeeper::Authentication>& auth,
-    bool _autoInitialize)
+    bool _autoInitialize,
+    const Option<string>& metricsPrefix)
   : ProcessBase(ID::generate("log")),
     quorum(_quorum),
     replica(new Replica(path)),
@@ -91,7 +96,8 @@ LogProcess::LogProcess(
         auth,
         Set<UPID>((UPID) replica->pid()))),
     autoInitialize(_autoInitialize),
-    group(new zookeeper::Group(servers, timeout, znode, auth)) {}
+    group(new zookeeper::Group(servers, timeout, znode, auth)),
+    metrics(*this, metricsPrefix) {}
 
 
 void LogProcess::initialize()
@@ -236,6 +242,12 @@ void LogProcess::_recover()
 }
 
 
+double LogProcess::_recovered()
+{
+  return recovered.future().isReady() ? 1 : 0;
+}
+
+
 void LogProcess::watch(
     const UPID& pid,
     const set<zookeeper::Group::Membership>& memberships)
@@ -268,6 +280,23 @@ void LogProcess::discarded()
 }
 
 
+LogProcess::Metrics::Metrics(
+    const LogProcess& process,
+    const Option<string>& prefix)
+  : recovered(
+        prefix.getOrElse("") + "log/recovered",
+        defer(process, &LogProcess::_recovered))
+{
+  process::metrics::add(recovered);
+}
+
+
+LogProcess::Metrics::~Metrics()
+{
+  process::metrics::remove(recovered);
+}
+
+
 /////////////////////////////////////////////////
 // Implementation of LogReaderProcess.
 /////////////////////////////////////////////////
@@ -610,7 +639,8 @@ Log::Log(
     int quorum,
     const string& path,
     const set<UPID>& pids,
-    bool autoInitialize)
+    bool autoInitialize,
+    const Option<string>& metricsPrefix)
 {
   GOOGLE_PROTOBUF_VERIFY_VERSION;
 
@@ -619,11 +649,13 @@ Log::Log(
         quorum,
         path,
         pids,
-        autoInitialize);
+        autoInitialize,
+        metricsPrefix);
 
   spawn(process);
 }
 
+
 Log::Log(
     int quorum,
     const string& path,
@@ -631,7 +663,8 @@ Log::Log(
     const Duration& timeout,
     const string& znode,
     const Option<zookeeper::Authentication>& auth,
-    bool autoInitialize)
+    bool autoInitialize,
+    const Option<string>& metricsPrefix)
 {
   GOOGLE_PROTOBUF_VERIFY_VERSION;
 
@@ -643,7 +676,8 @@ Log::Log(
         timeout,
         znode,
         auth,
-        autoInitialize);
+        autoInitialize,
+        metricsPrefix);
 
   spawn(process);
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/7b1ff0be/src/log/log.hpp
----------------------------------------------------------------------
diff --git a/src/log/log.hpp b/src/log/log.hpp
index 6e75773..a600025 100644
--- a/src/log/log.hpp
+++ b/src/log/log.hpp
@@ -26,6 +26,8 @@
 #include <process/process.hpp>
 #include <process/shared.hpp>
 
+#include <process/metrics/gauge.hpp>
+
 #include <stout/nothing.hpp>
 
 #include "log/coordinator.hpp"
@@ -44,7 +46,8 @@ public:
       size_t _quorum,
       const std::string& path,
       const std::set<process::UPID>& pids,
-      bool _autoInitialize);
+      bool _autoInitialize,
+      const Option<std::string>& metricsPrefix);
 
   LogProcess(
       size_t _quorum,
@@ -53,7 +56,8 @@ public:
       const Duration& timeout,
       const std::string& znode,
       const Option<zookeeper::Authentication>& auth,
-      bool _autoInitialize);
+      bool _autoInitialize,
+      const Option<std::string>& metricsPrefix);
 
   // Recovers the log by catching up if needed. Returns a shared
   // pointer to the local replica if the recovery succeeds.
@@ -70,6 +74,9 @@ private:
   // Continuations.
   void _recover();
 
+  // Return true if the log has finished recovery.
+  double _recovered();
+
   // TODO(benh): Factor this out into "membership renewer".
   void watch(
       const process::UPID& pid,
@@ -92,6 +99,17 @@ private:
   // continually renew the replicas membership (when using ZooKeeper).
   zookeeper::Group* group;
   process::Future<zookeeper::Group::Membership> membership;
+
+  struct Metrics
+  {
+    explicit Metrics(
+        const LogProcess& process,
+        const Option<std::string>& prefix);
+
+    ~Metrics();
+
+    process::metrics::Gauge recovered;
+  } metrics;
 };