aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject aurora git commit: Expose stats on JobUpdateAction transitions
Date Tue, 27 Dec 2016 13:19:57 GMT
Repository: aurora
Updated Branches:
  refs/heads/master d6c1d7f79 -> 31f095da4


Expose stats on JobUpdateAction transitions

Introduced new stats that exposes `JobUpdateAction` transitions.

Refactored away from `CachedCounters` for existing metric; it was dynamically
generating new String objects (through concatenation) per stats collection event.

Fixed for a mistake in a previous changeset (https://reviews.apache.org/r/55003/);
removed unnecessary checked `Exception` on `CacheLoader.load()`.

Bugs closed: AURORA-1851

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


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

Branch: refs/heads/master
Commit: 31f095da4eb4c605341d867d7a5136b03cb67ef8
Parents: d6c1d7f
Author: Mehrdad Nurolahzade <mehrdad@nurolahzade.com>
Authored: Tue Dec 27 14:19:40 2016 +0100
Committer: Stephan Erb <serb@apache.org>
Committed: Tue Dec 27 14:19:40 2016 +0100

----------------------------------------------------------------------
 .../scheduler/storage/db/DbJobUpdateStore.java  | 43 +++++++++++++++++---
 .../thrift/aop/LoggingInterceptor.java          |  2 +-
 .../storage/db/DbJobUpdateStoreTest.java        | 10 ++++-
 3 files changed, 47 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/31f095da/src/main/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStore.java
index e0698a3..cbe5a0d 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStore.java
@@ -15,19 +15,24 @@ package org.apache.aurora.scheduler.storage.db;
 
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.inject.Inject;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableSet;
 
 import org.apache.aurora.common.base.MorePreconditions;
+import org.apache.aurora.common.stats.StatsProvider;
+import org.apache.aurora.gen.JobUpdateAction;
 import org.apache.aurora.gen.JobUpdateStatus;
 import org.apache.aurora.gen.storage.StoredJobUpdateDetails;
-import org.apache.aurora.scheduler.stats.CachedCounters;
 import org.apache.aurora.scheduler.storage.JobUpdateStore;
 import org.apache.aurora.scheduler.storage.db.views.DbJobUpdate;
 import org.apache.aurora.scheduler.storage.db.views.DbJobUpdateInstructions;
@@ -58,7 +63,8 @@ public class DbJobUpdateStore implements JobUpdateStore.Mutable {
   private final JobUpdateEventMapper jobEventMapper;
   private final JobInstanceUpdateEventMapper instanceEventMapper;
   private final TaskConfigManager taskConfigManager;
-  private final CachedCounters stats;
+  private final LoadingCache<JobUpdateStatus, AtomicLong> jobUpdateEventStats;
+  private final LoadingCache<JobUpdateAction, AtomicLong> jobUpdateActionStats;
 
   @Inject
   DbJobUpdateStore(
@@ -67,14 +73,33 @@ public class DbJobUpdateStore implements JobUpdateStore.Mutable {
       JobUpdateEventMapper jobEventMapper,
       JobInstanceUpdateEventMapper instanceEventMapper,
       TaskConfigManager taskConfigManager,
-      CachedCounters stats) {
+      StatsProvider statsProvider) {
 
     this.jobKeyMapper = requireNonNull(jobKeyMapper);
     this.detailsMapper = requireNonNull(detailsMapper);
     this.jobEventMapper = requireNonNull(jobEventMapper);
     this.instanceEventMapper = requireNonNull(instanceEventMapper);
     this.taskConfigManager = requireNonNull(taskConfigManager);
-    this.stats = requireNonNull(stats);
+    this.jobUpdateEventStats = CacheBuilder.newBuilder()
+        .build(new CacheLoader<JobUpdateStatus, AtomicLong>() {
+          @Override
+          public AtomicLong load(JobUpdateStatus status) {
+            return statsProvider.makeCounter(jobUpdateStatusStatName(status));
+          }
+        });
+    for (JobUpdateStatus status : JobUpdateStatus.values()) {
+      jobUpdateEventStats.getUnchecked(status).get();
+    }
+    this.jobUpdateActionStats = CacheBuilder.newBuilder()
+        .build(new CacheLoader<JobUpdateAction, AtomicLong>() {
+          @Override
+          public AtomicLong load(JobUpdateAction action) {
+            return statsProvider.makeCounter(jobUpdateActionStatName(action));
+          }
+        });
+    for (JobUpdateAction action : JobUpdateAction.values()) {
+      jobUpdateActionStats.getUnchecked(action).get();
+    }
   }
 
   @Timed("job_update_store_save_update")
@@ -141,21 +166,27 @@ public class DbJobUpdateStore implements JobUpdateStore.Mutable {
   }
 
   @VisibleForTesting
-  static String statName(JobUpdateStatus status) {
+  static String jobUpdateStatusStatName(JobUpdateStatus status) {
     return "update_transition_" + status;
   }
 
   @Timed("job_update_store_save_event")
   @Override
   public void saveJobUpdateEvent(IJobUpdateKey key, IJobUpdateEvent event) {
-    stats.get(statName(event.getStatus())).incrementAndGet();
     jobEventMapper.insert(key, event.newBuilder());
+    jobUpdateEventStats.getUnchecked(event.getStatus()).incrementAndGet();
+  }
+
+  @VisibleForTesting
+  static String jobUpdateActionStatName(JobUpdateAction action) {
+    return "update_instance_transition_" + action;
   }
 
   @Timed("job_update_store_save_instance_event")
   @Override
   public void saveJobInstanceUpdateEvent(IJobUpdateKey key, IJobInstanceUpdateEvent event)
{
     instanceEventMapper.insert(key, event.newBuilder());
+    jobUpdateActionStats.getUnchecked(event.getAction()).incrementAndGet();
   }
 
   @Timed("job_update_store_delete_all")

http://git-wip-us.apache.org/repos/asf/aurora/blob/31f095da/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
b/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
index 7621fac..1c7604b 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/aop/LoggingInterceptor.java
@@ -72,7 +72,7 @@ class LoggingInterceptor implements MethodInterceptor {
       CacheBuilder.newBuilder()
           .build(new CacheLoader<ResponseCode, AtomicLong>() {
             @Override
-            public AtomicLong load(ResponseCode code) throws Exception {
+            public AtomicLong load(ResponseCode code) {
               return Stats.exportLong("scheduler_thrift_response_" + code.name());
             }
           });

http://git-wip-us.apache.org/repos/asf/aurora/blob/31f095da/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
index d01dc3f..5332939 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
@@ -80,6 +80,7 @@ import static org.apache.aurora.gen.JobUpdateStatus.ROLLING_BACK;
 import static org.apache.aurora.gen.JobUpdateStatus.ROLLING_FORWARD;
 import static org.apache.aurora.gen.JobUpdateStatus.ROLL_BACK_PAUSED;
 import static org.apache.aurora.gen.JobUpdateStatus.ROLL_FORWARD_PAUSED;
+import static org.apache.aurora.scheduler.storage.db.DbJobUpdateStore.jobUpdateActionStatName;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
@@ -328,7 +329,7 @@ public class DbJobUpdateStoreTest {
     for (Map.Entry<JobUpdateStatus, T> entry : expected.entrySet()) {
       assertEquals(
           entry.getValue().longValue(),
-          stats.getLongValue(DbJobUpdateStore.statName(entry.getKey())));
+          stats.getLongValue(DbJobUpdateStore.jobUpdateStatusStatName(entry.getKey())));
     }
   }
 
@@ -350,6 +351,7 @@ public class DbJobUpdateStoreTest {
     assertEquals(
         event1,
         Iterables.getOnlyElement(getUpdateDetails(updateId).get().getInstanceEvents()));
+    assertEquals(1L, stats.getLongValue(jobUpdateActionStatName(INSTANCE_UPDATED)));
 
     saveJobInstanceEvent(event2, updateId);
     assertEquals(
@@ -357,6 +359,7 @@ public class DbJobUpdateStoreTest {
         getUpdateDetails(updateId).get().getUpdate());
     assertEquals(event1, getUpdateDetails(updateId).get().getInstanceEvents().get(0));
     assertEquals(event2, getUpdateDetails(updateId).get().getInstanceEvents().get(1));
+    assertEquals(1L, stats.getLongValue(jobUpdateActionStatName(INSTANCE_ROLLING_BACK)));
   }
 
   @Test(expected = StorageException.class)
@@ -420,16 +423,20 @@ public class DbJobUpdateStoreTest {
     saveJobEvent(jEvent11, updateId1);
     saveJobEvent(jEvent12, updateId1);
     saveJobInstanceEvent(iEvent11, updateId1);
+    assertEquals(1L, stats.getLongValue(jobUpdateActionStatName(INSTANCE_UPDATED)));
     saveJobInstanceEvent(iEvent12, updateId1);
+    assertEquals(1L, stats.getLongValue(jobUpdateActionStatName(INSTANCE_UPDATING)));
 
     saveJobEvent(jEvent21, updateId2);
     saveJobEvent(jEvent22, updateId2);
     assertEquals(ImmutableList.of(), getInstanceEvents(updateId2, 3));
     saveJobInstanceEvent(iEvent21, updateId2);
+    assertEquals(2L, stats.getLongValue(jobUpdateActionStatName(INSTANCE_UPDATING)));
 
     assertEquals(ImmutableList.of(iEvent21), getInstanceEvents(updateId2, 3));
     saveJobInstanceEvent(iEvent22, updateId2);
     assertEquals(ImmutableList.of(iEvent21, iEvent22), getInstanceEvents(updateId2, 3));
+    assertEquals(2L, stats.getLongValue(jobUpdateActionStatName(INSTANCE_UPDATING)));
 
     details1 = updateJobDetails(
         populateExpected(details1.getUpdate(), ERROR, CREATED_MS, 457L),
@@ -463,6 +470,7 @@ public class DbJobUpdateStoreTest {
     saveUpdate(update, Optional.of("lock"));
     saveJobEvent(makeJobUpdateEvent(ROLLING_FORWARD, 123L), updateId);
     saveJobInstanceEvent(instanceEvent, updateId);
+    assertEquals(1L, stats.getLongValue(jobUpdateActionStatName(INSTANCE_ROLLBACK_FAILED)));
     assertEquals(
         populateExpected(update, ROLLING_FORWARD, CREATED_MS, 125L),
         getUpdate(updateId).get());


Mime
View raw message