aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zma...@apache.org
Subject aurora git commit: Remove static Stats method `exportSize`.
Date Tue, 06 Sep 2016 19:18:26 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 5d3f94549 -> 059b08621


Remove static Stats method `exportSize`.

Reviewed at https://reviews.apache.org/r/51469/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/059b0862
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/059b0862
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/059b0862

Branch: refs/heads/master
Commit: 059b08621ae4892d98954a6cd0e88f274cdd1bef
Parents: 5d3f945
Author: Zameer Manji <zmanji@apache.org>
Authored: Tue Sep 6 12:18:36 2016 -0700
Committer: Zameer Manji <zmanji@apache.org>
Committed: Tue Sep 6 12:18:36 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/aurora/common/stats/Stats.java    | 14 --------------
 .../org/apache/aurora/common/stats/StatsProvider.java | 11 +++++++++++
 .../aurora/scheduler/TaskStatusHandlerImpl.java       |  6 ++++--
 .../apache/aurora/scheduler/offers/OfferManager.java  | 11 ++++++++---
 .../aurora/scheduler/TaskStatusHandlerImplTest.java   |  2 ++
 .../aurora/scheduler/offers/OfferManagerImplTest.java |  5 ++++-
 6 files changed, 29 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/059b0862/commons/src/main/java/org/apache/aurora/common/stats/Stats.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/Stats.java b/commons/src/main/java/org/apache/aurora/common/stats/Stats.java
index 538e807..af1a7b3 100644
--- a/commons/src/main/java/org/apache/aurora/common/stats/Stats.java
+++ b/commons/src/main/java/org/apache/aurora/common/stats/Stats.java
@@ -237,20 +237,6 @@ public class Stats {
   }
 
   /**
-   * Exports a metric that tracks the size of a collection.
-   *
-   * @param name Name of the stat to export.
-   * @param collection Collection whose size should be tracked.
-   */
-  public static void exportSize(String name, final Collection<?> collection) {
-    export(new StatImpl<Integer>(name) {
-      @Override public Integer read() {
-        return collection.size();
-      }
-    });
-  }
-
-  /**
    * Exports a 'static' statistic, which will not be registered for time series tracking.
    *
    * @param var Variable to statically export.

http://git-wip-us.apache.org/repos/asf/aurora/blob/059b0862/commons/src/main/java/org/apache/aurora/common/stats/StatsProvider.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/StatsProvider.java b/commons/src/main/java/org/apache/aurora/common/stats/StatsProvider.java
index 6b1fa4b..c02dd38 100644
--- a/commons/src/main/java/org/apache/aurora/common/stats/StatsProvider.java
+++ b/commons/src/main/java/org/apache/aurora/common/stats/StatsProvider.java
@@ -13,6 +13,7 @@
  */
 package org.apache.aurora.common.stats;
 
+import java.util.Collection;
 import java.util.concurrent.atomic.AtomicLong;
 
 import com.google.common.base.Supplier;
