Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncates incident messages when they exceed configured value #1987

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/main/java/sirius/biz/protocol/Protocols.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> t : incident.getMDC()) {
si.getMdc().put(t.getFirst(), t.getSecond());
storedIncident.setNumberOfOccurrences(storedIncident.getNumberOfOccurrences() + 1);
storedIncident.setNode(CallContext.getNodeName());
for (Tuple<String, String> tuple : incident.getMDC()) {
storedIncident.getMdc().put(tuple.getFirst(), tuple.getSecond());
}
si.setUser(UserContext.getCurrentUser().getProtocolUsername());
si.setMessage(incident.getException().getMessage());
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();
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/sirius/biz/protocol/StoredIncident.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = 16_000;

/**
* Contains the error message.
*/
Expand Down Expand Up @@ -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;
}
Expand Down