You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gr...@apache.org on 2018/12/14 21:32:10 UTC

[mesos] 06/06: Added gauge metric for operator event stream subscribers.

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

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

commit a2726e86570bf1e3f953ed56480b49c87eaee9c9
Author: Joseph Wu <jo...@mesosphere.io>
AuthorDate: Thu Dec 13 16:35:12 2018 -0800

    Added gauge metric for operator event stream subscribers.
    
    This metric "master/operator_event_stream_subscribers" returns
    the total number of subscribers to the master's operator event stream.
    
    Review: https://reviews.apache.org/r/69514/
---
 docs/monitoring.md         | 7 +++++++
 docs/operator-http-api.md  | 4 ++++
 src/master/master.cpp      | 6 ++++++
 src/master/metrics.cpp     | 6 ++++++
 src/master/metrics.hpp     | 2 ++
 src/tests/api_tests.cpp    | 9 +++++++++
 src/tests/master_tests.cpp | 3 +++
 7 files changed, 37 insertions(+)

diff --git a/docs/monitoring.md b/docs/monitoring.md
index 00c6ea9..2c2320a 100644
--- a/docs/monitoring.md
+++ b/docs/monitoring.md
@@ -979,6 +979,13 @@ event queue.
   <td>Number of messages in the event queue</td>
   <td>Gauge</td>
 </tr>
+<tr>
+  <td>
+  <code>master/operator_event_stream_subscribers</code>
+  </td>
+  <td>Number of subscribers to the operator event stream</td>
+  <td>Gauge</td>
+</tr>
 </table>
 
 #### Registrar
diff --git a/docs/operator-http-api.md b/docs/operator-http-api.md
index 6edf361..2d4a9b6 100644
--- a/docs/operator-http-api.md
+++ b/docs/operator-http-api.md
@@ -717,6 +717,10 @@ Content-Type: application/json
         "value": 0.0
       },
       {
+        "name": "master/operator_event_stream_subscribers",
+        "value": 0.0
+      },
+      {
         "name": "master/frameworks_active",
         "value": 0.0
       },
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 53aa7a1..6ae53c1 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -12139,6 +12139,9 @@ void Master::exited(const id::UUID& id)
             << " from the list of active subscribers";
 
   subscribers.subscribed.erase(id);
+
+  metrics->operator_event_stream_subscribers =
+    subscribers.subscribed.size();
 }
 
 
@@ -12168,6 +12171,9 @@ void Master::subscribe(
       http.streamId,
       Owned<Subscribers::Subscriber>(
           new Subscribers::Subscriber{http, principal}));
+
+  metrics->operator_event_stream_subscribers =
+    subscribers.subscribed.size();
 }
 
 
diff --git a/src/master/metrics.cpp b/src/master/metrics.cpp
index f69ed52..bb029d3 100644
--- a/src/master/metrics.cpp
+++ b/src/master/metrics.cpp
@@ -80,6 +80,8 @@ Metrics::Metrics(const Master& master)
     outstanding_offers(
         "master/outstanding_offers",
         defer(master, &Master::_outstanding_offers)),
+    operator_event_stream_subscribers(
+        "master/operator_event_stream_subscribers"),
     tasks_staging(
         "master/tasks_staging",
         defer(master, &Master::_tasks_staging)),
@@ -232,6 +234,8 @@ Metrics::Metrics(const Master& master)
 
   process::metrics::add(outstanding_offers);
 
+  process::metrics::add(operator_event_stream_subscribers);
+
   process::metrics::add(tasks_staging);
   process::metrics::add(tasks_starting);
   process::metrics::add(tasks_running);
@@ -383,6 +387,8 @@ Metrics::~Metrics()
 
   process::metrics::remove(outstanding_offers);
 
+  process::metrics::remove(operator_event_stream_subscribers);
+
   process::metrics::remove(tasks_staging);
   process::metrics::remove(tasks_starting);
   process::metrics::remove(tasks_running);
diff --git a/src/master/metrics.hpp b/src/master/metrics.hpp
index f6bb89d..eca48e6 100644
--- a/src/master/metrics.hpp
+++ b/src/master/metrics.hpp
@@ -60,6 +60,8 @@ struct Metrics
 
   process::metrics::PullGauge outstanding_offers;
 
+  process::metrics::PushGauge operator_event_stream_subscribers;
+
   // Task state metrics.
   process::metrics::PullGauge tasks_staging;
   process::metrics::PullGauge tasks_starting;
diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp
index 80104a7..b6064cd 100644
--- a/src/tests/api_tests.cpp
+++ b/src/tests/api_tests.cpp
@@ -3591,6 +3591,7 @@ TEST_P(MasterAPITest, MaxEventStreamSubscribers)
   Clock::pause();
 
   ContentType contentType = GetParam();
+  const string METRIC_NAME("master/operator_event_stream_subscribers");
 
   // Lower the max number of connections for this test.
   master::Flags masterFlags = CreateMasterFlags();
@@ -3656,6 +3657,10 @@ TEST_P(MasterAPITest, MaxEventStreamSubscribers)
   AWAIT_READY(event);
   ASSERT_EQ(v1::master::Event::HEARTBEAT, event->get().type());
 
+  // Check the relevant metric for total active subscribers.
+  JSON::Object metrics = Metrics();
+  EXPECT_EQ(2, metrics.values.at(METRIC_NAME));
+
   // Start a third connection.
   {
     // This is basically `http::streaming::post` unwrapped inside the
@@ -3715,6 +3720,10 @@ TEST_P(MasterAPITest, MaxEventStreamSubscribers)
   ASSERT_TRUE(event->isSome());
   ASSERT_EQ(v1::master::Event::HEARTBEAT, event->get().type());
 
+  // Check the metric again.
+  metrics = Metrics();
+  EXPECT_EQ(1, metrics.values.at(METRIC_NAME));
+
   // Start a fourth connection. This should be under the maximum
   // and should not cause any disconnections.
   Future<http::Response> response4 = http::streaming::post(
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index 3bff7a1..50b905b 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -2266,6 +2266,9 @@ TEST_F(MasterTest, MetricsInMetricsEndpoint)
 
   EXPECT_EQ(1u, snapshot.values.count("master/outstanding_offers"));
 
+  EXPECT_EQ(1u, snapshot.values.count(
+      "master/operator_event_stream_subscribers"));
+
   EXPECT_EQ(1u, snapshot.values.count("master/tasks_staging"));
   EXPECT_EQ(1u, snapshot.values.count("master/tasks_starting"));
   EXPECT_EQ(1u, snapshot.values.count("master/tasks_running"));