@@ -43,6 +44,16 @@ public interface StatsProvider {
   <T extends Number> Stat<T> makeGauge(String name, Supplier<T> gauge);
 
   /**
+   * Exports a metric that tracks the size of a collection.
+   *
+   * @param name Name of the stat to export.
+   * @param collection Collection whose size should be tracked.
+   */
+  default void exportSize(String name, final Collection<?> collection) {
+    makeGauge(name, (Supplier<Number>) collection::size);
+  }
+
+  /**
    * Gets a stats provider that does not track stats in an internal time series repository.
    * The stored variables will only be available as instantaneous values.
    *

http://git-wip-us.apache.org/repos/asf/aurora/blob/059b0862/src/main/java/org/apache/aurora/scheduler/TaskStatusHandlerImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/TaskStatusHandlerImpl.java b/src/main/java/org/apache/aurora/scheduler/TaskStatusHandlerImpl.java
index a83f183..51215b6 100644
--- a/src/main/java/org/apache/aurora/scheduler/TaskStatusHandlerImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/TaskStatusHandlerImpl.java
@@ -28,7 +28,7 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.AbstractExecutionThreadService;
 import com.google.common.util.concurrent.MoreExecutors;
 
-import org.apache.aurora.common.stats.Stats;
+import org.apache.aurora.common.stats.StatsProvider;
 import org.apache.aurora.gen.ScheduleStatus;
 import org.apache.aurora.scheduler.base.Conversions;
 import org.apache.aurora.scheduler.mesos.Driver;
@@ -93,6 +93,7 @@ public class TaskStatusHandlerImpl extends AbstractExecutionThreadService
   TaskStatusHandlerImpl(
       Storage storage,
       StateManager stateManager,
+      StatsProvider statsProvider,
       final Driver driver,
       @StatusUpdateQueue BlockingQueue<TaskStatus> pendingUpdates,
       @MaxBatchSize Integer maxBatchSize,
@@ -104,8 +105,9 @@ public class TaskStatusHandlerImpl extends AbstractExecutionThreadService
     this.pendingUpdates = requireNonNull(pendingUpdates);
     this.maxBatchSize = requireNonNull(maxBatchSize);
     this.counters = requireNonNull(counters);
+    requireNonNull(statsProvider);
 
-    Stats.exportSize("status_updates_queue_size", this.pendingUpdates);
+    statsProvider.exportSize("status_updates_queue_size", this.pendingUpdates);
 
     addListener(
         new Listener() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/059b0862/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java b/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
index a1ae7c7..925c025 100644
--- a/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/offers/OfferManager.java
@@ -36,6 +36,7 @@ import com.google.common.eventbus.Subscribe;
 import org.apache.aurora.common.inject.TimedInterceptor.Timed;
 import org.apache.aurora.common.quantity.Time;
 import org.apache.aurora.common.stats.Stats;
+import org.apache.aurora.common.stats.StatsProvider;
 import org.apache.aurora.gen.MaintenanceMode;
 import org.apache.aurora.scheduler.HostOffer;
 import org.apache.aurora.scheduler.async.AsyncModule.AsyncExecutor;
@@ -145,23 +146,27 @@ public interface OfferManager extends EventSubscriber {
     @VisibleForTesting
     static final Logger LOG = LoggerFactory.getLogger(OfferManagerImpl.class);
 
-    private final HostOffers hostOffers = new HostOffers();
+    private final HostOffers hostOffers;
     private final AtomicLong offerRaces = Stats.exportLong("offer_accept_races");
 
     private final Driver driver;
     private final OfferSettings offerSettings;
     private final DelayExecutor executor;
+    private final StatsProvider statsProvider;
 
     @Inject
     @VisibleForTesting
     public OfferManagerImpl(
         Driver driver,
         OfferSettings offerSettings,
+        StatsProvider statsProvider,
         @AsyncExecutor DelayExecutor executor) {
 
       this.driver = requireNonNull(driver);
       this.offerSettings = requireNonNull(offerSettings);
       this.executor = requireNonNull(executor);
+      this.statsProvider = requireNonNull(statsProvider);
+      this.hostOffers = new HostOffers(statsProvider);
     }
 
     @Override
@@ -281,10 +286,10 @@ public interface OfferManager extends EventSubscriber {
       // scheduling attempts. See VetoGroup for more details on static ban.
       private final Multimap<OfferID, TaskGroupKey> staticallyBannedOffers = HashMultimap.create();
 
-      HostOffers() {
+      HostOffers(StatsProvider statsProvider) {
         // Potential gotcha - since this is a ConcurrentSkipListSet, size() is more expensive.
         // Could track this separately if it turns out to pose problems.
-        Stats.exportSize("outstanding_offers", offers);
+        statsProvider.exportSize("outstanding_offers", offers);
       }
 
       synchronized Optional<HostOffer> get(SlaveID slaveId) {

http://git-wip-us.apache.org/repos/asf/aurora/blob/059b0862/src/test/java/org/apache/aurora/scheduler/TaskStatusHandlerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/TaskStatusHandlerImplTest.java b/src/test/java/org/apache/aurora/scheduler/TaskStatusHandlerImplTest.java
index 6d4934b..b28d703 100644
--- a/src/test/java/org/apache/aurora/scheduler/TaskStatusHandlerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/TaskStatusHandlerImplTest.java
@@ -68,6 +68,7 @@ public class TaskStatusHandlerImplTest extends EasyMockTest {
     statusHandler = new TaskStatusHandlerImpl(
         storageUtil.storage,
         stateManager,
+        stats,
         driver,
         queue,
         1000,
@@ -261,6 +262,7 @@ public class TaskStatusHandlerImplTest extends EasyMockTest {
     statusHandler = new TaskStatusHandlerImpl(
         storageUtil.storage,
         stateManager,
+        stats,
         driver,
         queue,
         1000,

http://git-wip-us.apache.org/repos/asf/aurora/blob/059b0862/src/test/java/org/apache/aurora/scheduler/offers/OfferManagerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/offers/OfferManagerImplTest.java b/src/test/java/org/apache/aurora/scheduler/offers/OfferManagerImplTest.java
index e7534c4..a739bce 100644
--- a/src/test/java/org/apache/aurora/scheduler/offers/OfferManagerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/offers/OfferManagerImplTest.java
@@ -19,6 +19,7 @@ import com.google.common.collect.Iterables;
 
 import org.apache.aurora.common.quantity.Amount;
 import org.apache.aurora.common.quantity.Time;
+import org.apache.aurora.common.stats.StatsProvider;
 import org.apache.aurora.common.testing.easymock.EasyMockTest;
 import org.apache.aurora.gen.HostAttributes;
 import org.apache.aurora.gen.JobKey;
@@ -34,6 +35,7 @@ import org.apache.aurora.scheduler.offers.OfferManager.OfferManagerImpl;
 import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.apache.aurora.scheduler.testing.FakeScheduledExecutor;
+import org.apache.aurora.scheduler.testing.FakeStatsProvider;
 import org.apache.mesos.Protos;
 import org.apache.mesos.Protos.Filters;
 import org.apache.mesos.Protos.TaskInfo;
@@ -85,7 +87,8 @@ public class OfferManagerImplTest extends EasyMockTest {
     OfferSettings offerSettings = new OfferSettings(
         Amount.of(OFFER_FILTER_SECONDS, Time.SECONDS),
         () -> RETURN_DELAY);
-    offerManager = new OfferManagerImpl(driver, offerSettings, executorMock);
+    StatsProvider stats = new FakeStatsProvider();
+    offerManager = new OfferManagerImpl(driver, offerSettings, stats, executorMock);
   }
 
   @Test


Mime
View raw message