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

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

commit 0e5d6d7633b8f64ecd89e74e8003eb89b0ef0b21
Author: Chun-Hung Hsiao <[email protected]>
AuthorDate: Mon Apr 1 23:23:35 2019 -0700

    Moved CSI plugin metrics out from SLRP metrics.
    
    This is a preliminary refactor patch for `ServiceManager` introduced in
    the next patch. The CSI plugin metrics are moved out from SLRP metrics
    object so the metrics can be accessed by `ServiceManager`. However, SLRP
    still owns these metrics for now. Eventually we would like to decouple
    metrics lifecycles from SLRP lifecycles.
    
    Review: https://reviews.apache.org/r/70245/
---
 src/CMakeLists.txt                                 |   1 +
 src/Makefile.am                                    |   2 +
 src/csi/metrics.cpp                                | 126 +++++++++++++++++++++
 src/csi/metrics.hpp                                |  46 ++++++++
 src/resource_provider/storage/provider.cpp         |  84 +-------------
 src/resource_provider/storage/provider_process.hpp |  11 +-
 6 files changed, 179 insertions(+), 91 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3397c3b..53b0e7b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -241,6 +241,7 @@ set(COMMON_SRC
 
 set(CSI_SRC
   csi/client.cpp
+  csi/metrics.cpp
   csi/paths.cpp
   csi/rpc.cpp
   csi/utils.cpp)
diff --git a/src/Makefile.am b/src/Makefile.am
index 7c2131a..7ef8825 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1554,6 +1554,8 @@ noinst_LTLIBRARIES += libcsi.la
 libcsi_la_SOURCES =                                                    \
   csi/client.cpp                                                       \
   csi/client.hpp                                                       \
+  csi/metrics.cpp                                                      \
+  csi/metrics.hpp                                                      \
   csi/paths.cpp                                                                
\
   csi/paths.hpp                                                                
\
   csi/rpc.cpp                                                          \
diff --git a/src/csi/metrics.cpp b/src/csi/metrics.cpp
new file mode 100644
index 0000000..1ef591e
--- /dev/null
+++ b/src/csi/metrics.cpp
@@ -0,0 +1,126 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "csi/metrics.hpp"
+
+#include <vector>
+
+#include <process/metrics/metrics.hpp>
+
+#include <stout/foreach.hpp>
+#include <stout/stringify.hpp>
+
+using std::string;
+using std::vector;
+
+using process::metrics::Counter;
+using process::metrics::PushGauge;
+
+namespace mesos {
+namespace csi {
+
+Metrics::Metrics(const string& prefix)
+  : csi_plugin_container_terminations(
+        prefix + "csi_plugin/container_terminations")
+{
+  process::metrics::add(csi_plugin_container_terminations);
+
+  vector<csi::v0::RPC> rpcs;
+
+  // NOTE: We use a switch statement here as a compile-time sanity check so we
+  // won't forget to add metrics for new RPCs in the future. Since each case
+  // falls through intentionally, every RPC will be added.
+  csi::v0::RPC firstRpc = csi::v0::GET_PLUGIN_INFO;
+  switch (firstRpc) {
+    case csi::v0::GET_PLUGIN_INFO:
+      rpcs.push_back(csi::v0::GET_PLUGIN_INFO);
+    case csi::v0::GET_PLUGIN_CAPABILITIES:
+      rpcs.push_back(csi::v0::GET_PLUGIN_CAPABILITIES);
+    case csi::v0::PROBE:
+      rpcs.push_back(csi::v0::PROBE);
+    case csi::v0::CREATE_VOLUME:
+      rpcs.push_back(csi::v0::CREATE_VOLUME);
+    case csi::v0::DELETE_VOLUME:
+      rpcs.push_back(csi::v0::DELETE_VOLUME);
+    case csi::v0::CONTROLLER_PUBLISH_VOLUME:
+      rpcs.push_back(csi::v0::CONTROLLER_PUBLISH_VOLUME);
+    case csi::v0::CONTROLLER_UNPUBLISH_VOLUME:
+      rpcs.push_back(csi::v0::CONTROLLER_UNPUBLISH_VOLUME);
+    case csi::v0::VALIDATE_VOLUME_CAPABILITIES:
+      rpcs.push_back(csi::v0::VALIDATE_VOLUME_CAPABILITIES);
+    case csi::v0::LIST_VOLUMES:
+      rpcs.push_back(csi::v0::LIST_VOLUMES);
+    case csi::v0::GET_CAPACITY:
+      rpcs.push_back(csi::v0::GET_CAPACITY);
+    case csi::v0::CONTROLLER_GET_CAPABILITIES:
+      rpcs.push_back(csi::v0::CONTROLLER_GET_CAPABILITIES);
+    case csi::v0::NODE_STAGE_VOLUME:
+      rpcs.push_back(csi::v0::NODE_STAGE_VOLUME);
+    case csi::v0::NODE_UNSTAGE_VOLUME:
+      rpcs.push_back(csi::v0::NODE_UNSTAGE_VOLUME);
+    case csi::v0::NODE_PUBLISH_VOLUME:
+      rpcs.push_back(csi::v0::NODE_PUBLISH_VOLUME);
+    case csi::v0::NODE_UNPUBLISH_VOLUME:
+      rpcs.push_back(csi::v0::NODE_UNPUBLISH_VOLUME);
+    case csi::v0::NODE_GET_ID:
+      rpcs.push_back(csi::v0::NODE_GET_ID);
+    case csi::v0::NODE_GET_CAPABILITIES:
+      rpcs.push_back(csi::v0::NODE_GET_CAPABILITIES);
+  }
+
+  foreach (const csi::v0::RPC& rpc, rpcs) {
+    const string name = stringify(rpc);
+
+    csi_plugin_rpcs_pending.put(
+        rpc, PushGauge(prefix + "csi_plugin/rpcs/" + name + "/pending"));
+    csi_plugin_rpcs_successes.put(
+        rpc, Counter(prefix + "csi_plugin/rpcs/" + name + "/successes"));
+    csi_plugin_rpcs_errors.put(
+        rpc, Counter(prefix + "csi_plugin/rpcs/" + name + "/errors"));
+    csi_plugin_rpcs_cancelled.put(
+        rpc, Counter(prefix + "csi_plugin/rpcs/" + name + "/cancelled"));
+
+    process::metrics::add(csi_plugin_rpcs_pending.at(rpc));
+    process::metrics::add(csi_plugin_rpcs_successes.at(rpc));
+    process::metrics::add(csi_plugin_rpcs_errors.at(rpc));
+    process::metrics::add(csi_plugin_rpcs_cancelled.at(rpc));
+  }
+}
+
+
+Metrics::~Metrics()
+{
+  process::metrics::remove(csi_plugin_container_terminations);
+
+  foreachvalue (const PushGauge& gauge, csi_plugin_rpcs_pending) {
+    process::metrics::remove(gauge);
+  }
+
+  foreachvalue (const Counter& counter, csi_plugin_rpcs_successes) {
+    process::metrics::remove(counter);
+  }
+
+  foreachvalue (const Counter& counter, csi_plugin_rpcs_errors) {
+    process::metrics::remove(counter);
+  }
+
+  foreachvalue (const Counter& counter, csi_plugin_rpcs_cancelled) {
+    process::metrics::remove(counter);
+  }
+}
+
+} // namespace csi {
+} // namespace mesos {
diff --git a/src/csi/metrics.hpp b/src/csi/metrics.hpp
new file mode 100644
index 0000000..1892cdd
--- /dev/null
+++ b/src/csi/metrics.hpp
@@ -0,0 +1,46 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __CSI_METRICS_HPP__
+#define __CSI_METRICS_HPP__
+
+#include <string>
+
+#include <process/metrics/counter.hpp>
+#include <process/metrics/push_gauge.hpp>
+
+#include "csi/rpc.hpp"
+
+namespace mesos {
+namespace csi {
+
+struct Metrics
+{
+  explicit Metrics(const std::string& prefix);
+
+  ~Metrics();
+
+  process::metrics::Counter csi_plugin_container_terminations;
+  hashmap<csi::v0::RPC, process::metrics::PushGauge> csi_plugin_rpcs_pending;
+  hashmap<csi::v0::RPC, process::metrics::Counter> csi_plugin_rpcs_successes;
+  hashmap<csi::v0::RPC, process::metrics::Counter> csi_plugin_rpcs_errors;
+  hashmap<csi::v0::RPC, process::metrics::Counter> csi_plugin_rpcs_cancelled;
+};
+
+} // namespace csi {
+} // namespace mesos {
+
+#endif // __CSI_METRICS_HPP__
diff --git a/src/resource_provider/storage/provider.cpp 
b/src/resource_provider/storage/provider.cpp
index cc7944c..f307f8e 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -77,6 +77,7 @@
 #include "common/resources_utils.hpp"
 
 #include "csi/client.hpp"
+#include "csi/metrics.hpp"
 #include "csi/paths.hpp"
 #include "csi/rpc.hpp"
 #include "csi/state.hpp"
@@ -3647,71 +3648,8 @@ void 
StorageLocalResourceProviderProcess::sendOperationStatusUpdate(
 
 
 StorageLocalResourceProviderProcess::Metrics::Metrics(const string& prefix)
-  : csi_plugin_container_terminations(
-        prefix + "csi_plugin/container_terminations")
+  : csi::Metrics(prefix)
 {
-  process::metrics::add(csi_plugin_container_terminations);
-
-  vector<csi::v0::RPC> rpcs;
-
-  // NOTE: We use a switch statement here as a compile-time sanity check so we
-  // won't forget to add metrics for new RPCs in the future.
-  csi::v0::RPC firstRpc = csi::v0::GET_PLUGIN_INFO;
-  switch (firstRpc) {
-    case csi::v0::GET_PLUGIN_INFO:
-      rpcs.push_back(csi::v0::GET_PLUGIN_INFO);
-    case csi::v0::GET_PLUGIN_CAPABILITIES:
-      rpcs.push_back(csi::v0::GET_PLUGIN_CAPABILITIES);
-    case csi::v0::PROBE:
-      rpcs.push_back(csi::v0::PROBE);
-    case csi::v0::CREATE_VOLUME:
-      rpcs.push_back(csi::v0::CREATE_VOLUME);
-    case csi::v0::DELETE_VOLUME:
-      rpcs.push_back(csi::v0::DELETE_VOLUME);
-    case csi::v0::CONTROLLER_PUBLISH_VOLUME:
-      rpcs.push_back(csi::v0::CONTROLLER_PUBLISH_VOLUME);
-    case csi::v0::CONTROLLER_UNPUBLISH_VOLUME:
-      rpcs.push_back(csi::v0::CONTROLLER_UNPUBLISH_VOLUME);
-    case csi::v0::VALIDATE_VOLUME_CAPABILITIES:
-      rpcs.push_back(csi::v0::VALIDATE_VOLUME_CAPABILITIES);
-    case csi::v0::LIST_VOLUMES:
-      rpcs.push_back(csi::v0::LIST_VOLUMES);
-    case csi::v0::GET_CAPACITY:
-      rpcs.push_back(csi::v0::GET_CAPACITY);
-    case csi::v0::CONTROLLER_GET_CAPABILITIES:
-      rpcs.push_back(csi::v0::CONTROLLER_GET_CAPABILITIES);
-    case csi::v0::NODE_STAGE_VOLUME:
-      rpcs.push_back(csi::v0::NODE_STAGE_VOLUME);
-    case csi::v0::NODE_UNSTAGE_VOLUME:
-      rpcs.push_back(csi::v0::NODE_UNSTAGE_VOLUME);
-    case csi::v0::NODE_PUBLISH_VOLUME:
-      rpcs.push_back(csi::v0::NODE_PUBLISH_VOLUME);
-    case csi::v0::NODE_UNPUBLISH_VOLUME:
-      rpcs.push_back(csi::v0::NODE_UNPUBLISH_VOLUME);
-    case csi::v0::NODE_GET_ID:
-      rpcs.push_back(csi::v0::NODE_GET_ID);
-    case csi::v0::NODE_GET_CAPABILITIES:
-      rpcs.push_back(csi::v0::NODE_GET_CAPABILITIES);
-  }
-
-  foreach (const csi::v0::RPC& rpc, rpcs) {
-    const string name = stringify(rpc);
-
-    csi_plugin_rpcs_pending.put(
-        rpc, PushGauge(prefix + "csi_plugin/rpcs/" + name + "/pending"));
-    csi_plugin_rpcs_successes.put(
-        rpc, Counter(prefix + "csi_plugin/rpcs/" + name + "/successes"));
-    csi_plugin_rpcs_errors.put(
-        rpc, Counter(prefix + "csi_plugin/rpcs/" + name + "/errors"));
-    csi_plugin_rpcs_cancelled.put(
-        rpc, Counter(prefix + "csi_plugin/rpcs/" + name + "/cancelled"));
-
-    process::metrics::add(csi_plugin_rpcs_pending.at(rpc));
-    process::metrics::add(csi_plugin_rpcs_successes.at(rpc));
-    process::metrics::add(csi_plugin_rpcs_errors.at(rpc));
-    process::metrics::add(csi_plugin_rpcs_cancelled.at(rpc));
-  }
-
   vector<Offer::Operation::Type> operationTypes;
 
   // NOTE: We use a switch statement here as a compile-time sanity check so we
@@ -3772,24 +3710,6 @@ 
StorageLocalResourceProviderProcess::Metrics::Metrics(const string& prefix)
 
 StorageLocalResourceProviderProcess::Metrics::~Metrics()
 {
-  process::metrics::remove(csi_plugin_container_terminations);
-
-  foreachvalue (const PushGauge& gauge, csi_plugin_rpcs_pending) {
-    process::metrics::remove(gauge);
-  }
-
-  foreachvalue (const Counter& counter, csi_plugin_rpcs_successes) {
-    process::metrics::remove(counter);
-  }
-
-  foreachvalue (const Counter& counter, csi_plugin_rpcs_errors) {
-    process::metrics::remove(counter);
-  }
-
-  foreachvalue (const Counter& counter, csi_plugin_rpcs_cancelled) {
-    process::metrics::remove(counter);
-  }
-
   foreachvalue (const PushGauge& gauge, operations_pending) {
     process::metrics::remove(gauge);
   }
diff --git a/src/resource_provider/storage/provider_process.hpp 
b/src/resource_provider/storage/provider_process.hpp
index a5536b3..8640fbc 100644
--- a/src/resource_provider/storage/provider_process.hpp
+++ b/src/resource_provider/storage/provider_process.hpp
@@ -54,6 +54,7 @@
 #include <stout/uuid.hpp>
 
 #include "csi/client.hpp"
+#include "csi/metrics.hpp"
 #include "csi/rpc.hpp"
 #include "csi/state.hpp"
 #include "csi/utils.hpp"
@@ -399,19 +400,11 @@ private:
   // that any reconciliation waits for these operations to finish.
   process::Sequence sequence;
 
-  struct Metrics
+  struct Metrics : public csi::Metrics
   {
     explicit Metrics(const std::string& prefix);
     ~Metrics();
 
-    // CSI plugin metrics.
-    process::metrics::Counter csi_plugin_container_terminations;
-    hashmap<csi::v0::RPC, process::metrics::PushGauge> csi_plugin_rpcs_pending;
-    hashmap<csi::v0::RPC, process::metrics::Counter> csi_plugin_rpcs_successes;
-    hashmap<csi::v0::RPC, process::metrics::Counter> csi_plugin_rpcs_errors;
-    hashmap<csi::v0::RPC, process::metrics::Counter> csi_plugin_rpcs_cancelled;
-
-    // Operation state metrics.
     hashmap<Offer::Operation::Type, process::metrics::PushGauge>
       operations_pending;
     hashmap<Offer::Operation::Type, process::metrics::Counter>

Reply via email to