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

UNOMI-846: improve log for event validation #687

Merged
merged 1 commit into from
Oct 14, 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
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOGGER.isDebugEnabled() should be removed

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
Loading