Add a country code dimension to the non-normalized number counter
This commit is contained in:
parent
2bfe2c8ff8
commit
4d78437fe4
|
@ -5,23 +5,33 @@
|
|||
|
||||
package org.whispersystems.textsecuregcm.mappers;
|
||||
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||
|
||||
import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import org.whispersystems.textsecuregcm.util.NonNormalizedPhoneNumberException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
|
||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||
import org.whispersystems.textsecuregcm.util.NonNormalizedPhoneNumberException;
|
||||
|
||||
public class NonNormalizedPhoneNumberExceptionMapper implements ExceptionMapper<NonNormalizedPhoneNumberException> {
|
||||
|
||||
private static final Counter NON_NORMALIZED_NUMBER_COUNTER =
|
||||
Metrics.counter(name(NonNormalizedPhoneNumberExceptionMapper.class, "nonNormalizedNumbers"));
|
||||
private static final String NON_NORMALIZED_NUMBER_COUNTER_NAME =
|
||||
name(NonNormalizedPhoneNumberExceptionMapper.class, "nonNormalizedNumbers");
|
||||
|
||||
@Override
|
||||
public Response toResponse(final NonNormalizedPhoneNumberException exception) {
|
||||
NON_NORMALIZED_NUMBER_COUNTER.increment();
|
||||
String countryCode;
|
||||
|
||||
try {
|
||||
countryCode =
|
||||
String.valueOf(PhoneNumberUtil.getInstance().parse(exception.getOriginalNumber(), null).getCountryCode());
|
||||
} catch (final NumberParseException ignored) {
|
||||
countryCode = "unknown";
|
||||
}
|
||||
|
||||
Metrics.counter(NON_NORMALIZED_NUMBER_COUNTER_NAME, "countryCode", countryCode).increment();
|
||||
|
||||
return Response.status(Status.BAD_REQUEST)
|
||||
.entity(new NonNormalizedPhoneNumberResponse(exception.getOriginalNumber(), exception.getNormalizedNumber()))
|
||||
|
|
Loading…
Reference in New Issue