Skip to content

Commit

Permalink
UNOMI-846: improve log for event validation (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsinovassin authored Oct 14, 2024
1 parent 9022fc3 commit 64aa2a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public boolean isValid(String data, String schemaId) {
try {
JsonNode jsonNode = parseData(data);
JsonSchema jsonSchema = getJsonSchema(schemaId);
return validate(jsonNode, jsonSchema).size() == 0;
return validate(jsonNode, jsonSchema).isEmpty();
} catch (ValidationException e) {
LOGGER.debug("{}", e.getMessage(), e);
LOGGER.warn("{}", e.getMessage(), e);
}
return false;
}
Expand All @@ -102,7 +102,7 @@ public boolean isEventValid(String event) {
try {
return validateEvent(event).isEmpty();
} catch (ValidationException e) {
LOGGER.debug("{}", e.getMessage(), e);
LOGGER.warn("{}", e.getMessage(), e);
}
return false;
}
Expand Down Expand Up @@ -134,6 +134,7 @@ public Map<String, Set<ValidationError>> validateEvents(String events) throws Va
}
}
} catch (ValidationException e) {
LOGGER.warn("An error occurred during the validation of your event - switch to DEBUG log level for more information.");
LOGGER.debug("Validation error : {}", e.getMessage());
Set<ValidationError> errors = buildCustomErrorMessage(e.getMessage());
String eventTypeOrErrorKey = eventType != null ? eventType : GENERIC_ERROR_KEY;
Expand Down Expand Up @@ -225,10 +226,10 @@ private Set<ValidationError> validate(JsonNode jsonNode, JsonSchema jsonSchema)
try {
Set<ValidationMessage> validationMessages = jsonSchema.validate(jsonNode);

if (LOGGER.isDebugEnabled() && !validationMessages.isEmpty()) {
LOGGER.debug("Schema validation found {} errors while validating against schema: {}", validationMessages.size(), jsonSchema.getCurrentUri());
if (!validationMessages.isEmpty()) {
LOGGER.warn("Schema validation found {} errors while validating against schema: {}", validationMessages.size(), jsonSchema.getCurrentUri());
for (ValidationMessage validationMessage : validationMessages) {
LOGGER.debug("Validation error: {}", validationMessage);
LOGGER.warn("Validation error: {}", validationMessage);
}
}

Expand Down
2 changes: 0 additions & 2 deletions rest/src/main/java/org/apache/unomi/utils/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ public static List<Event> filterValidEvents(ArrayNode eventsNode, SchemaService
for (JsonNode event : eventsNode) {
if (schemaService.isEventValid(event.toString())) {
filteredEvents.add(jsonParser.getCodec().treeToValue(event, Event.class));
} else {
LOGGER.error("An event was rejected - switch to DEBUG log level for more information OR test the payload of your event against the \"validateEvent\" endpoint.");
}
}
return filteredEvents;
Expand Down

0 comments on commit 64aa2a8

Please sign in to comment.