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

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

commit 74f01313d563ab127fa34cc14383061a7812ddb0
Author: Benjamin Mahler <[email protected]>
AuthorDate: Mon Jul 29 17:45:26 2019 -0400

    Added a test for quota guarantee/limit metrics.
    
    Review: https://reviews.apache.org/r/71189
---
 src/tests/hierarchical_allocator_tests.cpp | 78 ++++++++++++++++++++++++++++++
 src/tests/master_quota_tests.cpp           | 11 +++--
 2 files changed, 85 insertions(+), 4 deletions(-)

diff --git a/src/tests/hierarchical_allocator_tests.cpp 
b/src/tests/hierarchical_allocator_tests.cpp
index e549951..2c1d0fe 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -4251,10 +4251,24 @@ 
TEST_F_TEMP_DISABLED_ON_WINDOWS(HierarchicalAllocatorTest, DRFWithQuota)
   metric =
     "allocator/mesos/quota"
     "/roles/" + QUOTA_ROLE +
+    "/resources/cpus"
+    "/limit";
+  EXPECT_EQ(0.25, metrics.values[metric]);
+
+  metric =
+    "allocator/mesos/quota"
+    "/roles/" + QUOTA_ROLE +
     "/resources/mem"
     "/guarantee";
   EXPECT_EQ(128, metrics.values[metric]);
 
+  metric =
+    "allocator/mesos/quota"
+    "/roles/" + QUOTA_ROLE +
+    "/resources/mem"
+    "/limit";
+  EXPECT_EQ(128, metrics.values[metric]);
+
   // Add an agent with some allocated resources.
   SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
   allocator->addSlave(
@@ -5097,6 +5111,70 @@ 
TEST_F_TEMP_DISABLED_ON_WINDOWS(HierarchicalAllocatorTest, ResourceMetrics)
 }
 
 
+// Ensures that guarantee and limit metrics are exposed
+// and updated correctly.
+TEST_F(HierarchicalAllocatorTest, QuotaMetrics)
+{
+  // 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();
+
+  const string cpuGuaranteeKey =
+    "allocator/mesos/quota/roles/role/resources/cpus/guarantee";
+  const string cpuLimitKey =
+    "allocator/mesos/quota/roles/role/resources/cpus/limit";
+  const string memGuaranteeKey =
+    "allocator/mesos/quota/roles/role/resources/mem/guarantee";
+  const string memLimitKey =
+    "allocator/mesos/quota/roles/role/resources/mem/limit";
+
+  JSON::Object metrics = Metrics();
+
+  EXPECT_TRUE(metrics.values.count(cpuGuaranteeKey) == 0);
+  EXPECT_TRUE(metrics.values.count(cpuLimitKey) == 0);
+  EXPECT_TRUE(metrics.values.count(memGuaranteeKey) == 0);
+  EXPECT_TRUE(metrics.values.count(memLimitKey) == 0);
+
+  // Set quota to have:
+  //   * 1 cpu guarantee / no cpu limit and
+  //   * no mem guarantee / 1024 mem limit
+  Quota quota = createQuota("cpus:1", "mem:1024");
+  allocator->updateQuota("role", quota);
+  Clock::settle();
+
+  metrics = Metrics();
+
+  EXPECT_EQ(1, metrics.values[cpuGuaranteeKey]);
+  EXPECT_TRUE(metrics.values.count(cpuLimitKey) == 0);
+  EXPECT_TRUE(metrics.values.count(memGuaranteeKey) == 0);
+  EXPECT_EQ(1024, metrics.values[memLimitKey]);
+
+  // Increase the cpu guarantee:
+  quota = createQuota("cpus:2", "mem:1024");
+  allocator->updateQuota("role", quota);
+  Clock::settle();
+
+  metrics = Metrics();
+
+  EXPECT_EQ(2, metrics.values[cpuGuaranteeKey]);
+
+  // Set back to default quota.
+  quota = createQuota("", "");
+  allocator->updateQuota("role", quota);
+  Clock::settle();
+
+  metrics = Metrics();
+
+  EXPECT_TRUE(metrics.values.count(cpuGuaranteeKey) == 0);
+  EXPECT_TRUE(metrics.values.count(cpuLimitKey) == 0);
+  EXPECT_TRUE(metrics.values.count(memGuaranteeKey) == 0);
+  EXPECT_TRUE(metrics.values.count(memLimitKey) == 0);
+}
+
+
 // The allocator is not fully initialized until `allocator->initialize(...)`
 // is called (e.g., from `Master::initialize()` or
 // `HierarchicalAllocatorTestBase::initialize(...)`). This test
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index 7745fb0..02b1e8d 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -723,13 +723,15 @@ TEST_F(MasterQuotaTest, RemoveSingleQuota)
     // Ensure metrics update is finished.
     Clock::settle();
 
-    const string metricKey =
+    const string guaranteeKey =
       "allocator/mesos/quota/roles/" + ROLE1 + "/resources/cpus/guarantee";
-
+    const string limitKey =
+      "allocator/mesos/quota/roles/" + ROLE1 + "/resources/cpus/limit";
 
     JSON::Object metrics = Metrics();
 
-    EXPECT_EQ(1, metrics.values[metricKey]);
+    EXPECT_EQ(1, metrics.values[guaranteeKey]);
+    EXPECT_EQ(1, metrics.values[limitKey]);
 
     // Remove the previously requested quota.
     Future<Nothing> receivedQuotaRequest;
@@ -747,7 +749,8 @@ TEST_F(MasterQuotaTest, RemoveSingleQuota)
 
     metrics = Metrics();
 
-    ASSERT_NONE(metrics.at<JSON::Number>(metricKey));
+    ASSERT_NONE(metrics.at<JSON::Number>(guaranteeKey));
+    ASSERT_NONE(metrics.at<JSON::Number>(limitKey));
   }
 }
 

Reply via email to