Convert `PushRecord` to a `record` and make `PushType` non-optional
This commit is contained in:
parent
a768498250
commit
2ddd2b9476
|
@ -6,8 +6,6 @@
|
||||||
package org.whispersystems.textsecuregcm.push;
|
package org.whispersystems.textsecuregcm.push;
|
||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.vdurmont.semver4j.Semver;
|
import com.vdurmont.semver4j.Semver;
|
||||||
|
@ -23,7 +21,6 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -63,29 +60,7 @@ public class PushLatencyManager {
|
||||||
VOIP
|
VOIP
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
record PushRecord(Instant timestamp, PushType pushType) {
|
||||||
static class PushRecord {
|
|
||||||
private final Instant timestamp;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final PushType pushType;
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
PushRecord(@JsonProperty("timestamp") final Instant timestamp,
|
|
||||||
@JsonProperty("pushType") @Nullable final PushType pushType) {
|
|
||||||
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
this.pushType = pushType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instant getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public PushType getPushType() {
|
|
||||||
return pushType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PushLatencyManager(final FaultTolerantRedisCluster redisCluster,
|
public PushLatencyManager(final FaultTolerantRedisCluster redisCluster,
|
||||||
|
@ -122,15 +97,12 @@ public class PushLatencyManager {
|
||||||
void recordQueueRead(final UUID accountUuid, final long deviceId, final String userAgentString) {
|
void recordQueueRead(final UUID accountUuid, final long deviceId, final String userAgentString) {
|
||||||
takePushRecord(accountUuid, deviceId).thenAccept(pushRecord -> {
|
takePushRecord(accountUuid, deviceId).thenAccept(pushRecord -> {
|
||||||
if (pushRecord != null) {
|
if (pushRecord != null) {
|
||||||
final Duration latency = Duration.between(pushRecord.getTimestamp(), Instant.now());
|
final Duration latency = Duration.between(pushRecord.timestamp(), Instant.now());
|
||||||
|
|
||||||
final List<Tag> tags = new ArrayList<>(2);
|
final List<Tag> tags = new ArrayList<>(2);
|
||||||
|
|
||||||
tags.add(UserAgentTagUtil.getPlatformTag(userAgentString));
|
tags.add(UserAgentTagUtil.getPlatformTag(userAgentString));
|
||||||
|
tags.add(Tag.of("pushType", pushRecord.pushType().name().toLowerCase()));
|
||||||
if (pushRecord.getPushType() != null) {
|
|
||||||
tags.add(Tag.of("pushType", pushRecord.getPushType().name().toLowerCase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final UserAgent userAgent = UserAgentUtil.parseUserAgentString(userAgentString);
|
final UserAgent userAgent = UserAgentUtil.parseUserAgentString(userAgentString);
|
||||||
|
|
Loading…
Reference in New Issue