mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [05/16] mesos git commit: Added per-framework metrics for scheduler events.
Date Wed, 01 Aug 2018 20:24:22 GMT
Added per-framework metrics for scheduler events.

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


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

Branch: refs/heads/master
Commit: 96dea3659599f8165d159ca6b4e83bb8ae65effb
Parents: 133669a
Author: Greg Mann <greg@mesosphere.io>
Authored: Wed Aug 1 07:58:22 2018 -0700
Committer: Greg Mann <gregorywmann@gmail.com>
Committed: Wed Aug 1 13:07:54 2018 -0700

----------------------------------------------------------------------
 src/master/master.hpp  | 22 +++++++++++++++++++---
 src/master/metrics.cpp | 41 ++++++++++++++++++++++++++++++++++++++++-
 src/master/metrics.hpp |  5 +++++
 3 files changed, 64 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/96dea365/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 6c92d33..5875640 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -380,13 +380,16 @@ public:
               const Message& _heartbeatMessage,
               const HttpConnection& _http,
               const Duration& _interval,
-              const Option<Duration>& _delay = None())
+              const Option<Duration>& _delay = None(),
+              const Option<lambda::function<void(const Message&)>>&
+                _callback = None())
     : process::ProcessBase(process::ID::generate("heartbeater")),
       logMessage(_logMessage),
       heartbeatMessage(_heartbeatMessage),
       http(_http),
       interval(_interval),
-      delay(_delay) {}
+      delay(_delay),
+      callback(_callback) {}
 
 protected:
   void initialize() override
@@ -408,6 +411,10 @@ private:
     if (http.closed().isPending()) {
       VLOG(2) << "Sending heartbeat to " << logMessage;
 
+      if (callback.isSome()) {
+        callback.get()(heartbeatMessage);
+      }
+
       Message message(heartbeatMessage);
       http.send<Message, Event>(message);
     }
@@ -420,6 +427,7 @@ private:
   HttpConnection http;
   const Duration interval;
   const Option<Duration> delay;
+  const Option<lambda::function<void(const Message&)>> callback;
 };
 
 
@@ -2420,6 +2428,10 @@ struct Framework
                    << " framework " << *this;
     }
 
+    // TODO(gilbert): add a helper to transform `SchedulerDriver` API messages
+    // directly to v0 events.
+    metrics.incrementEvent(devolve(evolve(message)));
+
     if (http.isSome()) {
       if (!http->send(message)) {
         LOG(WARNING) << "Unable to send event to framework " << *this <<
":"
@@ -2905,7 +2917,11 @@ struct Framework
           "framework " + stringify(info.id()),
           event,
           http.get(),
-          DEFAULT_HEARTBEAT_INTERVAL);
+          DEFAULT_HEARTBEAT_INTERVAL,
+          None(),
+          [this](const scheduler::Event& event) {
+            this->metrics.incrementEvent(event);
+          });
 
     process::spawn(heartbeater->get());
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/96dea365/src/master/metrics.cpp
----------------------------------------------------------------------
diff --git a/src/master/metrics.cpp b/src/master/metrics.cpp
index c4252e0..8dbe1e9 100644
--- a/src/master/metrics.cpp
+++ b/src/master/metrics.cpp
@@ -555,7 +555,9 @@ FrameworkMetrics::FrameworkMetrics(const FrameworkInfo& _frameworkInfo)
     subscribed(
         getFrameworkMetricPrefix(frameworkInfo) + "subscribed"),
     calls(
-        getFrameworkMetricPrefix(frameworkInfo) + "calls")
+        getFrameworkMetricPrefix(frameworkInfo) + "calls"),
+    events(
+        getFrameworkMetricPrefix(frameworkInfo) + "events")
 {
   process::metrics::add(subscribed);
 
@@ -581,6 +583,29 @@ FrameworkMetrics::FrameworkMetrics(const FrameworkInfo& _frameworkInfo)
     call_types.put(type, counter);
     process::metrics::add(counter);
   }
+
+  // Add metrics for scheduler events.
+  process::metrics::add(events);
+  for (int index = 0;
+       index < scheduler::Event::Type_descriptor()->value_count();
+       index++) {
+    const google::protobuf::EnumValueDescriptor* descriptor =
+      scheduler::Event::Type_descriptor()->value(index);
+
+    const scheduler::Event::Type type =
+      static_cast<scheduler::Event::Type>(descriptor->number());
+
+    if (type == scheduler::Event::UNKNOWN) {
+      continue;
+    }
+
+    Counter counter = Counter(
+        getFrameworkMetricPrefix(frameworkInfo) + "events/" +
+        strings::lower(descriptor->name()));
+
+    event_types.put(type, counter);
+    process::metrics::add(counter);
+  }
 }
 
 
@@ -592,6 +617,11 @@ FrameworkMetrics::~FrameworkMetrics()
   foreachvalue (const Counter& counter, call_types) {
     process::metrics::remove(counter);
   }
+
+  process::metrics::remove(events);
+  foreachvalue (const Counter& counter, event_types) {
+    process::metrics::remove(counter);
+  }
 }
 
 
@@ -611,6 +641,15 @@ string getFrameworkMetricPrefix(const FrameworkInfo& frameworkInfo)
     "/" + stringify(frameworkInfo.id()) + "/";
 }
 
+
+void FrameworkMetrics::incrementEvent(const scheduler::Event& event)
+{
+  CHECK(event_types.contains(event.type()));
+
+  event_types.get(event.type()).get()++;
+  events++;
+}
+
 } // namespace master {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/96dea365/src/master/metrics.hpp
----------------------------------------------------------------------
diff --git a/src/master/metrics.hpp b/src/master/metrics.hpp
index ae4c703..abc6a7c 100644
--- a/src/master/metrics.hpp
+++ b/src/master/metrics.hpp
@@ -226,12 +226,17 @@ struct FrameworkMetrics
 
   void incrementCall(const scheduler::Call::Type& callType);
 
+  void incrementEvent(const scheduler::Event& event);
+
   const FrameworkInfo frameworkInfo;
 
   process::metrics::PushGauge subscribed;
 
   process::metrics::Counter calls;
   hashmap<scheduler::Call::Type, process::metrics::Counter> call_types;
+
+  process::metrics::Counter events;
+  hashmap<scheduler::Event::Type, process::metrics::Counter> event_types;
 };
 
 


Mime
View raw message