aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmclaugh...@apache.org
Subject aurora git commit: Expose stats on deleted tasks in TaskHistoryPruner
Date Fri, 23 Dec 2016 10:07:27 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 61e6bc6c4 -> 436a2adb8


Expose stats on deleted tasks in TaskHistoryPruner

Bugs closed: AURORA-1855

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


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

Branch: refs/heads/master
Commit: 436a2adb8ea16df6aecc02f6556d73a77679adfb
Parents: 61e6bc6
Author: Mehrdad Nurolahzade <mehrdad@nurolahzade.com>
Authored: Fri Dec 23 02:07:08 2016 -0800
Committer: David McLaughlin <dmclaughlin@twitter.com>
Committed: Fri Dec 23 02:07:08 2016 -0800

----------------------------------------------------------------------
 .../aurora/scheduler/pruning/TaskHistoryPruner.java | 10 +++++++++-
 .../scheduler/pruning/TaskHistoryPrunerTest.java    | 16 +++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/436a2adb/src/main/java/org/apache/aurora/scheduler/pruning/TaskHistoryPruner.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/pruning/TaskHistoryPruner.java b/src/main/java/org/apache/aurora/scheduler/pruning/TaskHistoryPruner.java
index bb973ca..f778494 100644
--- a/src/main/java/org/apache/aurora/scheduler/pruning/TaskHistoryPruner.java
+++ b/src/main/java/org/apache/aurora/scheduler/pruning/TaskHistoryPruner.java
@@ -14,6 +14,7 @@
 package org.apache.aurora.scheduler.pruning;
 
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.inject.Inject;
 
@@ -27,6 +28,7 @@ import com.google.common.eventbus.Subscribe;
 import org.apache.aurora.common.application.Lifecycle;
 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.util.Clock;
 import org.apache.aurora.gen.apiConstants;
 import org.apache.aurora.scheduler.BatchWorker;
