This is an automated email from the ASF dual-hosted git repository. mzhu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 4bdbd8e7da5063d55726b628b5e0d31c79650d3f Author: Meng Zhu <[email protected]> AuthorDate: Thu Jun 6 15:58:05 2019 -0700 Added `Metrics::updateQuota` for quota metrics. This intends to replace the existing ``Metrics::setQuota` and `Metrics::remove` calls. Currently, it only tracks guarantees. Need to add limits metrics. Review: https://reviews.apache.org/r/70802 --- src/master/allocator/mesos/metrics.cpp | 59 ++++++++++++++++++++++++++++++++++ src/master/allocator/mesos/metrics.hpp | 3 ++ 2 files changed, 62 insertions(+) diff --git a/src/master/allocator/mesos/metrics.cpp b/src/master/allocator/mesos/metrics.cpp index 5533eb9..b61a39b 100644 --- a/src/master/allocator/mesos/metrics.cpp +++ b/src/master/allocator/mesos/metrics.cpp @@ -139,6 +139,7 @@ void Metrics::setQuota(const string& role, const Quota& quota) CHECK_EQ(Value::SCALAR, resource.type()); double value = resource.scalar().value(); + // TODO(mzhu): use PushGauge for guarantees. PullGauge guarantee = PullGauge( "allocator/mesos/quota" "/roles/" + role + @@ -146,6 +147,8 @@ void Metrics::setQuota(const string& role, const Quota& quota) "/guarantee", process::defer([value]() { return value; })); + // TODO(mzhu): expose this for every role, including roles + // with default quota. PullGauge offered_or_allocated( "allocator/mesos/quota" "/roles/" + role + @@ -186,6 +189,62 @@ void Metrics::removeQuota(const string& role) } +// TODO(mzhu): This currently only updates quota guarantees. +// Add metrics for quota limits as well. +void Metrics::updateQuota(const string& role, const Quota2& quota) +{ + // This is the "remove" case where the role's quota + // is set to the default. + if (quota.guarantees == DEFAULT_QUOTA.guarantees) { + foreachvalue (const PullGauge& gauge, quota_allocated[role]) { + process::metrics::remove(gauge); + } + + foreachvalue (const PullGauge& gauge, quota_guarantee[role]) { + process::metrics::remove(gauge); + } + + quota_allocated.erase(role); + quota_guarantee.erase(role); + + return; + } + + hashmap<string, PullGauge> allocated; + hashmap<string, PullGauge> guarantees; + + foreach (auto& quantity, quota.guarantees) { + double value = quantity.second.value(); + + PullGauge guarantee = PullGauge( + "allocator/mesos/quota" + "/roles/" + role + + "/resources/" + quantity.first + + "/guarantee", + process::defer([value]() { return value; })); + + PullGauge offered_or_allocated( + "allocator/mesos/quota" + "/roles/" + role + + "/resources/" + quantity.first + + "/offered_or_allocated", + defer(allocator, + &HierarchicalAllocatorProcess::_quota_allocated, + role, + quantity.first)); + + guarantees.put(quantity.first, guarantee); + allocated.put(quantity.first, offered_or_allocated); + + process::metrics::add(guarantee); + process::metrics::add(offered_or_allocated); + } + + quota_allocated[role] = allocated; + quota_guarantee[role] = guarantees; +} + + void Metrics::addRole(const string& role) { CHECK(!offer_filters_active.contains(role)); diff --git a/src/master/allocator/mesos/metrics.hpp b/src/master/allocator/mesos/metrics.hpp index a26278a..a0953b0 100644 --- a/src/master/allocator/mesos/metrics.hpp +++ b/src/master/allocator/mesos/metrics.hpp @@ -48,9 +48,12 @@ struct Metrics ~Metrics(); + // TODO(mzhu): Remove these in favor of `updateQuota`. void setQuota(const std::string& role, const Quota& quota); void removeQuota(const std::string& role); + void updateQuota(const std::string& role, const Quota2& quota); + void addRole(const std::string& role); void removeRole(const std::string& role);
