Limit notification request errors stats to 100
This commit is contained in:
parent
dd51aba417
commit
285b8803da
@ -134,9 +134,3 @@ DELETE FROM asset WHERE type='TbServiceQueue';
|
||||
DELETE FROM asset_profile WHERE name ='TbServiceQueue';
|
||||
|
||||
-- QUEUE STATS UPDATE END
|
||||
|
||||
-- NOTIFICATIONS UPDATE START
|
||||
|
||||
ALTER TABLE notification_request ALTER COLUMN stats SET DATA TYPE varchar(100000);
|
||||
|
||||
-- NOTIFICATIONS UPDATE END
|
||||
|
||||
@ -523,18 +523,17 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
|
||||
|
||||
@Test
|
||||
public void testNotificationRequestStats() throws Exception {
|
||||
wsClient.subscribeForUnreadNotifications(10);
|
||||
wsClient.waitForReply(true);
|
||||
|
||||
wsClient.registerWaitForUpdate();
|
||||
NotificationTarget notificationTarget = createNotificationTarget(customerUserId);
|
||||
NotificationRequest notificationRequest = submitNotificationRequest(notificationTarget.getId(), "Test :)", NotificationDeliveryMethod.WEB);
|
||||
wsClient.waitForUpdate();
|
||||
|
||||
await().atMost(2, TimeUnit.SECONDS)
|
||||
.until(() -> findNotificationRequest(notificationRequest.getId()).isSent());
|
||||
NotificationRequestStats stats = getStats(notificationRequest.getId());
|
||||
NotificationRequest notificationRequest = submitNotificationRequest(notificationTarget.getId(), "Test :)", NotificationDeliveryMethod.WEB);
|
||||
NotificationRequestStats stats = awaitNotificationRequest(notificationRequest.getId());
|
||||
assertThat(stats.getSent().get(NotificationDeliveryMethod.WEB)).hasValue(1);
|
||||
|
||||
doDelete("/api/user/mobile/session").andExpect(status().isOk());
|
||||
notificationRequest = submitNotificationRequest(notificationTarget.getId(), "Test", NotificationDeliveryMethod.MOBILE_APP);
|
||||
stats = awaitNotificationRequest(notificationRequest.getId());
|
||||
assertThat(stats.getErrors().get(NotificationDeliveryMethod.MOBILE_APP)).hasSize(1);
|
||||
assertThat(stats.getTotalErrors()).hasValue(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -34,7 +34,6 @@ public class NotificationRequestStats {
|
||||
@JsonIgnore
|
||||
private final AtomicInteger totalSent;
|
||||
private final Map<NotificationDeliveryMethod, Map<String, String>> errors;
|
||||
@JsonIgnore
|
||||
private final AtomicInteger totalErrors;
|
||||
private String error;
|
||||
@JsonIgnore
|
||||
@ -51,11 +50,19 @@ public class NotificationRequestStats {
|
||||
@JsonCreator
|
||||
public NotificationRequestStats(@JsonProperty("sent") Map<NotificationDeliveryMethod, AtomicInteger> sent,
|
||||
@JsonProperty("errors") Map<NotificationDeliveryMethod, Map<String, String>> errors,
|
||||
@JsonProperty("totalErrors") Integer totalErrors,
|
||||
@JsonProperty("error") String error) {
|
||||
this.sent = sent;
|
||||
this.totalSent = null;
|
||||
this.errors = errors;
|
||||
this.totalErrors = null;
|
||||
if (totalErrors == null) {
|
||||
if (errors != null) {
|
||||
totalErrors = errors.values().stream().mapToInt(Map::size).sum();
|
||||
} else {
|
||||
totalErrors = 0;
|
||||
}
|
||||
}
|
||||
this.totalErrors = new AtomicInteger(totalErrors);
|
||||
this.error = error;
|
||||
this.processedRecipients = Collections.emptyMap();
|
||||
}
|
||||
@ -73,7 +80,10 @@ public class NotificationRequestStats {
|
||||
if (errorMessage == null) {
|
||||
errorMessage = error.getClass().getSimpleName();
|
||||
}
|
||||
errors.computeIfAbsent(deliveryMethod, k -> new ConcurrentHashMap<>()).put(recipient.getTitle(), errorMessage);
|
||||
Map<String, String> errors = this.errors.computeIfAbsent(deliveryMethod, k -> new ConcurrentHashMap<>());
|
||||
if (errors.size() < 100) {
|
||||
errors.put(recipient.getTitle(), errorMessage);
|
||||
}
|
||||
totalErrors.incrementAndGet();
|
||||
}
|
||||
|
||||
|
||||
@ -855,7 +855,7 @@ CREATE TABLE IF NOT EXISTS notification_request (
|
||||
originator_entity_type VARCHAR(32),
|
||||
rule_id UUID NULL,
|
||||
status VARCHAR(32),
|
||||
stats VARCHAR(100000)
|
||||
stats VARCHAR(10000)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS notification (
|
||||
|
||||
@ -165,8 +165,7 @@ export class SentTableConfigResolver implements Resolve<EntityTableConfig<Notifi
|
||||
if (!stats?.errors) {
|
||||
return '';
|
||||
}
|
||||
let countError = 0;
|
||||
Object.keys(stats.errors).forEach(method => countError += Object.keys(stats.errors[method]).length);
|
||||
const countError = stats.totalErrors;
|
||||
if (countError === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ export interface NotificationRequestPreview {
|
||||
export interface NotificationRequestStats {
|
||||
sent: Map<NotificationDeliveryMethod, any>;
|
||||
errors: { [key in NotificationDeliveryMethod]: {[errorKey in string]: string}};
|
||||
processedRecipients: Map<NotificationDeliveryMethod, Set<UserId>>;
|
||||
totalErrors: number;
|
||||
}
|
||||
|
||||
export interface NotificationRequestConfig {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user