You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/03/23 01:55:49 UTC
[1/2] mesos git commit: Style and consistency cleanups for allocator
quota metrics.
Repository: mesos
Updated Branches:
refs/heads/master 9c97c787a -> 39e503a74
Style and consistency cleanups for allocator quota metrics.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/39e503a7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/39e503a7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/39e503a7
Branch: refs/heads/master
Commit: 39e503a74721605da77a16b6a650f4eac8c7bffa
Parents: 74b6b0e
Author: Benjamin Mahler <bm...@apache.org>
Authored: Tue Mar 22 16:57:36 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Mar 22 17:42:51 2016 -0700
----------------------------------------------------------------------
src/master/allocator/mesos/metrics.cpp | 52 ++++++++++++-----------------
1 file changed, 22 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/39e503a7/src/master/allocator/mesos/metrics.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/metrics.cpp b/src/master/allocator/mesos/metrics.cpp
index 58edb12..719adc7 100644
--- a/src/master/allocator/mesos/metrics.cpp
+++ b/src/master/allocator/mesos/metrics.cpp
@@ -106,7 +106,7 @@ Metrics::~Metrics()
}
-void Metrics::setQuota(const std::string& role, const Quota& quota)
+void Metrics::setQuota(const string& role, const Quota& quota)
{
CHECK(!quota_allocated.contains(role));
@@ -114,39 +114,31 @@ void Metrics::setQuota(const std::string& role, const Quota& quota)
hashmap<string, Gauge> guarantees;
foreach (const Resource& resource, quota.info.guarantee()) {
- // And gauges for the currently offered or allocated
- // resources under quota.
- {
- Gauge gauge = Gauge(
- "allocator/mesos/quota"
- "/roles/" + role +
- "/resources/" + resource.name() +
- "/offered_or_allocated",
- process::defer(
- allocator,
+ CHECK_EQ(Value::SCALAR, resource.type());
+ double value = resource.scalar().value();
+
+ Gauge guarantee = Gauge(
+ "allocator/mesos/quota"
+ "/roles/" + role +
+ "/resources/" + resource.name() +
+ "/guarantee",
+ process::defer([value]() { return value; }));
+
+ Gauge offered_or_allocated(
+ "allocator/mesos/quota"
+ "/roles/" + role +
+ "/resources/" + resource.name() +
+ "/offered_or_allocated",
+ defer(allocator,
&HierarchicalAllocatorProcess::_quota_allocated,
role,
resource.name()));
- allocated.put(resource.name(), gauge);
- process::metrics::add(gauge);
- }
+ guarantees.put(resource.name(), guarantee);
+ allocated.put(resource.name(), offered_or_allocated);
- // Add gauges for the quota resource guarantees.
- {
- CHECK_EQ(Value::SCALAR, resource.type());
- double value = resource.scalar().value();
-
- Gauge gauge = Gauge(
- "allocator/mesos/quota"
- "/roles/" + role +
- "/resources/" + resource.name() +
- "/guarantee",
- process::defer([value]() { return value; }));
-
- guarantees.put(resource.name(), gauge);
- process::metrics::add(gauge);
- }
+ process::metrics::add(guarantee);
+ process::metrics::add(offered_or_allocated);
}
quota_allocated[role] = allocated;
@@ -154,7 +146,7 @@ void Metrics::setQuota(const std::string& role, const Quota& quota)
}
-void Metrics::removeQuota(const std::string& role)
+void Metrics::removeQuota(const string& role)
{
CHECK(quota_allocated.contains(role));
[2/2] mesos git commit: Added allocator metrics for total and
allocated/offered resources.
Posted by bm...@apache.org.
Added allocator metrics for total and allocated/offered resources.
Review: https://reviews.apache.org/r/43880
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/74b6b0ee
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/74b6b0ee
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/74b6b0ee
Branch: refs/heads/master
Commit: 74b6b0ee915759b96a47dcbd1fe1189edac08dec
Parents: 9c97c78
Author: Benjamin Mahler <bm...@apache.org>
Authored: Tue Mar 22 16:56:26 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Mar 22 17:42:51 2016 -0700
----------------------------------------------------------------------
docs/monitoring.md | 42 +++++++++++++++
src/master/allocator/mesos/hierarchical.cpp | 29 ++++++++++
src/master/allocator/mesos/hierarchical.hpp | 4 ++
src/master/allocator/mesos/metrics.cpp | 38 +++++++++++++
src/master/allocator/mesos/metrics.hpp | 7 +++
src/tests/hierarchical_allocator_tests.cpp | 68 ++++++++++++++++++++++++
6 files changed, 188 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/74b6b0ee/docs/monitoring.md
----------------------------------------------------------------------
diff --git a/docs/monitoring.md b/docs/monitoring.md
index cdc91c3..a746682 100644
--- a/docs/monitoring.md
+++ b/docs/monitoring.md
@@ -888,6 +888,48 @@ and resource allocations in the allocator.
<td>Amount of resources guaranteed for a role via quota</td>
<td>Gauge</td>
</tr>
+<tr>
+ <td>
+ <code>allocator/mesos/resources/cpus/offered_or_allocated</code>
+ </td>
+ <td>Number of CPUs offered or allocated</td>
+ <td>Gauge</td>
+</tr>
+<tr>
+ <td>
+ <code>allocator/mesos/resources/cpus/total</code>
+ </td>
+ <td>Number of CPUs</td>
+ <td>Gauge</td>
+</tr>
+<tr>
+ <td>
+ <code>allocator/mesos/resources/disk/offered_or_allocated</code>
+ </td>
+ <td>Allocated or offered disk space in MB</td>
+ <td>Gauge</td>
+</tr>
+<tr>
+ <td>
+ <code>allocator/mesos/resources/disk/total</code>
+ </td>
+ <td>Total disk space in MB</td>
+ <td>Gauge</td>
+</tr>
+<tr>
+ <td>
+ <code>allocator/mesos/resources/mem/offered_or_allocated</code>
+ </td>
+ <td>Allocated or offered memory in MB</td>
+ <td>Gauge</td>
+</tr>
+<tr>
+ <td>
+ <code>allocator/mesos/resources/mem/total</code>
+ </td>
+ <td>Total memory in MB</td>
+ <td>Gauge</td>
+</tr>
</table>
### Basic Alerts
http://git-wip-us.apache.org/repos/asf/mesos/blob/74b6b0ee/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index e3266b3..800496a 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -1688,6 +1688,35 @@ bool HierarchicalAllocatorProcess::allocatable(
}
+double HierarchicalAllocatorProcess::_resources_offered_or_allocated(
+ const string& resource)
+{
+ double offered_or_allocated = 0;
+
+ foreachvalue (const Slave& slave, slaves) {
+ Option<Value::Scalar> value =
+ slave.allocated.get<Value::Scalar>(resource);
+
+ if (value.isSome()) {
+ offered_or_allocated += value->value();
+ }
+ }
+
+ return offered_or_allocated;
+}
+
+
+double HierarchicalAllocatorProcess::_resources_total(
+ const string& resource)
+{
+ Option<Value::Scalar> total =
+ roleSorter->totalScalarQuantities()
+ .get<Value::Scalar>(resource);
+
+ return total.isSome() ? total->value() : 0;
+}
+
+
double HierarchicalAllocatorProcess::_quota_allocated(
const string& role,
const string& resource)
http://git-wip-us.apache.org/repos/asf/mesos/blob/74b6b0ee/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 4fb019c..e4604f4 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -287,6 +287,10 @@ protected:
return static_cast<double>(eventCount<process::DispatchEvent>());
}
+ double _resources_total(const std::string& resource);
+
+ double _resources_offered_or_allocated(const std::string& resource);
+
double _quota_allocated(
const std::string& role,
const std::string& resource);
http://git-wip-us.apache.org/repos/asf/mesos/blob/74b6b0ee/src/master/allocator/mesos/metrics.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/metrics.cpp b/src/master/allocator/mesos/metrics.cpp
index 9c42e78..58edb12 100644
--- a/src/master/allocator/mesos/metrics.cpp
+++ b/src/master/allocator/mesos/metrics.cpp
@@ -24,6 +24,7 @@
#include "master/allocator/mesos/metrics.hpp"
using std::string;
+using std::vector;
using process::metrics::Gauge;
@@ -46,6 +47,35 @@ Metrics::Metrics(const HierarchicalAllocatorProcess& _allocator)
{
process::metrics::add(event_queue_dispatches);
process::metrics::add(event_queue_dispatches_);
+
+ // Create and install gauges for the total and allocated
+ // amount of standard scalar resources.
+ //
+ // TODO(bbannier) Add support for more than just scalar resources.
+ // TODO(bbannier) Simplify this once MESOS-3214 is fixed.
+ // TODO(dhamon): Set these up dynamically when adding a slave based on the
+ // resources the slave exposes.
+ string resources[] = {"cpus", "mem", "disk"};
+
+ foreach (const string& resource, resources) {
+ Gauge total(
+ "allocator/mesos/resources/" + resource + "/total",
+ defer(allocator,
+ &HierarchicalAllocatorProcess::_resources_total,
+ resource));
+
+ Gauge offered_or_allocated(
+ "allocator/mesos/resources/" + resource + "/offered_or_allocated",
+ defer(allocator,
+ &HierarchicalAllocatorProcess::_resources_offered_or_allocated,
+ resource));
+
+ resources_total.push_back(total);
+ resources_offered_or_allocated.push_back(offered_or_allocated);
+
+ process::metrics::add(total);
+ process::metrics::add(offered_or_allocated);
+ }
}
@@ -54,6 +84,14 @@ Metrics::~Metrics()
process::metrics::remove(event_queue_dispatches);
process::metrics::remove(event_queue_dispatches_);
+ foreach (const Gauge& gauge, resources_total) {
+ process::metrics::remove(gauge);
+ }
+
+ foreach (const Gauge& gauge, resources_offered_or_allocated) {
+ process::metrics::remove(gauge);
+ }
+
foreachkey(const string& role, quota_allocated) {
foreachvalue(const Gauge& gauge, quota_allocated[role]) {
process::metrics::remove(gauge);
http://git-wip-us.apache.org/repos/asf/mesos/blob/74b6b0ee/src/master/allocator/mesos/metrics.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/metrics.hpp b/src/master/allocator/mesos/metrics.hpp
index 90260a2..2c5ef3a 100644
--- a/src/master/allocator/mesos/metrics.hpp
+++ b/src/master/allocator/mesos/metrics.hpp
@@ -18,6 +18,7 @@
#define __MASTER_ALLOCATOR_MESOS_METRICS_HPP__
#include <string>
+#include <vector>
#include <process/metrics/gauge.hpp>
@@ -54,6 +55,12 @@ struct Metrics
// uses a name deprecated in 0.29. This metric should be removed with 0.30.
process::metrics::Gauge event_queue_dispatches_;
+ // Gauges for the total amount of each resource in the cluster.
+ std::vector<process::metrics::Gauge> resources_total;
+
+ // Gauges for the allocated amount of each resource in the cluster.
+ std::vector<process::metrics::Gauge> resources_offered_or_allocated;
+
// Gauges for the per-role quota allocation for each resource.
hashmap<std::string, hashmap<std::string, process::metrics::Gauge>>
quota_allocated;
http://git-wip-us.apache.org/repos/asf/mesos/blob/74b6b0ee/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 2a0a9be..55c2d52 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -2462,6 +2462,74 @@ TEST_F(HierarchicalAllocatorTest, DeactivateAndReactivateFramework)
}
+// This test checks that total and allocator resources
+// are correctly reflected in the metrics endpoint.
+TEST_F(HierarchicalAllocatorTest, ResourceMetrics)
+{
+ // Pausing the clock is not necessary, but ensures that the test
+ // doesn't rely on the batch allocation in the allocator, which
+ // would slow down the test.
+ Clock::pause();
+
+ initialize();
+
+ SlaveInfo agent = createSlaveInfo("cpus:2;mem:1024;disk:0");
+ allocator->addSlave(agent.id(), agent, None(), agent.resources(), {});
+ Clock::settle();
+
+ JSON::Object expected;
+
+ // No frameworks are registered yet, so nothing is allocated.
+ expected.values = {
+ {"allocator/mesos/resources/cpus/total", 2},
+ {"allocator/mesos/resources/mem/total", 1024},
+ {"allocator/mesos/resources/disk/total", 0},
+ {"allocator/mesos/resources/cpus/offered_or_allocated", 0},
+ {"allocator/mesos/resources/mem/offered_or_allocated", 0},
+ {"allocator/mesos/resources/disk/offered_or_allocated", 0},
+ };
+
+ JSON::Value metrics = Metrics();
+
+ EXPECT_TRUE(metrics.contains(expected));
+
+ FrameworkInfo framework = createFrameworkInfo("role1");
+ allocator->addFramework(framework.id(), framework, {});
+ Clock::settle();
+
+ // All of the resources should be offered.
+ expected.values = {
+ {"allocator/mesos/resources/cpus/total", 2},
+ {"allocator/mesos/resources/mem/total", 1024},
+ {"allocator/mesos/resources/disk/total", 0},
+ {"allocator/mesos/resources/cpus/offered_or_allocated", 2},
+ {"allocator/mesos/resources/mem/offered_or_allocated", 1024},
+ {"allocator/mesos/resources/disk/offered_or_allocated", 0},
+ };
+
+ metrics = Metrics();
+
+ EXPECT_TRUE(metrics.contains(expected));
+
+ allocator->removeSlave(agent.id());
+ Clock::settle();
+
+ // No frameworks are registered yet, so nothing is allocated.
+ expected.values = {
+ {"allocator/mesos/resources/cpus/total", 0},
+ {"allocator/mesos/resources/mem/total", 0},
+ {"allocator/mesos/resources/disk/total", 0},
+ {"allocator/mesos/resources/cpus/offered_or_allocated", 0},
+ {"allocator/mesos/resources/mem/offered_or_allocated", 0},
+ {"allocator/mesos/resources/disk/offered_or_allocated", 0},
+ };
+
+ metrics = Metrics();
+
+ EXPECT_TRUE(metrics.contains(expected));
+}
+
+
// This test ensures that resource allocation is done according to each role's
// weight. This is done by having six agents and three frameworks and making
// sure each framework gets the appropriate number of resources.