Repository: aurora Updated Branches: refs/heads/master cffa5bac9 -> 06a221fda
Expose stats on deleted job updates in JobUpdateHistoryPruner Bugs closed: AURORA-1856 Reviewed at https://reviews.apache.org/r/54967/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/48ea3100 Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/48ea3100 Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/48ea3100 Branch: refs/heads/master Commit: 48ea31001e1a12622812cd876904f2baac5717df Parents: cffa5ba Author: Mehrdad Nurolahzade <[email protected]> Authored: Wed Jan 11 23:15:03 2017 +0100 Committer: Stephan Erb <[email protected]> Committed: Wed Jan 11 23:21:09 2017 +0100 ---------------------------------------------------------------------- .../scheduler/pruning/JobUpdateHistoryPruner.java | 11 ++++++++++- .../scheduler/pruning/JobUpdateHistoryPrunerTest.java | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/48ea3100/src/main/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPruner.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPruner.java b/src/main/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPruner.java index 6ab39ca..b2768d9 100644 --- a/src/main/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPruner.java +++ b/src/main/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPruner.java @@ -16,14 +16,17 @@ package org.apache.aurora.scheduler.pruning; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import javax.inject.Inject; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; import com.google.common.util.concurrent.AbstractIdleService; 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.scheduler.storage.Storage; import org.apache.aurora.scheduler.storage.Storage.MutateWork.NoResult; @@ -38,11 +41,14 @@ import static java.util.Objects.requireNonNull; */ class JobUpdateHistoryPruner extends AbstractIdleService { private static final Logger LOG = LoggerFactory.getLogger(JobUpdateHistoryPruner.class); + @VisibleForTesting + static final String JOB_UPDATES_PRUNED = "job_updates_pruned"; private final Clock clock; private final ScheduledExecutorService executor; private final Storage storage; private final HistoryPrunerSettings settings; + private final AtomicLong prunedUpdatesCount; static class HistoryPrunerSettings { private final Amount<Long, Time> pruneInterval; @@ -65,12 +71,14 @@ class JobUpdateHistoryPruner extends AbstractIdleService { Clock clock, ScheduledExecutorService executor, Storage storage, - HistoryPrunerSettings settings) { + HistoryPrunerSettings settings, + StatsProvider statsProvider) { this.clock = requireNonNull(clock); this.executor = requireNonNull(executor); this.storage = requireNonNull(storage); this.settings = requireNonNull(settings); + this.prunedUpdatesCount = statsProvider.makeCounter(JOB_UPDATES_PRUNED); } @Override @@ -81,6 +89,7 @@ class JobUpdateHistoryPruner extends AbstractIdleService { settings.maxUpdatesPerJob, clock.nowMillis() - settings.maxHistorySize.as(Time.MILLISECONDS)); + prunedUpdatesCount.addAndGet(prunedUpdates.size()); LOG.info(prunedUpdates.isEmpty() ? "No job update history to prune." : "Pruned job update history: " + Joiner.on(",").join(prunedUpdates)); http://git-wip-us.apache.org/repos/asf/aurora/blob/48ea3100/src/test/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPrunerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPrunerTest.java b/src/test/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPrunerTest.java index 20f790e..74db5ec 100644 --- a/src/test/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPrunerTest.java +++ b/src/test/java/org/apache/aurora/scheduler/pruning/JobUpdateHistoryPrunerTest.java @@ -27,9 +27,12 @@ import org.apache.aurora.scheduler.pruning.JobUpdateHistoryPruner.HistoryPrunerS import org.apache.aurora.scheduler.storage.entities.IJobUpdateKey; import org.apache.aurora.scheduler.storage.testing.StorageTestUtil; import org.apache.aurora.scheduler.testing.FakeScheduledExecutor; +import org.apache.aurora.scheduler.testing.FakeStatsProvider; import org.junit.Test; +import static org.apache.aurora.scheduler.pruning.JobUpdateHistoryPruner.JOB_UPDATES_PRUNED; import static org.easymock.EasyMock.expect; +import static org.junit.Assert.assertEquals; public class JobUpdateHistoryPrunerTest extends EasyMockTest { @Test @@ -37,6 +40,8 @@ public class JobUpdateHistoryPrunerTest extends EasyMockTest { StorageTestUtil storageUtil = new StorageTestUtil(this); storageUtil.expectOperations(); + final FakeStatsProvider statsProvider = new FakeStatsProvider(); + final ScheduledExecutorService executor = createMock(ScheduledExecutorService.class); FakeScheduledExecutor executorClock = FakeScheduledExecutor.scheduleAtFixedRateExecutor(executor, 2); @@ -60,10 +65,15 @@ public class JobUpdateHistoryPrunerTest extends EasyMockTest { new HistoryPrunerSettings( Amount.of(1L, Time.MILLISECONDS), Amount.of(1L, Time.MILLISECONDS), - 1)); + 1), + statsProvider); pruner.startAsync().awaitRunning(); + + assertEquals(0L, statsProvider.getValue(JOB_UPDATES_PRUNED)); executorClock.advance(Amount.of(1L, Time.MILLISECONDS)); + assertEquals(1L, statsProvider.getValue(JOB_UPDATES_PRUNED)); executorClock.advance(Amount.of(1L, Time.MILLISECONDS)); + assertEquals(1L, statsProvider.getValue(JOB_UPDATES_PRUNED)); } }
