mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
perf(sns): log each captured push and SMS at debug level (#7569)
* perf(sns): log each captured push and SMS at debug level * chore(test): check that pushes and SMS log below INFO
This commit is contained in:
1 parent
8fa33c710b
commit
a5291ca192
2 files changed
+26
-2
No files matched your search
@@ -1356,7 +1356,7 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
recordPushNotification(new PushNotification(
|
||||
endpoint.getArn(), app.getArn(), app.getPlatform(), endpoint.getToken(),
|
||||
payload, subject, messageAttributes, messageId, Instant.now()));
|
||||
LOG.infov("Captured push notification {0} -> {1} ({2})", messageId, endpoint.getArn(), app.getPlatform());
|
||||
LOG.debugv("Captured push notification {0} -> {1} ({2})", messageId, endpoint.getArn(), app.getPlatform());
|
||||
return messageId;
|
||||
}
|
||||
|
||||
@@ -3031,7 +3031,7 @@ public class SnsService implements Resettable, ResourceProvider {
|
||||
String effectiveRegion = region != null ? region : regionResolver.getDefaultRegion();
|
||||
SentSms sms = new SentSms(messageId, effectiveRegion, phoneNumber, message, subject, Instant.now());
|
||||
smsStore.put("sms::" + effectiveRegion + "::" + messageId, sms);
|
||||
LOG.infov("SNS SMS published: messageId={0} phone={1}", messageId, phoneNumber);
|
||||
LOG.debugv("SNS SMS published: messageId={0} phone={1}", messageId, phoneNumber);
|
||||
return messageId;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,15 @@ import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.sns.model.PlatformApplication;
|
||||
import io.github.hectorvent.floci.services.sns.model.PlatformEndpoint;
|
||||
import io.github.hectorvent.floci.services.sns.model.PushNotification;
|
||||
import io.github.hectorvent.floci.testutil.LogCapture;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -354,6 +357,27 @@ class SnsMobilePushTest {
|
||||
assertTrue(capturedB.get(0).payload().contains("market alert"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void publish_logsEachPushAndSmsBelowInfo() {
|
||||
PlatformApplication app = snsService.createPlatformApplication("android-app", "GCM", Map.of(), REGION);
|
||||
PlatformEndpoint endpoint = snsService.createPlatformEndpoint(app.getArn(), "fcm-token", null, Map.of(), REGION);
|
||||
String topicArn = snsService.createTopic("market-alerts", null, null, REGION).getTopicArn();
|
||||
snsService.subscribe(topicArn, "application", endpoint.getArn(), REGION, Map.of());
|
||||
|
||||
List<LogRecord> records = LogCapture.capture(SnsService.class, () -> {
|
||||
snsService.publish(topicArn, null, null, "to topic", null, null, null, null, null, REGION);
|
||||
snsService.publish(null, endpoint.getArn(), null, "to endpoint", null, null, null, null, null, REGION);
|
||||
snsService.publish(null, null, "+15555550100", "to phone", null, null, REGION);
|
||||
});
|
||||
|
||||
assertEquals(2, records.stream().filter(r -> r.getMessage().startsWith("Captured push notification")).count());
|
||||
assertEquals(1, records.stream().filter(r -> r.getMessage().startsWith("SNS SMS published")).count());
|
||||
assertEquals(List.of(), records.stream()
|
||||
.filter(r -> r.getLevel().intValue() >= Level.INFO.intValue())
|
||||
.map(LogRecord::getMessage)
|
||||
.toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void publish_topicBroadcastSkipsDisabledEndpointButDeliversToEnabled() {
|
||||
PlatformApplication app = snsService.createPlatformApplication("android-app", "GCM", Map.of(), REGION);
|
||||
|
||||
Reference in new issue
Block a user