From 8d37f28985952021d4d78a5d3dffc99a36274e07 Mon Sep 17 00:00:00 2001 From: mko Date: Tue, 7 May 2024 14:18:58 +0200 Subject: [PATCH 1/3] Reverts message truncating in BeforeSave handler Fixes: SIRI-960 --- .../sirius/biz/protocol/StoredIncident.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/java/sirius/biz/protocol/StoredIncident.java b/src/main/java/sirius/biz/protocol/StoredIncident.java index 0e06aa1a9..90e39f6a9 100644 --- a/src/main/java/sirius/biz/protocol/StoredIncident.java +++ b/src/main/java/sirius/biz/protocol/StoredIncident.java @@ -13,9 +13,7 @@ import sirius.db.es.annotations.ESOption; import sirius.db.es.annotations.IndexMode; import sirius.db.mixing.Mapping; -import sirius.db.mixing.annotations.BeforeSave; import sirius.db.mixing.types.StringMap; -import sirius.kernel.commons.Strings; import sirius.kernel.di.std.Framework; import java.time.LocalDateTime; @@ -26,11 +24,6 @@ @Framework(Protocols.FRAMEWORK_PROTOCOLS) public class StoredIncident extends SearchableEntity { - /** - * Defines the maximum length of the message. - */ - private static final int MAX_MESSAGE_LENGTH = 16384; - /** * Contains the error message. */ @@ -101,17 +94,6 @@ public class StoredIncident extends SearchableEntity { @SearchContent private String user; - /** - * Truncates the message if it exceeds the maximum length. - */ - @BeforeSave - protected void truncateMessage() { - if (message.length() > MAX_MESSAGE_LENGTH) { - message = Strings.limit(message, MAX_MESSAGE_LENGTH, true); - message += "\nThe error message was too long and has been truncated."; - } - } - public String getMessage() { return message; } From 3e3bafecf44cbd60cb0621604ce630df63dc3160 Mon Sep 17 00:00:00 2001 From: mko Date: Tue, 7 May 2024 14:19:46 +0200 Subject: [PATCH 2/3] Adds message truncating in Protocols where the message is filled Fixes: SIRI-960 --- src/main/java/sirius/biz/protocol/Protocols.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/sirius/biz/protocol/Protocols.java b/src/main/java/sirius/biz/protocol/Protocols.java index a160657d1..8a88b1a86 100644 --- a/src/main/java/sirius/biz/protocol/Protocols.java +++ b/src/main/java/sirius/biz/protocol/Protocols.java @@ -128,7 +128,7 @@ public void handle(Incident incident) throws Exception { si.getMdc().put(t.getFirst(), t.getSecond()); } si.setUser(UserContext.getCurrentUser().getProtocolUsername()); - si.setMessage(incident.getException().getMessage()); + si.setMessage(Strings.limit(incident.getException().getMessage(), maxMessageLength, true)); si.setStack(NLS.toUserString(incident.getException())); si.setCategory(incident.getCategory()); si.setLastOccurrence(LocalDateTime.now()); From 6da3c11ff757c5a750948912bda8e55c9ff4dbc1 Mon Sep 17 00:00:00 2001 From: mko Date: Tue, 7 May 2024 16:16:49 +0200 Subject: [PATCH 3/3] Renames variables to increase the maintainability of the code Fixes: SIRI-960 --- .../java/sirius/biz/protocol/Protocols.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/sirius/biz/protocol/Protocols.java b/src/main/java/sirius/biz/protocol/Protocols.java index 8a88b1a86..0a8cbf42e 100644 --- a/src/main/java/sirius/biz/protocol/Protocols.java +++ b/src/main/java/sirius/biz/protocol/Protocols.java @@ -108,32 +108,32 @@ public void handle(Incident incident) throws Exception { try { LocalDate yesterday = LocalDate.now().minusDays(1); - StoredIncident si = null; + StoredIncident storedIncident = null; if (incident.getLocation() != null) { - si = elastic.select(StoredIncident.class) - .eq(StoredIncident.LOCATION, incident.getLocation()) - .where(Elastic.FILTERS.gt(StoredIncident.LAST_OCCURRENCE, yesterday)) - .queryFirst(); + storedIncident = elastic.select(StoredIncident.class) + .eq(StoredIncident.LOCATION, incident.getLocation()) + .where(Elastic.FILTERS.gt(StoredIncident.LAST_OCCURRENCE, yesterday)) + .queryFirst(); } - if (si == null) { - si = new StoredIncident(); - si.setLocation(incident.getLocation()); - si.setFirstOccurrence(LocalDateTime.now()); + if (storedIncident == null) { + storedIncident = new StoredIncident(); + storedIncident.setLocation(incident.getLocation()); + storedIncident.setFirstOccurrence(LocalDateTime.now()); } - si.setNumberOfOccurrences(si.getNumberOfOccurrences() + 1); - si.setNode(CallContext.getNodeName()); - for (Tuple t : incident.getMDC()) { - si.getMdc().put(t.getFirst(), t.getSecond()); + storedIncident.setNumberOfOccurrences(storedIncident.getNumberOfOccurrences() + 1); + storedIncident.setNode(CallContext.getNodeName()); + for (Tuple tuple : incident.getMDC()) { + storedIncident.getMdc().put(tuple.getFirst(), tuple.getSecond()); } - si.setUser(UserContext.getCurrentUser().getProtocolUsername()); - si.setMessage(Strings.limit(incident.getException().getMessage(), maxMessageLength, true)); - si.setStack(NLS.toUserString(incident.getException())); - si.setCategory(incident.getCategory()); - si.setLastOccurrence(LocalDateTime.now()); + storedIncident.setUser(UserContext.getCurrentUser().getProtocolUsername()); + storedIncident.setMessage(Strings.limit(incident.getException().getMessage(), maxMessageLength, true)); + storedIncident.setStack(NLS.toUserString(incident.getException())); + storedIncident.setCategory(incident.getCategory()); + storedIncident.setLastOccurrence(LocalDateTime.now()); - elastic.update(si); + elastic.update(storedIncident); } catch (Exception exception) { Elastic.LOG.SEVERE(exception); disableForOneMinute();