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 442acc772a38473bf16167379b98d0df126c3262 Author: Andrei Sekretenko <[email protected]> AuthorDate: Fri Oct 4 18:15:01 2019 -0400 Added quota consumption metrics to the hierarchial allocator. Review: https://reviews.apache.org/r/71490/ --- src/master/allocator/mesos/hierarchical.cpp | 12 ++++++++++++ src/master/allocator/mesos/hierarchical.hpp | 9 +++++++++ src/master/allocator/mesos/metrics.cpp | 7 +++++++ src/master/allocator/mesos/metrics.hpp | 3 +++ 4 files changed, 31 insertions(+) diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp index 29f650a..0854956 100644 --- a/src/master/allocator/mesos/hierarchical.cpp +++ b/src/master/allocator/mesos/hierarchical.cpp @@ -340,6 +340,14 @@ bool RoleTree::tryRemove(const std::string& role) } +void RoleTree::updateQuotaConsumedMetric(const Role* role) +{ + if (metrics.isSome()) { + (*metrics)->updateConsumed(role->role, role->quotaConsumed()); + } +} + + void RoleTree::trackReservations(const Resources& resources) { foreach (const Resource& r, resources.scalars()) { @@ -354,6 +362,7 @@ void RoleTree::trackReservations(const Resources& resources) // Create new role tree node if necessary. for (; current != nullptr; current = current->parent) { current->reservationScalarQuantities_ += quantities; + updateQuotaConsumedMetric(current); } } } @@ -374,6 +383,7 @@ void RoleTree::untrackReservations(const Resources& resources) current = current->parent) { CHECK_CONTAINS(current->reservationScalarQuantities_, quantities); current->reservationScalarQuantities_ -= quantities; + updateQuotaConsumedMetric(current); } tryRemove(reservationRole); @@ -393,6 +403,7 @@ void RoleTree::trackAllocated(const Resources& resources_) for (Role* current = &(roles_.at(role)); current != nullptr; current = current->parent) { current->allocatedScalars_ += resources; + updateQuotaConsumedMetric(current); } } } @@ -411,6 +422,7 @@ void RoleTree::untrackAllocated(const Resources& resources_) current = current->parent) { CHECK_CONTAINS(current->allocatedScalars_, resources); current->allocatedScalars_ -= resources; + updateQuotaConsumedMetric(current); } } } diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp index da22603..647718d 100644 --- a/src/master/allocator/mesos/hierarchical.hpp +++ b/src/master/allocator/mesos/hierarchical.hpp @@ -131,6 +131,13 @@ public: const Quota& quota() const { return quota_; } + ResourceQuantities quotaConsumed() const + { + return ResourceQuantities::fromScalarResources( + allocatedScalars_.unreserved().nonRevocable()) + + reservationScalarQuantities_; + } + double weight() const { return weight_; } bool isEmpty() const @@ -269,6 +276,8 @@ private: // Otherwise the "tracking only non-empty" tree invariant may break. bool tryRemove(const std::string& role); + void updateQuotaConsumedMetric(const Role* role); + // Root node of the tree, its `basename` == `role` == "". Role* root_; diff --git a/src/master/allocator/mesos/metrics.cpp b/src/master/allocator/mesos/metrics.cpp index 6a8d369..463376e 100644 --- a/src/master/allocator/mesos/metrics.cpp +++ b/src/master/allocator/mesos/metrics.cpp @@ -219,6 +219,13 @@ void Metrics::updateQuota(const string& role, const Quota& quota) } +void Metrics::updateConsumed( + const string& role, const ResourceQuantities& consumed) +{ + quotaConsumed.update(role, consumed); +} + + 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 d2cb41b..f4691d9 100644 --- a/src/master/allocator/mesos/metrics.hpp +++ b/src/master/allocator/mesos/metrics.hpp @@ -68,6 +68,8 @@ struct Metrics ~Metrics(); void updateQuota(const std::string& role, const Quota& quota); + void updateConsumed( + const std::string& role, const ResourceQuantities& consumed); void addRole(const std::string& role); void removeRole(const std::string& role); @@ -117,6 +119,7 @@ private: // (Example of a name: allocator/mesos/quota/roles/roleA/resources/cpu/limit.) QuotaMetrics quotaGuarantees {"/guarantee"}; QuotaMetrics quotaLimits {"/limit"}; + QuotaMetrics quotaConsumed {"/consumed"}; };
