Add metric for ServiceId string parsing

This commit is contained in:
ravi-signal
2024-01-19 13:56:47 -06:00
committed by GitHub
parent 360a4793ae
commit 70134507f8
3 changed files with 12 additions and 7 deletions

View File

@@ -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) {