Skip to content

Commit

Permalink
Add WARNING prefix to fpd type normalization warnings (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraslavskiyAndrey authored Sep 15, 2020
1 parent 62ab956 commit 0dae95c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/prebid/server/auction/OrtbTypesResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private JsonNode normalizeNode(JsonNode containerNode, String nodeName,
() -> toCommaSeparatedTextNode(containerObjectNode, fieldName, nodeName, nodePrefix,
warnings)));
} else {
warnings.add(String.format("FDP warning: %s%s field ignored. Expected type is object, but was `%s`.",
warnings.add(String.format("%s%s field ignored. Expected type is object, but was `%s`.",
nodePrefix, nodeName, containerNode.getNodeType().name()));
return null;
}
Expand Down Expand Up @@ -252,14 +252,18 @@ private static boolean isTextualArray(ArrayNode arrayNode) {
private void processWarnings(List<String> resolverWarning, List<String> warnings, String containerValue,
String referer, String containerName) {
if (CollectionUtils.isNotEmpty(resolverWarning)) {
warnings.addAll(resolverWarning);
warnings.addAll(updateWithWarningPrefix(resolverWarning));
// log only 1% of cases
if (System.currentTimeMillis() % 100 == 0) {
logger.info(String.format("%s. \n Referer = %s and %s = %s",
logger.info(String.format("WARNINGS: %s. \n Referer = %s and %s = %s",
String.join("\n", resolverWarning),
StringUtils.isNotBlank(referer) ? referer : UNKNOWN_REFERER,
containerName, containerValue));
}
}
}

private List<String> updateWithWarningPrefix(List<String> resolverWarning) {
return resolverWarning.stream().map(warning -> "WARNING: " + warning).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public void normalizeTargetingShouldConvertArrayToFirstElementFieldForUserAndWri
// then
assertThat(inputParam).isEqualTo(mapper.createObjectNode().set("user",
mapper.createObjectNode().put("gender", "male")));
assertThat(errors).containsOnly("Incorrect type for first party data field targeting.user.gender, expected is"
+ " string, but was an array of strings. Converted to string by taking first element of array.");
assertThat(errors).containsOnly("WARNING: Incorrect type for first party data field targeting.user.gender,"
+ " expected is string, but was an array of strings. Converted to string by taking first element "
+ "of array.");
}

@Test
Expand All @@ -57,8 +58,9 @@ public void normalizeTargetingShouldConvertArrayToCommaSeparatedStringFieldForUs
// then
assertThat(inputParam).isEqualTo(mapper.createObjectNode().set("user",
mapper.createObjectNode().put("keywords", "keyword1,keyword2")));
assertThat(errors).containsOnly("Incorrect type for first party data field targeting.user.keywords, expected is"
+ " string, but was an array of strings. Converted to string by separating values with comma.");
assertThat(errors).containsOnly("WARNING: Incorrect type for first party data field targeting.user.keywords,"
+ " expected is string, but was an array of strings. Converted to string by separating values with"
+ " comma.");
}

@Test
Expand All @@ -85,7 +87,7 @@ public void normalizeTargetingToCommaSeparatedTextNodeShouldWriteMessageAndRemov

// then
assertThat(inputParam).isEqualTo(mapper.createObjectNode().set("user", mapper.createObjectNode()));
assertThat(errors).containsOnly("Incorrect type for first party data field targeting.user.keywords,"
assertThat(errors).containsOnly("WARNING: Incorrect type for first party data field targeting.user.keywords,"
+ " expected strings, but was `ARRAY of different types`. Failed to convert to correct type.");
}

Expand All @@ -101,7 +103,7 @@ public void normalizeTargetingToFirstElementTextNodeShouldWriteMessageAndRemoveF

// then
assertThat(inputParam).isEqualTo(mapper.createObjectNode().set("user", mapper.createObjectNode()));
assertThat(errors).containsOnly("Incorrect type for first party data field targeting.user.gender,"
assertThat(errors).containsOnly("WARNING: Incorrect type for first party data field targeting.user.gender,"
+ " expected strings, but was `NUMBER`. Failed to convert to correct type.");
}

Expand Down

0 comments on commit 0dae95c

Please sign in to comment.