mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 21:18:04 +01:00
Gather IP-based metrics for international, unsealed-sender messages.
This commit is contained in:
committed by
Jon Chambers
parent
df9dc82de5
commit
f57a4171ba
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.controllers;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||
import org.whispersystems.textsecuregcm.push.MessageSender;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
import org.whispersystems.textsecuregcm.redis.AbstractRedisClusterTest;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
|
||||
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class MessageControllerMetricsTest extends AbstractRedisClusterTest {
|
||||
|
||||
private MessageController messageController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
messageController = new MessageController(mock(RateLimiters.class),
|
||||
mock(MessageSender.class),
|
||||
mock(ReceiptSender.class),
|
||||
mock(AccountsManager.class),
|
||||
mock(MessagesManager.class),
|
||||
mock(ApnFallbackManager.class),
|
||||
mock(DynamicConfigurationManager.class),
|
||||
getRedisCluster(),
|
||||
mock(ScheduledExecutorService.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecordInternationalUnsealedSenderMetrics() {
|
||||
final String senderIp = "127.0.0.1";
|
||||
|
||||
messageController.recordInternationalUnsealedSenderMetrics(senderIp, "84", "+18005551234");
|
||||
messageController.recordInternationalUnsealedSenderMetrics(senderIp, "84", "+18005551234");
|
||||
|
||||
getRedisCluster().useCluster(connection -> {
|
||||
assertEquals(1, (long)connection.sync().pfcount(MessageController.getDestinationSetKey(senderIp)));
|
||||
assertEquals(2, Long.parseLong(connection.sync().get(MessageController.getMessageCountKey(senderIp)), 10));
|
||||
|
||||
assertTrue(connection.sync().ttl(MessageController.getDestinationSetKey(senderIp)) >= 0);
|
||||
assertTrue(connection.sync().ttl(MessageController.getMessageCountKey(senderIp)) >= 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import io.lettuce.core.ScriptOutputType;
|
||||
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
|
||||
import junitparams.JUnitParamsRunner;
|
||||
import junitparams.Parameters;
|
||||
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
|
||||
@@ -81,6 +83,7 @@ import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
|
||||
import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
import org.whispersystems.textsecuregcm.tests.util.RedisClusterHelper;
|
||||
import org.whispersystems.textsecuregcm.util.Base64;
|
||||
|
||||
@RunWith(JUnitParamsRunner.class)
|
||||
@@ -95,6 +98,9 @@ public class MessageControllerTest {
|
||||
private static final String INTERNATIONAL_RECIPIENT = "+61123456789";
|
||||
private static final UUID INTERNATIONAL_UUID = UUID.randomUUID();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final RedisAdvancedClusterCommands<String, String> redisCommands = mock(RedisAdvancedClusterCommands.class);
|
||||
|
||||
private final MessageSender messageSender = mock(MessageSender.class);
|
||||
private final ReceiptSender receiptSender = mock(ReceiptSender.class);
|
||||
private final AccountsManager accountsManager = mock(AccountsManager.class);
|
||||
@@ -104,7 +110,7 @@ public class MessageControllerTest {
|
||||
private final CardinalityRateLimiter unsealedSenderLimiter = mock(CardinalityRateLimiter.class);
|
||||
private final ApnFallbackManager apnFallbackManager = mock(ApnFallbackManager.class);
|
||||
private final DynamicConfigurationManager dynamicConfigurationManager = mock(DynamicConfigurationManager.class);
|
||||
private final FaultTolerantRedisCluster metricsCluster = mock(FaultTolerantRedisCluster.class);
|
||||
private final FaultTolerantRedisCluster metricsCluster = RedisClusterHelper.buildMockRedisCluster(redisCommands);
|
||||
private final ScheduledExecutorService receiptExecutor = mock(ScheduledExecutorService.class);
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -207,6 +213,8 @@ public class MessageControllerTest {
|
||||
when(messageRateConfiguration.getReceiptDelayJitter()).thenReturn(Duration.ofMillis(1));
|
||||
when(messageRateConfiguration.getReceiptProbability()).thenReturn(1.0);
|
||||
|
||||
when(redisCommands.evalsha(any(), any(), any(), any())).thenReturn(List.of(1L, 1L));
|
||||
|
||||
Response response =
|
||||
resources.getJerseyTest()
|
||||
.target(String.format("/v1/messages/%s", INTERNATIONAL_RECIPIENT))
|
||||
|
||||
Reference in New Issue
Block a user