mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 18:28:10 +01:00
Fix flaky MessageMetricsTest
Make the MeterRegistry in MessageMetrics configurable
This commit is contained in:
committed by
ravi-signal
parent
a80c020146
commit
40639f70f4
@@ -7,6 +7,8 @@ package org.whispersystems.textsecuregcm.metrics;
|
||||
|
||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
@@ -30,13 +32,23 @@ public final class MessageMetrics {
|
||||
"mismatchedAccountEnvelopeUuid");
|
||||
|
||||
public static final String DELIVERY_LATENCY_TIMER_NAME = name(MessageMetrics.class, "deliveryLatency");
|
||||
private final MeterRegistry metricRegistry;
|
||||
|
||||
public static void measureAccountOutgoingMessageUuidMismatches(final Account account,
|
||||
@VisibleForTesting
|
||||
MessageMetrics(final MeterRegistry metricRegistry) {
|
||||
this.metricRegistry = metricRegistry;
|
||||
}
|
||||
|
||||
public MessageMetrics() {
|
||||
this(Metrics.globalRegistry);
|
||||
}
|
||||
|
||||
public void measureAccountOutgoingMessageUuidMismatches(final Account account,
|
||||
final OutgoingMessageEntity outgoingMessage) {
|
||||
measureAccountDestinationUuidMismatches(account, outgoingMessage.destinationUuid());
|
||||
}
|
||||
|
||||
public static void measureAccountEnvelopeUuidMismatches(final Account account,
|
||||
public void measureAccountEnvelopeUuidMismatches(final Account account,
|
||||
final MessageProtos.Envelope envelope) {
|
||||
if (envelope.hasDestinationUuid()) {
|
||||
try {
|
||||
@@ -47,16 +59,16 @@ public final class MessageMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
private static void measureAccountDestinationUuidMismatches(final Account account, final ServiceIdentifier destinationIdentifier) {
|
||||
private void measureAccountDestinationUuidMismatches(final Account account, final ServiceIdentifier destinationIdentifier) {
|
||||
if (!account.isIdentifiedBy(destinationIdentifier)) {
|
||||
// In all cases, this represents a mismatch between the account’s current PNI and its PNI when the message was
|
||||
// sent. This is an expected case, but if this metric changes significantly, it could indicate an issue to
|
||||
// investigate.
|
||||
Metrics.counter(MISMATCHED_ACCOUNT_ENVELOPE_UUID_COUNTER_NAME).increment();
|
||||
metricRegistry.counter(MISMATCHED_ACCOUNT_ENVELOPE_UUID_COUNTER_NAME).increment();
|
||||
}
|
||||
}
|
||||
|
||||
public static void measureOutgoingMessageLatency(final long serverTimestamp,
|
||||
public void measureOutgoingMessageLatency(final long serverTimestamp,
|
||||
final String channel,
|
||||
final String userAgent,
|
||||
final ClientReleaseManager clientReleaseManager) {
|
||||
@@ -70,7 +82,7 @@ public final class MessageMetrics {
|
||||
Timer.builder(DELIVERY_LATENCY_TIMER_NAME)
|
||||
.publishPercentileHistogram(true)
|
||||
.tags(tags)
|
||||
.register(Metrics.globalRegistry)
|
||||
.register(metricRegistry)
|
||||
.record(Duration.between(Instant.ofEpochMilli(serverTimestamp), Instant.now()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user