@@ -56,6 +58,8 @@ public class TaskHistoryPruner implements EventSubscriber {
   private static final Logger LOG = LoggerFactory.getLogger(TaskHistoryPruner.class);
   private static final String FATAL_ERROR_FORMAT =
       "Unexpected problem pruning task history for %s. Triggering shutdown";
+  @VisibleForTesting
+  static final String TASKS_PRUNED = "tasks_pruned";
 
   private final DelayExecutor executor;
   private final StateManager stateManager;
@@ -64,6 +68,7 @@ public class TaskHistoryPruner implements EventSubscriber {
   private final Storage storage;
   private final Lifecycle lifecycle;
   private final TaskEventBatchWorker batchWorker;
+  private final AtomicLong prunedTasksCount;
 
   private final Predicate<IScheduledTask> safeToDelete = new Predicate<IScheduledTask>()
{
     @Override
@@ -97,7 +102,8 @@ public class TaskHistoryPruner implements EventSubscriber {
       HistoryPrunnerSettings settings,
       Storage storage,
       Lifecycle lifecycle,
-      TaskEventBatchWorker batchWorker) {
+      TaskEventBatchWorker batchWorker,
+      StatsProvider statsProvider) {
 
     this.executor = requireNonNull(executor);
     this.stateManager = requireNonNull(stateManager);
@@ -106,6 +112,7 @@ public class TaskHistoryPruner implements EventSubscriber {
     this.storage = requireNonNull(storage);
     this.lifecycle = requireNonNull(lifecycle);
     this.batchWorker = requireNonNull(batchWorker);
+    this.prunedTasksCount = statsProvider.makeCounter(TASKS_PRUNED);
   }
 
   @VisibleForTesting
@@ -139,6 +146,7 @@ public class TaskHistoryPruner implements EventSubscriber {
       stateManager.deleteTasks(storeProvider, taskIds);
       return BatchWorker.NO_RESULT;
     });
+    prunedTasksCount.addAndGet(taskIds.size());
   }
 
   @VisibleForTesting

http://git-wip-us.apache.org/repos/asf/aurora/blob/436a2adb/src/test/java/org/apache/aurora/scheduler/pruning/TaskHistoryPrunerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/pruning/TaskHistoryPrunerTest.java
b/src/test/java/org/apache/aurora/scheduler/pruning/TaskHistoryPrunerTest.java
index 8469596..14e4040 100644
--- a/src/test/java/org/apache/aurora/scheduler/pruning/TaskHistoryPrunerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/pruning/TaskHistoryPrunerTest.java
@@ -38,6 +38,7 @@ import org.apache.aurora.scheduler.state.StateManager;
 import org.apache.aurora.scheduler.storage.entities.IJobKey;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.testing.StorageTestUtil;
+import org.apache.aurora.scheduler.testing.FakeStatsProvider;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
 import org.junit.After;
@@ -49,9 +50,11 @@ import static org.apache.aurora.gen.ScheduleStatus.KILLED;
 import static org.apache.aurora.gen.ScheduleStatus.LOST;
 import static org.apache.aurora.gen.ScheduleStatus.RUNNING;
 import static org.apache.aurora.gen.ScheduleStatus.STARTING;
+import static org.apache.aurora.scheduler.pruning.TaskHistoryPruner.TASKS_PRUNED;
 import static org.apache.aurora.scheduler.testing.BatchWorkerUtil.expectBatchExecute;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expectLastCall;
+import static org.junit.Assert.assertEquals;
 
 public class TaskHistoryPrunerTest extends EasyMockTest {
   private static final String SLAVE_HOST = "HOST_A";
@@ -68,6 +71,7 @@ public class TaskHistoryPrunerTest extends EasyMockTest {
   private TaskHistoryPruner pruner;
   private Closer closer;
   private Command shutdownCommand;
+  private FakeStatsProvider statsProvider;
 
   @Before
   public void setUp() throws Exception {
@@ -78,6 +82,7 @@ public class TaskHistoryPrunerTest extends EasyMockTest {
     storageUtil.expectOperations();
     shutdownCommand = createMock(Command.class);
     TaskEventBatchWorker batchWorker = createMock(TaskEventBatchWorker.class);
+    statsProvider = new FakeStatsProvider();
     expectBatchExecute(batchWorker, storageUtil.storage, control).anyTimes();
 
     pruner = new TaskHistoryPruner(
@@ -87,7 +92,8 @@ public class TaskHistoryPrunerTest extends EasyMockTest {
         new HistoryPrunnerSettings(ONE_DAY, ONE_MINUTE, PER_JOB_HISTORY),
         storageUtil.storage,
         new Lifecycle(shutdownCommand),
-        batchWorker);
+        batchWorker,
+        statsProvider);
     closer = Closer.create();
   }
 
@@ -146,9 +152,11 @@ public class TaskHistoryPrunerTest extends EasyMockTest {
 
     control.replay();
 
+    assertEquals(0L, statsProvider.getValue(TASKS_PRUNED));
     for (IScheduledTask task : ImmutableList.of(a, b, c, d, e)) {
       pruner.recordStateChange(TaskStateChange.initialized(task));
     }
+    assertEquals(2L, statsProvider.getValue(TASKS_PRUNED));
   }
 
   @Test
@@ -184,8 +192,10 @@ public class TaskHistoryPrunerTest extends EasyMockTest {
     // Capture future for inactive task "a"
     changeState(running, killed);
     clock.advance(ONE_HOUR);
+    assertEquals(0L, statsProvider.getValue(TASKS_PRUNED));
     // Execute future to prune task "a" from the system.
     delayedDelete.getValue().run();
+    assertEquals(1L, statsProvider.getValue(TASKS_PRUNED));
   }
 
   @Test
@@ -234,7 +244,9 @@ public class TaskHistoryPrunerTest extends EasyMockTest {
     changeState(a, aKilled);
     changeState(b, bKilled);
     changeState(c, cLost);
+    assertEquals(0L, statsProvider.getValue(TASKS_PRUNED));
     changeState(d, dLost);
+    assertEquals(2L, statsProvider.getValue(TASKS_PRUNED));
   }
 
   @Test
@@ -253,7 +265,9 @@ public class TaskHistoryPrunerTest extends EasyMockTest {
 
     changeState(running, killed);
     clock.advance(ONE_HOUR);
+    assertEquals(0L, statsProvider.getValue(TASKS_PRUNED));
     delayedDelete.getValue().run();
+    assertEquals(0L, statsProvider.getValue(TASKS_PRUNED));
   }
 
   private void expectDeleteTasks(String... tasks) {


Mime
View raw message