You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2019/08/15 19:18:18 UTC

[mesos] branch master updated: Added container transition times to the logs.

This is an automated email from the ASF dual-hosted git repository.

gilbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d5db35  Added container transition times to the logs.
5d5db35 is described below

commit 5d5db35082524daf8f7a9565f03e93035a83e727
Author: James Peach <jp...@apache.org>
AuthorDate: Thu Aug 15 12:18:06 2019 -0700

    Added container transition times to the logs.
    
    It's very useful to know directly how long a container spent in each
    state. Capture a timestamp at each state transition time and log the
    elapsed time in the corresponding state.
    
    Review: https://reviews.apache.org/r/71286/
---
 src/slave/containerizer/mesos/containerizer.cpp | 13 +++++++++----
 src/slave/containerizer/mesos/containerizer.hpp | 11 +++++++++--
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index 75e7cda..9030af1 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -1444,7 +1444,6 @@ Future<Containerizer::LaunchResult> MesosContainerizerProcess::launch(
   }
 
   Owned<Container> container(new Container());
-  container->state = PROVISIONING;
   container->config = containerConfig;
   container->resources = containerConfig.resources();
   container->directory = containerConfig.directory();
@@ -1457,6 +1456,7 @@ Future<Containerizer::LaunchResult> MesosContainerizerProcess::launch(
   }
 
   containers_.put(containerId, container);
+  transition(containerId, PROVISIONING);
 
   Future<Nothing> _prepare;
 
@@ -3313,13 +3313,16 @@ void MesosContainerizerProcess::transition(
 {
   CHECK(containers_.contains(containerId));
 
+  Time now = Clock::now();
   const Owned<Container>& container = containers_.at(containerId);
 
   LOG_BASED_ON_CLASS(container->containerClass())
     << "Transitioning the state of container " << containerId << " from "
-    << container->state << " to " << state;
+    << container->state << " to " << state
+    << " after " << (now - container->lastStateTransition);
 
   container->state = state;
+  container->lastStateTransition = now;
 }
 
 
@@ -3359,6 +3362,8 @@ std::ostream& operator<<(
     const MesosContainerizerProcess::State& state)
 {
   switch (state) {
+    case MesosContainerizerProcess::STARTING:
+      return stream << "STARTING";
     case MesosContainerizerProcess::PROVISIONING:
       return stream << "PROVISIONING";
     case MesosContainerizerProcess::PREPARING:
@@ -3371,9 +3376,9 @@ std::ostream& operator<<(
       return stream << "RUNNING";
     case MesosContainerizerProcess::DESTROYING:
       return stream << "DESTROYING";
-    default:
-      UNREACHABLE();
   }
+
+  UNREACHABLE();
 };
 
 } // namespace slave {
diff --git a/src/slave/containerizer/mesos/containerizer.hpp b/src/slave/containerizer/mesos/containerizer.hpp
index 271d632..6537f65 100644
--- a/src/slave/containerizer/mesos/containerizer.hpp
+++ b/src/slave/containerizer/mesos/containerizer.hpp
@@ -23,10 +23,12 @@
 
 #include <mesos/slave/isolator.hpp>
 
-#include <process/id.hpp>
+#include <process/clock.hpp>
 #include <process/http.hpp>
+#include <process/id.hpp>
 #include <process/sequence.hpp>
 #include <process/shared.hpp>
+#include <process/time.hpp>
 
 #include <process/metrics/counter.hpp>
 
@@ -228,6 +230,7 @@ public:
 private:
   enum State
   {
+    STARTING,
     PROVISIONING,
     PREPARING,
     ISOLATING,
@@ -350,7 +353,10 @@ private:
 
   struct Container
   {
-    Container() : sequence("mesos-container-status-updates") {}
+    Container()
+      : state(STARTING),
+        lastStateTransition(process::Clock::now()),
+        sequence("mesos-container-status-updates") {}
 
     // Promise for futures returned from wait().
     process::Promise<mesos::slave::ContainerTermination> termination;
@@ -422,6 +428,7 @@ private:
     Option<mesos::slave::ContainerLaunchInfo> launchInfo;
 
     State state;
+    process::Time lastStateTransition;
 
     // Used when `status` needs to be collected from isolators
     // associated with this container. `Sequence` allows us to