Skip to content

Commit

Permalink
Untangle metric names for RepeatedUseSignedPreKeyStore subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-signal committed Jun 30, 2023
1 parent 2d154eb commit ce4fdbf
Showing 1 changed file with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,12 @@ public abstract class RepeatedUseSignedPreKeyStore<K extends SignedPreKey<?>> {
static final String ATTR_PUBLIC_KEY = "P";
static final String ATTR_SIGNATURE = "S";

private static final Timer STORE_SINGLE_KEY_TIMER =
Metrics.timer(MetricsUtil.name(RepeatedUseSignedPreKeyStore.class, "storeSingleKey"));
private final Timer storeSingleKeyTimer = Metrics.timer(MetricsUtil.name(getClass(), "storeSingleKey"));
private final Timer storeKeyBatchTimer = Metrics.timer(MetricsUtil.name(getClass(), "storeKeyBatch"));
private final Timer deleteForDeviceTimer = Metrics.timer(MetricsUtil.name(getClass(), "deleteForDevice"));
private final Timer deleteForAccountTimer = Metrics.timer(MetricsUtil.name(getClass(), "deleteForAccount"));

private static final Timer STORE_KEY_BATCH_TIMER =
Metrics.timer(MetricsUtil.name(RepeatedUseSignedPreKeyStore.class, "storeKeyBatch"));

private static final Timer DELETE_FOR_DEVICE_TIMER =
Metrics.timer(MetricsUtil.name(RepeatedUseSignedPreKeyStore.class, "deleteForDevice"));

private static final Timer DELETE_FOR_ACCOUNT_TIMER =
Metrics.timer(MetricsUtil.name(RepeatedUseSignedPreKeyStore.class, "deleteForAccount"));

private static final String FIND_KEY_TIMER_NAME = MetricsUtil.name(RepeatedUseSignedPreKeyStore.class, "findKey");
private static final String KEY_PRESENT_TAG_NAME = "keyPresent";
private final String findKeyTimerName = MetricsUtil.name(getClass(), "findKey");

public RepeatedUseSignedPreKeyStore(final DynamoDbAsyncClient dynamoDbAsyncClient, final String tableName) {
this.dynamoDbAsyncClient = dynamoDbAsyncClient;
Expand All @@ -82,7 +74,7 @@ public CompletableFuture<Void> store(final UUID identifier, final long deviceId,
.tableName(tableName)
.item(getItemFromPreKey(identifier, deviceId, signedPreKey))
.build())
.thenRun(() -> sample.stop(STORE_SINGLE_KEY_TIMER));
.thenRun(() -> sample.stop(storeSingleKeyTimer));
}

/**
Expand Down Expand Up @@ -113,7 +105,7 @@ public CompletableFuture<Void> store(final UUID identifier, final Map<Long, K> s
})
.toList())
.build())
.thenRun(() -> sample.stop(STORE_KEY_BATCH_TIMER));
.thenRun(() -> sample.stop(storeKeyBatchTimer));
}

/**
Expand All @@ -136,7 +128,8 @@ public CompletableFuture<Optional<K>> find(final UUID identifier, final long dev
.thenApply(response -> response.hasItem() ? Optional.of(getPreKeyFromItem(response.item())) : Optional.empty());

findFuture.whenComplete((maybeSignedPreKey, throwable) ->
sample.stop(Metrics.timer(FIND_KEY_TIMER_NAME, KEY_PRESENT_TAG_NAME, String.valueOf(maybeSignedPreKey != null && maybeSignedPreKey.isPresent()))));
sample.stop(Metrics.timer(findKeyTimerName,
"keyPresent", String.valueOf(maybeSignedPreKey != null && maybeSignedPreKey.isPresent()))));

return findFuture;
}
Expand All @@ -161,7 +154,7 @@ public CompletableFuture<Void> delete(final UUID identifier) {
// Idiom: wait for everything to finish, but discard the results
.reduce(0, (a, b) -> 0)
.toFuture()
.thenRun(() -> sample.stop(DELETE_FOR_ACCOUNT_TIMER));
.thenRun(() -> sample.stop(deleteForAccountTimer));
}

/**
Expand All @@ -179,7 +172,7 @@ public CompletableFuture<Void> delete(final UUID identifier, final long deviceId
.tableName(tableName)
.key(getPrimaryKey(identifier, deviceId))
.build())
.thenRun(() -> sample.stop(DELETE_FOR_DEVICE_TIMER));
.thenRun(() -> sample.stop(deleteForDeviceTimer));
}

public Flux<Long> getDeviceIdsWithKeys(final UUID identifier) {
Expand Down

0 comments on commit ce4fdbf

Please sign in to comment.