You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2013/07/31 03:46:26 UTC

[2/3] git commit: Added /health endpoints to the Master and Slave.

Added /health endpoints to the Master and Slave.

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


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

Branch: refs/heads/master
Commit: b36726074fb128724340a112eb15028a1d4ca15d
Parents: 02fdd03
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Mon Jul 29 17:50:26 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue Jul 30 18:43:01 2013 -0700

----------------------------------------------------------------------
 src/master/http.cpp   | 21 +++++++++++++++++++++
 src/master/master.cpp |  1 +
 src/master/master.hpp |  6 ++++++
 src/slave/http.cpp    | 21 +++++++++++++++++++++
 src/slave/slave.cpp   |  1 +
 src/slave/slave.hpp   | 10 ++++++++--
 6 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b3672607/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index ec9b05a..a85f800 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -25,6 +25,8 @@
 #include <mesos/mesos.hpp>
 #include <mesos/resources.hpp>
 
+#include <process/help.hpp>
+
 #include <stout/foreach.hpp>
 #include <stout/json.hpp>
 #include <stout/net.hpp>
@@ -46,6 +48,9 @@ namespace internal {
 namespace master {
 
 using process::Future;
+using process::HELP;
+using process::TLDR;
+using process::USAGE;
 
 using process::http::BadRequest;
 using process::http::InternalServerError;
@@ -230,6 +235,22 @@ JSON::Object model(const Role& role)
 }
 
 
+const string Master::Http::HEALTH_HELP = HELP(
+    TLDR(
+        "Health check of the Master."),
+    USAGE(
+        "/master/health"),
+    DESCRIPTION(
+        "Returns 200 OK iff the Master is healthy.",
+        "Delayed responses are also indicative of poor health."));
+
+
+Future<Response> Master::Http::health(const Request& request)
+{
+  return OK();
+}
+
+
 Future<Response> Master::Http::redirect(const Request& request)
 {
   LOG(INFO) << "HTTP request for '" << request.path << "'";

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3672607/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 690b558..1228232 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -405,6 +405,7 @@ void Master::initialize()
       &ExitedExecutorMessage::status);
 
   // Setup HTTP routes.
+  route("/health", Http::HEALTH_HELP, bind(&Http::health, http, params::_1));
   route("/redirect", None(), bind(&Http::redirect, http, params::_1));
   route("/stats.json", None(), bind(&Http::stats, http, params::_1));
   route("/state.json", None(), bind(&Http::state, http, params::_1));

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3672607/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index f0e46a3..1d109c7 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -199,6 +199,10 @@ private:
   public:
     Http(const Master& _master) : master(_master) {}
 
+    // /master/health
+    process::Future<process::http::Response> health(
+        const process::http::Request& request);
+
     // /master/redirect
     process::Future<process::http::Response> redirect(
         const process::http::Request& request);
@@ -215,6 +219,8 @@ private:
     process::Future<process::http::Response> roles(
         const process::http::Request& request);
 
+    const static std::string HEALTH_HELP;
+
   private:
     const Master& master;
   } http;

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3672607/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 12a866c..c45dfb4 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -24,6 +24,8 @@
 #include <mesos/mesos.hpp>
 #include <mesos/resources.hpp>
 
+#include <process/help.hpp>
+
 #include <stout/foreach.hpp>
 #include <stout/json.hpp>
 #include <stout/net.hpp>
@@ -42,6 +44,9 @@ namespace internal {
 namespace slave {
 
 using process::Future;
+using process::HELP;
+using process::TLDR;
+using process::USAGE;
 
 using process::http::OK;
 using process::http::Response;
@@ -244,6 +249,22 @@ JSON::Object model(const Framework& framework)
 }
 
 
+const string Slave::Http::HEALTH_HELP = HELP(
+    TLDR(
+        "Health check of the Slave."),
+    USAGE(
+        "/slave(1)/health"),
+    DESCRIPTION(
+        "Returns 200 OK iff the Slave is healthy.",
+        "Delayed responses are also indicative of poor health."));
+
+
+Future<Response> Slave::Http::health(const Request& request)
+{
+  return OK();
+}
+
+
 Future<Response> Slave::Http::stats(const Request& request)
 {
   LOG(INFO) << "HTTP request for '" << request.path << "'";

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3672607/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 8fb47f6..7f6e6b4 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -362,6 +362,7 @@ void Slave::initialize()
   install("PING", &Slave::ping);
 
   // Setup HTTP routes.
+  route("/health", Http::HEALTH_HELP, bind(&Http::health, http, params::_1));
   route("/stats.json", None(), bind(&Http::stats, http, params::_1));
   route("/state.json", None(), bind(&Http::state, http, params::_1));
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b3672607/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index f2c5e56..97f2083 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -259,13 +259,19 @@ private:
   public:
     Http(const Slave& _slave) : slave(_slave) {}
 
+    // /slave/health
+    process::Future<process::http::Response> health(
+        const process::http::Request& request);
+
     // /slave/stats.json
     process::Future<process::http::Response> stats(
-      const process::http::Request& request);
+        const process::http::Request& request);
 
     // /slave/state.json
     process::Future<process::http::Response> state(
-      const process::http::Request& request);
+        const process::http::Request& request);
+
+    static const std::string HEALTH_HELP;
 
   private:
     const Slave& slave;