Add metric for ServiceId string parsing
This commit is contained in:
parent
360a4793ae
commit
70134507f8
|
@ -5,13 +5,14 @@
|
|||
|
||||
package org.whispersystems.textsecuregcm.identity;
|
||||
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.HexFormat;
|
||||
import java.util.UUID;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import org.signal.libsignal.protocol.ServiceId;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.util.UUIDUtil;
|
||||
|
||||
/**
|
||||
|
@ -24,6 +25,7 @@ import org.whispersystems.textsecuregcm.util.UUIDUtil;
|
|||
description = "An identifier for an account based on the account's ACI"
|
||||
)
|
||||
public record AciServiceIdentifier(UUID uuid) implements ServiceIdentifier {
|
||||
private static final String SERVICE_ID_STRING_COUNTER_NAME = MetricsUtil.name(AciServiceIdentifier.class, "serviceIdString");
|
||||
|
||||
private static final IdentityType IDENTITY_TYPE = IdentityType.ACI;
|
||||
|
||||
|
@ -59,9 +61,10 @@ public record AciServiceIdentifier(UUID uuid) implements ServiceIdentifier {
|
|||
}
|
||||
|
||||
public static AciServiceIdentifier valueOf(final String string) {
|
||||
return new AciServiceIdentifier(
|
||||
UUID.fromString(string.startsWith(IDENTITY_TYPE.getStringPrefix())
|
||||
? string.substring(IDENTITY_TYPE.getStringPrefix().length()) : string));
|
||||
final boolean valid = !string.startsWith(IDENTITY_TYPE.getStringPrefix());
|
||||
final UUID uuid = UUID.fromString(valid ? string : string.substring(IDENTITY_TYPE.getStringPrefix().length()));
|
||||
Metrics.counter(SERVICE_ID_STRING_COUNTER_NAME, "valid", String.valueOf(valid)).increment();
|
||||
return new AciServiceIdentifier(uuid);
|
||||
}
|
||||
|
||||
public static AciServiceIdentifier fromBytes(final byte[] bytes) {
|
||||
|
|
|
@ -26,7 +26,7 @@ public final class MessageMetrics {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MessageMetrics.class);
|
||||
|
||||
private static final String MISMATCHED_ACCOUNT_ENVELOPE_UUID_COUNTER_NAME = name(MessageMetrics.class,
|
||||
static final String MISMATCHED_ACCOUNT_ENVELOPE_UUID_COUNTER_NAME = name(MessageMetrics.class,
|
||||
"mismatchedAccountEnvelopeUuid");
|
||||
|
||||
public static final String DELIVERY_LATENCY_TIMER_NAME = name(MessageMetrics.class, "deliveryLatency");
|
||||
|
|
|
@ -119,7 +119,9 @@ class MessageMetricsTest {
|
|||
}
|
||||
|
||||
private Optional<Counter> findCounter(SimpleMeterRegistry meterRegistry) {
|
||||
final Optional<Meter> maybeMeter = meterRegistry.getMeters().stream().findFirst();
|
||||
final Optional<Meter> maybeMeter = meterRegistry.getMeters().stream()
|
||||
.filter(meter -> meter.getId().getName().contains(MessageMetrics.MISMATCHED_ACCOUNT_ENVELOPE_UUID_COUNTER_NAME))
|
||||
.findFirst();
|
||||
return maybeMeter.map(meter -> meter instanceof Counter ? (Counter) meter : null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue