You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ma...@apache.org on 2016/06/07 21:04:43 UTC
aurora git commit: Converting resource counters to use new resource
fields
Repository: aurora
Updated Branches:
refs/heads/master 8cce5bc00 -> 692074ca8
Converting resource counters to use new resource fields
Reviewed at https://reviews.apache.org/r/47998/
Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/692074ca
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/692074ca
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/692074ca
Branch: refs/heads/master
Commit: 692074ca852114d8d13520a6dfb12f6b1f4e2278
Parents: 8cce5bc
Author: Maxim Khutornenko <ma...@apache.org>
Authored: Tue Jun 7 14:04:31 2016 -0700
Committer: Maxim Khutornenko <ma...@apache.org>
Committed: Tue Jun 7 14:04:31 2016 -0700
----------------------------------------------------------------------
RELEASE-NOTES.md | 4 +-
.../aurora/scheduler/http/Utilization.java | 20 +++-
.../aurora/scheduler/quota/QuotaManager.java | 6 +-
.../scheduler/resources/ResourceType.java | 9 ++
.../aurora/scheduler/stats/ResourceCounter.java | 108 ++++++-------------
.../scheduler/stats/TaskStatCalculator.java | 17 +--
.../apache/aurora/scheduler/http/utilization.st | 4 +-
.../scheduler/resources/ResourceTypeTest.java | 5 +
.../scheduler/stats/ResourceCounterTest.java | 26 ++---
9 files changed, 96 insertions(+), 103 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/RELEASE-NOTES.md
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 741c725..2bb3142 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -24,7 +24,7 @@
reference to either a `Docker` or `Mesos` container.
- New scheduler command line argument `-ip` to control what ip address to bind the schedulers http
server to.
-- Added experimental support for Mesos GPU resource. This feature will be available in Mesos 0.29.0
+- Added experimental support for Mesos GPU resource. This feature will be available in Mesos 1.0
and is disabled by default. Use `-allow_gpu_resource` flag to enable it.
**IMPORTANT: once this feature is enabled, creating jobs with GPU resource will make scheduler
@@ -63,6 +63,8 @@
- The endpoint `/slaves` is deprecated. Please use `/agents` instead.
- Deprecated `production` field in `TaskConfig` thrift struct. Use `tier` field to specify task
scheduling and resource handling behavior.
+- The scheduler `resources_*_ram_gb` and `resources_*_disk_gb` metrics have been renamed to
+ `resources_*_ram_mb` and `resources_*_disk_mb` respectively. Note the unit change: GB -> MB.
0.13.0
------
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/Utilization.java b/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
index 4a609e3..3c77e29 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/Utilization.java
@@ -37,8 +37,8 @@ import org.apache.aurora.common.base.MorePreconditions;
import org.apache.aurora.common.util.templating.StringTemplateHelper;
import org.apache.aurora.common.util.templating.StringTemplateHelper.TemplateException;
import org.apache.aurora.scheduler.base.Query;
+import org.apache.aurora.scheduler.resources.ResourceType;
import org.apache.aurora.scheduler.stats.ResourceCounter;
-import org.apache.aurora.scheduler.stats.ResourceCounter.GlobalMetric;
import org.apache.aurora.scheduler.stats.ResourceCounter.Metric;
import org.apache.aurora.scheduler.stats.ResourceCounter.MetricType;
import org.apache.aurora.scheduler.storage.entities.IServerInfo;
@@ -123,6 +123,22 @@ public class Utilization {
return display.link;
}
+ public long getCpu() {
+ return valueOf(ResourceType.CPUS);
+ }
+
+ public long getRam() {
+ return valueOf(ResourceType.RAM_MB);
+ }
+
+ public long getDisk() {
+ return valueOf(ResourceType.DISK_MB);
+ }
+
+ private long valueOf(ResourceType type) {
+ return getBag().valueOf(type).longValue();
+ }
+
@Override
public boolean equals(Object o) {
if (!(o instanceof DisplayMetric)) {
@@ -141,7 +157,7 @@ public class Utilization {
}
}
- private static final Function<GlobalMetric, DisplayMetric> TO_DISPLAY =
+ private static final Function<Metric, DisplayMetric> TO_DISPLAY =
count -> new DisplayMetric(
new Display(
count.type.name().replace('_', ' ').toLowerCase(),
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java b/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
index 612525c..7f8c66c 100644
--- a/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/quota/QuotaManager.java
@@ -89,6 +89,9 @@ public interface QuotaManager {
EnumSet<ResourceType> QUOTA_RESOURCE_TYPES = EnumSet.of(CPUS, RAM_MB, DISK_MB);
+ Function<ITaskConfig, ResourceBag> QUOTA_RESOURCES =
+ config -> bagFromResources(getTaskResources(config, QUOTA_RESOURCE_TYPES));
+
/**
* Saves a new quota for the provided role or overrides the existing one.
*
@@ -416,9 +419,6 @@ public interface QuotaManager {
.setUpdateStatuses(Updates.ACTIVE_JOB_UPDATE_STATES));
}
- private static final Function<ITaskConfig, ResourceBag> QUOTA_RESOURCES =
- config -> bagFromResources(getTaskResources(config, QUOTA_RESOURCE_TYPES));
-
private static final Function<IInstanceTaskConfig, ResourceBag> INSTANCE_RESOURCES =
config -> scale(config.getTask(), getUpdateInstanceCount(config.getInstances()));
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java b/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
index bfe7583..4c102a3 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
@@ -279,6 +279,15 @@ public enum ResourceType implements TEnum {
}
/**
+ * Gets "stats-friendly" unit for using in metrics.
+ *
+ * @return
+ */
+ public String getAuroraStatUnit() {
+ return auroraUnit.replaceAll("\\(|\\)", "");
+ }
+
+ /**
* Scaling range to use for comparison of scheduling vetoes.
* <p>
* This has no real bearing besides trying to determine if a veto along one resource vector
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/main/java/org/apache/aurora/scheduler/stats/ResourceCounter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/stats/ResourceCounter.java b/src/main/java/org/apache/aurora/scheduler/stats/ResourceCounter.java
index 5231e9f..a3e9bc7 100644
--- a/src/main/java/org/apache/aurora/scheduler/stats/ResourceCounter.java
+++ b/src/main/java/org/apache/aurora/scheduler/stats/ResourceCounter.java
@@ -32,6 +32,8 @@ import com.google.common.collect.Iterables;
import org.apache.aurora.scheduler.base.Query;
import org.apache.aurora.scheduler.base.Tasks;
+import org.apache.aurora.scheduler.resources.ResourceBag;
+import org.apache.aurora.scheduler.resources.ResourceManager;
import org.apache.aurora.scheduler.storage.Storage;
import org.apache.aurora.scheduler.storage.Storage.StorageException;
import org.apache.aurora.scheduler.storage.entities.IResourceAggregate;
@@ -40,6 +42,7 @@ import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
import static org.apache.aurora.scheduler.quota.QuotaManager.DEDICATED;
import static org.apache.aurora.scheduler.quota.QuotaManager.NON_PROD_SHARED;
import static org.apache.aurora.scheduler.quota.QuotaManager.PROD_SHARED;
+import static org.apache.aurora.scheduler.quota.QuotaManager.QUOTA_RESOURCES;
/**
* Computes aggregate metrics about resource allocation and consumption in the scheduler.
@@ -58,22 +61,21 @@ public class ResourceCounter {
Tasks::getConfig);
}
- private static final Function<MetricType, GlobalMetric> TO_GLOBAL_METRIC =
- GlobalMetric::new;
+ private static final Function<MetricType, Metric> TO_METRIC = Metric::new;
/**
* Computes totals for each of the {@link MetricType}s.
*
- * @return aggregates for each global metric type.
+ * @return aggregates for each metric type.
* @throws StorageException if there was a problem fetching tasks from storage.
*/
- public List<GlobalMetric> computeConsumptionTotals() throws StorageException {
- List<GlobalMetric> counts = FluentIterable.from(Arrays.asList(MetricType.values()))
- .transform(TO_GLOBAL_METRIC)
+ public List<Metric> computeConsumptionTotals() throws StorageException {
+ List<Metric> counts = FluentIterable.from(Arrays.asList(MetricType.values()))
+ .transform(TO_METRIC)
.toList();
for (ITaskConfig task : getTasks(Query.unscoped().active())) {
- for (GlobalMetric count : counts) {
+ for (Metric count : counts) {
count.accumulate(task);
}
}
@@ -89,9 +91,7 @@ public class ResourceCounter {
public Metric computeQuotaAllocationTotals() throws StorageException {
return storage.read(storeProvider -> {
Metric allocation = new Metric();
- for (IResourceAggregate quota : storeProvider.getQuotaStore().fetchQuotas().values()) {
- allocation.accumulate(quota);
- }
+ storeProvider.getQuotaStore().fetchQuotas().values().forEach(allocation::accumulate);
return allocation;
});
}
@@ -137,85 +137,40 @@ public class ResourceCounter {
}
}
- public static class GlobalMetric extends Metric {
+ public static class Metric {
public final MetricType type;
+ private ResourceBag bag;
- public GlobalMetric(MetricType type) {
- this(type, 0, 0, 0);
- }
-
- @VisibleForTesting
- GlobalMetric(MetricType type, long cpu, long ramMb, long diskMb) {
- super(cpu, ramMb, diskMb);
- this.type = type;
- }
-
- @Override
- protected void accumulate(ITaskConfig task) {
- if (type.filter.apply(task)) {
- super.accumulate(task);
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof GlobalMetric)) {
- return false;
- }
-
- GlobalMetric other = (GlobalMetric) o;
- return super.equals(other)
- && Objects.equals(other.type, this.type);
+ public Metric() {
+ this(MetricType.TOTAL_CONSUMED);
}
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), type);
- }
- }
-
- public static class Metric {
- private long cpu = 0;
- private long ramMb = 0;
- private long diskMb = 0;
-
- public Metric() {
- this(0, 0, 0);
+ public Metric(MetricType type) {
+ this(type, ResourceBag.EMPTY);
}
public Metric(Metric copy) {
- this(copy.cpu, copy.ramMb, copy.diskMb);
+ this(copy.type, copy.bag);
}
@VisibleForTesting
- Metric(long cpu, long ramMb, long diskMb) {
- this.cpu = cpu;
- this.ramMb = ramMb;
- this.diskMb = diskMb;
- }
-
- protected void accumulate(ITaskConfig task) {
- cpu += task.getNumCpus();
- ramMb += task.getRamMb();
- diskMb += task.getDiskMb();
- }
-
- protected void accumulate(IResourceAggregate quota) {
- cpu += quota.getNumCpus();
- ramMb += quota.getRamMb();
- diskMb += quota.getDiskMb();
+ Metric(MetricType type, ResourceBag bag) {
+ this.type = type;
+ this.bag = bag;
}
- public long getCpu() {
- return cpu;
+ void accumulate(ITaskConfig task) {
+ if (type.filter.apply(task)) {
+ bag = bag.add(QUOTA_RESOURCES.apply(task));
+ }
}
- public long getRamGb() {
- return ramMb / 1024;
+ void accumulate(IResourceAggregate aggregate) {
+ bag = bag.add(ResourceManager.bagFromAggregate(aggregate));
}
- public long getDiskGb() {
- return diskMb / 1024;
+ public ResourceBag getBag() {
+ return bag;
}
@Override
@@ -225,14 +180,13 @@ public class ResourceCounter {
}
Metric other = (Metric) o;
- return getCpu() == other.getCpu()
- && getRamGb() == other.getRamGb()
- && getDiskGb() == other.getDiskGb();
+ return Objects.equals(other.type, this.type)
+ && Objects.equals(other.bag, this.bag);
}
@Override
public int hashCode() {
- return Objects.hash(cpu, ramMb, diskMb);
+ return Objects.hash(type, bag);
}
}
}
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/main/java/org/apache/aurora/scheduler/stats/TaskStatCalculator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/stats/TaskStatCalculator.java b/src/main/java/org/apache/aurora/scheduler/stats/TaskStatCalculator.java
index 2511a39..b98aaaf 100644
--- a/src/main/java/org/apache/aurora/scheduler/stats/TaskStatCalculator.java
+++ b/src/main/java/org/apache/aurora/scheduler/stats/TaskStatCalculator.java
@@ -15,7 +15,9 @@ package org.apache.aurora.scheduler.stats;
import javax.inject.Inject;
-import org.apache.aurora.scheduler.stats.ResourceCounter.GlobalMetric;
+import com.google.common.base.Joiner;
+
+import org.apache.aurora.scheduler.resources.ResourceType;
import org.apache.aurora.scheduler.stats.ResourceCounter.Metric;
import org.apache.aurora.scheduler.storage.Storage.StorageException;
import org.slf4j.Logger;
@@ -39,16 +41,19 @@ class TaskStatCalculator implements Runnable {
}
private void update(String prefix, Metric metric) {
- counters.get(prefix + "_cpu").set(metric.getCpu());
- counters.get(prefix + "_ram_gb").set(metric.getRamGb());
- counters.get(prefix + "_disk_gb").set(metric.getDiskGb());
+ metric.getBag().streamResourceVectors().forEach(r -> {
+ ResourceType type = r.getKey();
+ String metricName =
+ Joiner.on("_").join(prefix, type.getAuroraName(), type.getAuroraStatUnit()).toLowerCase();
+ counters.get(metricName).set(metric.getBag().valueOf(type).longValue());
+ });
}
@Override
public void run() {
try {
- for (GlobalMetric metric : resourceCounter.computeConsumptionTotals()) {
- update("resources_" + metric.type.name().toLowerCase(), metric);
+ for (Metric metric : resourceCounter.computeConsumptionTotals()) {
+ update("resources_" + metric.type.name(), metric);
}
update("resources_allocated_quota", resourceCounter.computeQuotaAllocationTotals());
} catch (StorageException e) {
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/main/resources/org/apache/aurora/scheduler/http/utilization.st
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/http/utilization.st b/src/main/resources/org/apache/aurora/scheduler/http/utilization.st
index acb8f46..d9b8ab7 100644
--- a/src/main/resources/org/apache/aurora/scheduler/http/utilization.st
+++ b/src/main/resources/org/apache/aurora/scheduler/http/utilization.st
@@ -35,8 +35,8 @@
$metric.title$
$endif$
<td>$metric.cpu$
- <td>$metric.ramGb$ GB
- <td>$metric.diskGb$ GB
+ <td>$metric.ram$ MB
+ <td>$metric.disk$ MB
</tr>
}$
</tbody>
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/test/java/org/apache/aurora/scheduler/resources/ResourceTypeTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/ResourceTypeTest.java b/src/test/java/org/apache/aurora/scheduler/resources/ResourceTypeTest.java
index 7ba5567..9682766 100644
--- a/src/test/java/org/apache/aurora/scheduler/resources/ResourceTypeTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/resources/ResourceTypeTest.java
@@ -39,4 +39,9 @@ public class ResourceTypeTest {
public void testFindByMesosResource() {
assertEquals(RAM_MB, fromResource(mesosScalar(RAM_MB, 1.0)));
}
+
+ @Test
+ public void testGetAuroraStatUnit() {
+ assertEquals("cores", CPUS.getAuroraStatUnit());
+ }
}
http://git-wip-us.apache.org/repos/asf/aurora/blob/692074ca/src/test/java/org/apache/aurora/scheduler/stats/ResourceCounterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/stats/ResourceCounterTest.java b/src/test/java/org/apache/aurora/scheduler/stats/ResourceCounterTest.java
index fd4b434..19c1f8e 100644
--- a/src/test/java/org/apache/aurora/scheduler/stats/ResourceCounterTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/stats/ResourceCounterTest.java
@@ -31,6 +31,7 @@ import org.apache.aurora.scheduler.base.JobKeys;
import org.apache.aurora.scheduler.base.Query;
import org.apache.aurora.scheduler.base.TaskTestUtil;
import org.apache.aurora.scheduler.configuration.ConfigurationManager;
+import org.apache.aurora.scheduler.resources.ResourceBag;
import org.apache.aurora.scheduler.resources.ResourceTestUtil;
import org.apache.aurora.scheduler.storage.Storage;
import org.apache.aurora.scheduler.storage.Storage.MutateWork.NoResult;
@@ -48,7 +49,7 @@ import static org.apache.aurora.gen.ScheduleStatus.KILLING;
import static org.apache.aurora.gen.ScheduleStatus.PENDING;
import static org.apache.aurora.gen.ScheduleStatus.RESTARTING;
import static org.apache.aurora.gen.ScheduleStatus.RUNNING;
-import static org.apache.aurora.scheduler.stats.ResourceCounter.GlobalMetric;
+import static org.apache.aurora.scheduler.resources.ResourceTestUtil.bag;
import static org.apache.aurora.scheduler.stats.ResourceCounter.Metric;
import static org.apache.aurora.scheduler.stats.ResourceCounter.MetricType.DEDICATED_CONSUMED;
import static org.apache.aurora.scheduler.stats.ResourceCounter.MetricType.FREE_POOL_CONSUMED;
@@ -58,7 +59,7 @@ import static org.junit.Assert.assertEquals;
public class ResourceCounterTest {
- private static final Metric ZERO = new Metric(0, 0, 0);
+ private static final Metric ZERO = new Metric(TOTAL_CONSUMED, ResourceBag.EMPTY);
private static final long GB = 1024;
private static final Optional<String> NOT_DEDICATED = Optional.absent();
@@ -87,7 +88,7 @@ public class ResourceCounterTest {
assertEquals(ImmutableMap.of(), aggregates);
for (Metric metric : resourceCounter.computeConsumptionTotals()) {
- assertEquals(ZERO, metric);
+ assertEquals(ZERO.getBag(), metric.getBag());
}
}
@@ -105,12 +106,11 @@ public class ResourceCounterTest {
task("lil", "jobI", "i", 1, GB, GB, PRODUCTION, FINISHED, NOT_DEDICATED)
);
- Set<GlobalMetric> expected = ImmutableSet.of(
- new GlobalMetric(TOTAL_CONSUMED, 8, 8 * GB, 8 * GB),
- new GlobalMetric(DEDICATED_CONSUMED, 2, 2 * GB, 2 * GB),
- new GlobalMetric(QUOTA_CONSUMED, 4, 4 * GB, 4 * GB),
- new GlobalMetric(FREE_POOL_CONSUMED, 2, 2 * GB, 2 * GB)
- );
+ Set<Metric> expected = ImmutableSet.of(
+ new Metric(TOTAL_CONSUMED, bag(8, 8 * GB, 8 * GB)),
+ new Metric(DEDICATED_CONSUMED, bag(2, 2 * GB, 2 * GB)),
+ new Metric(QUOTA_CONSUMED, bag(4, 4 * GB, 4 * GB)),
+ new Metric(FREE_POOL_CONSUMED, bag(2, 2 * GB, 2 * GB)));
assertEquals(expected, ImmutableSet.copyOf(resourceCounter.computeConsumptionTotals()));
}
@@ -122,7 +122,9 @@ public class ResourceCounterTest {
storeProvider.getQuotaStore().saveQuota("b", ResourceTestUtil.aggregate(2, 3, 4));
});
- assertEquals(new Metric(3, 4, 5), resourceCounter.computeQuotaAllocationTotals());
+ assertEquals(
+ new Metric(TOTAL_CONSUMED, bag(3, 4, 5)),
+ resourceCounter.computeQuotaAllocationTotals());
}
@Test
@@ -140,8 +142,8 @@ public class ResourceCounterTest {
assertEquals(
ImmutableMap.of(
- JobKeys.from("bob", "test", "jobA"), new Metric(1, 1 * GB, 1 * GB),
- JobKeys.from("bob", "test", "jobB"), new Metric(2, 2 * GB, 2 * GB)
+ JobKeys.from("bob", "test", "jobA"), new Metric(TOTAL_CONSUMED, bag(1, 1 * GB, 1 * GB)),
+ JobKeys.from("bob", "test", "jobB"), new Metric(TOTAL_CONSUMED, bag(2, 2 * GB, 2 * GB))
),
resourceCounter.computeAggregates(
Query.roleScoped("bob"),