You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/11/03 12:40:20 UTC

[2/5] mesos git commit: Used mesos-tcp-connect binary in TCP health checks.

Used mesos-tcp-connect binary in TCP health checks.

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


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

Branch: refs/heads/master
Commit: fa57e4f9bded9d914418786c4bcf795327ec5a0e
Parents: 0ddefe6
Author: Alexander Rukletsov <al...@apache.org>
Authored: Fri Sep 2 18:04:15 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Thu Nov 3 11:34:29 2016 +0100

----------------------------------------------------------------------
 src/docker/executor.cpp             |  1 +
 src/health-check/health_checker.cpp | 72 ++++++++++++++++++++------------
 src/health-check/health_checker.hpp |  3 ++
 src/launcher/default_executor.cpp   |  1 +
 src/launcher/executor.cpp           |  1 +
 5 files changed, 52 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/fa57e4f9/src/docker/executor.cpp
----------------------------------------------------------------------
diff --git a/src/docker/executor.cpp b/src/docker/executor.cpp
index ab3f047..749e590 100644
--- a/src/docker/executor.cpp
+++ b/src/docker/executor.cpp
@@ -522,6 +522,7 @@ private:
 
     Try<Owned<health::HealthChecker>> _checker = health::HealthChecker::create(
         healthCheck,
+        launcherDir,
         self(),
         task.task_id(),
         containerPid,

http://git-wip-us.apache.org/repos/asf/mesos/blob/fa57e4f9/src/health-check/health_checker.cpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.cpp b/src/health-check/health_checker.cpp
index 96ae1a7..5447ce2 100644
--- a/src/health-check/health_checker.cpp
+++ b/src/health-check/health_checker.cpp
@@ -38,6 +38,7 @@
 #include <stout/duration.hpp>
 #include <stout/option.hpp>
 #include <stout/os.hpp>
+#include <stout/path.hpp>
 #include <stout/protobuf.hpp>
 #include <stout/strings.hpp>
 #include <stout/try.hpp>
@@ -70,6 +71,12 @@ namespace mesos {
 namespace internal {
 namespace health {
 
+#ifndef __WINDOWS__
+constexpr char TCP_CHECK_COMMAND[] = "mesos-tcp-connect";
+#else
+constexpr char TCP_CHECK_COMMAND[] = "mesos-tcp-connect.exe";
+#endif // __WINDOWS__
+
 static const string DEFAULT_HTTP_SCHEME = "http";
 
 // Use '127.0.0.1' instead of 'localhost', because the host
@@ -109,6 +116,7 @@ pid_t cloneWithSetns(
 
 Try<Owned<HealthChecker>> HealthChecker::create(
     const HealthCheck& check,
+    const string& launcherDir,
     const UPID& executor,
     const TaskID& taskID,
     Option<pid_t> taskPid,
@@ -122,6 +130,7 @@ Try<Owned<HealthChecker>> HealthChecker::create(
 
   Owned<HealthCheckerProcess> process(new HealthCheckerProcess(
       check,
+      launcherDir,
       executor,
       taskID,
       taskPid,
@@ -154,12 +163,14 @@ Future<Nothing> HealthChecker::healthCheck()
 
 HealthCheckerProcess::HealthCheckerProcess(
     const HealthCheck& _check,
+    const string& _launcherDir,
     const UPID& _executor,
     const TaskID& _taskID,
     Option<pid_t> _taskPid,
     const vector<string>& _namespaces)
   : ProcessBase(process::ID::generate("health-checker")),
     check(_check),
+    launcherDir(_launcherDir),
     initializing(true),
     executor(_executor),
     taskID(_taskID),
@@ -500,21 +511,24 @@ Future<Nothing> HealthCheckerProcess::_tcpHealthCheck()
   CHECK_EQ(HealthCheck::TCP, check.type());
   CHECK(check.has_tcp());
 
+  // TCP_CHECK_COMMAND should be reachable.
+  CHECK(os::exists(launcherDir));
+
   const HealthCheck::TCPCheckInfo& tcp = check.tcp();
 
   VLOG(1) << "Launching TCP health check at port '" << tcp.port() << "'";
 
-  // TODO(haosdent): Replace `bash` with a tiny binary to support
-  // TCP health check with half-open.
-  const vector<string> argv = {
-    "bash",
-    "-c",
-    "</dev/tcp/" + DEFAULT_DOMAIN + "/" + stringify(tcp.port())
+  const string tcpConnectPath = path::join(launcherDir, TCP_CHECK_COMMAND);
+
+  const vector<string> tcpConnectArguments = {
+    tcpConnectPath,
+    "--ip=" + DEFAULT_DOMAIN,
+    "--port=" + stringify(tcp.port())
   };
 
   Try<Subprocess> s = subprocess(
-      "bash",
-      argv,
+      tcpConnectPath,
+      tcpConnectArguments,
       Subprocess::PATH("/dev/null"),
       Subprocess::PIPE(),
       Subprocess::PIPE(),
@@ -523,10 +537,12 @@ Future<Nothing> HealthCheckerProcess::_tcpHealthCheck()
       clone);
 
   if (s.isError()) {
-    return Failure("Failed to create the bash subprocess: " + s.error());
+    return Failure(
+        "Failed to create the " + string(TCP_CHECK_COMMAND) +
+        " subprocess: " + s.error());
   }
 
-  pid_t bashPid = s->pid();
+  pid_t tcpConnectPid = s->pid();
   Duration timeout = Seconds(static_cast<int64_t>(check.timeout_seconds()));
 
   return await(
@@ -534,20 +550,21 @@ Future<Nothing> HealthCheckerProcess::_tcpHealthCheck()
       process::io::read(s->out().get()),
       process::io::read(s->err().get()))
     .after(timeout,
-      [timeout, bashPid](Future<tuple<Future<Option<int>>,
-                                      Future<string>,
-                                      Future<string>>> future) {
+      [timeout, tcpConnectPid](Future<tuple<Future<Option<int>>,
+                                            Future<string>,
+                                            Future<string>>> future) {
       future.discard();
 
-      if (bashPid != -1) {
-        // Cleanup the bash process.
-        VLOG(1) << "Killing the TCP health check process " << bashPid;
+      if (tcpConnectPid != -1) {
+        // Cleanup the TCP_CHECK_COMMAND process.
+        VLOG(1) << "Killing the TCP health check process " << tcpConnectPid;
 
-        os::killtree(bashPid, SIGKILL);
+        os::killtree(tcpConnectPid, SIGKILL);
       }
 
       return Failure(
-          "bash has not returned after " + stringify(timeout) + "; aborting");
+          string(TCP_CHECK_COMMAND) + " has not returned after " +
+          stringify(timeout) + "; aborting");
     })
     .then(defer(self(), &Self::__tcpHealthCheck, lambda::_1));
 }
@@ -562,25 +579,28 @@ Future<Nothing> HealthCheckerProcess::__tcpHealthCheck(
   Future<Option<int>> status = std::get<0>(t);
   if (!status.isReady()) {
     return Failure(
-        "Failed to get the exit status of the bash process: " +
-        (status.isFailed() ? status.failure() : "discarded"));
+        "Failed to get the exit status of the " + string(TCP_CHECK_COMMAND) +
+        " process: " + (status.isFailed() ? status.failure() : "discarded"));
   }
 
   if (status->isNone()) {
-    return Failure("Failed to reap the bash process");
+    return Failure(
+        "Failed to reap the " + string(TCP_CHECK_COMMAND) + " process");
   }
 
   int statusCode = status->get();
   if (statusCode != 0) {
     Future<string> error = std::get<2>(t);
     if (!error.isReady()) {
-      return Failure("bash returned " + WSTRINGIFY(statusCode) +
-                     "; reading stderr failed: " +
-                     (error.isFailed() ? error.failure() : "discarded"));
+      return Failure(
+          string(TCP_CHECK_COMMAND) + " returned " +
+          WSTRINGIFY(statusCode) + "; reading stderr failed: " +
+          (error.isFailed() ? error.failure() : "discarded"));
     }
 
-    return Failure("bash returned " + WSTRINGIFY(statusCode) + ": " +
-                   error.get());
+    return Failure(
+        string(TCP_CHECK_COMMAND) + " returned " +
+        WSTRINGIFY(statusCode) + ": " + error.get());
   }
 
   return Nothing();

http://git-wip-us.apache.org/repos/asf/mesos/blob/fa57e4f9/src/health-check/health_checker.hpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.hpp b/src/health-check/health_checker.hpp
index 392b4d5..a1dc724 100644
--- a/src/health-check/health_checker.hpp
+++ b/src/health-check/health_checker.hpp
@@ -59,6 +59,7 @@ public:
    */
   static Try<process::Owned<HealthChecker>> create(
       const HealthCheck& check,
+      const std::string& launcherDir,
       const process::UPID& executor,
       const TaskID& taskID,
       Option<pid_t> taskPid,
@@ -80,6 +81,7 @@ class HealthCheckerProcess : public ProtobufProcess<HealthCheckerProcess>
 public:
   HealthCheckerProcess(
       const HealthCheck& _check,
+      const std::string& _launcherDir,
       const process::UPID& _executor,
       const TaskID& _taskID,
       Option<pid_t> _taskPid,
@@ -119,6 +121,7 @@ private:
 
   process::Promise<Nothing> promise;
   HealthCheck check;
+  std::string launcherDir;
   bool initializing;
   process::UPID executor;
   TaskID taskID;

http://git-wip-us.apache.org/repos/asf/mesos/blob/fa57e4f9/src/launcher/default_executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/default_executor.cpp b/src/launcher/default_executor.cpp
index 10ca94c..b8a88ad 100644
--- a/src/launcher/default_executor.cpp
+++ b/src/launcher/default_executor.cpp
@@ -406,6 +406,7 @@ protected:
         Try<Owned<health::HealthChecker>> _checker =
           health::HealthChecker::create(
               task.health_check(),
+              launcherDirectory,
               self(),
               taskId,
               None(),

http://git-wip-us.apache.org/repos/asf/mesos/blob/fa57e4f9/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index 0544121..a3b43b5 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -447,6 +447,7 @@ protected:
       Try<Owned<health::HealthChecker>> _checker =
         health::HealthChecker::create(
             task->health_check(),
+            launcherDir,
             self(),
             task->task_id(),
             pid,