diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java index 8f180cf53..144e62b50 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java @@ -15,6 +15,8 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -239,8 +241,10 @@ public class KeysController { if (unsignedEcPreKey == null) { Metrics.counter(ONE_TIME_EC_PRE_KEY_UNAVAILABLE_COUNTER_NAME, - "isPrimary", String.valueOf(device.isPrimary()), - "platform", getDevicePlatform(device).map(Enum::name).orElse("unknown")) + "isPrimary", String.valueOf(device.isPrimary()), + "platform", getDevicePlatform(device).map(Enum::name).orElse("unknown"), + "identityType", targetIdentifier.identityType().name(), + "isStale", String.valueOf(isDeviceStale(device))) .increment(); } @@ -279,6 +283,11 @@ public class KeysController { return Optional.empty(); } + private static boolean isDeviceStale(final Device device) { + return Duration.between(Instant.ofEpochMilli(device.getLastSeen()), Instant.now()) + .compareTo(Duration.ofDays(30)) >= 0; + } + @PUT @Path("/signed") @Consumes(MediaType.APPLICATION_JSON)