-
Notifications
You must be signed in to change notification settings - Fork 23
fix unknown fields error count metric, change exception message #80
base: master
Are you sure you want to change the base?
Conversation
return getMappings(message, mapping); | ||
} | ||
|
||
private List<DynamicMessage> getDynamicMessageFields(DynamicMessage message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed over call, using an accumulator will help in collecting the messages properly
final List<DynamicMessage> allNestedMessagesInProto = getAllNestedMessages(message, List.of(message));
List<DynamicMessage> messageWithUnknownFields = getMessageWithUnknownFields(allNestedMessagesInProto);
if (messageWithUnknownFields.size() > 0) {
statsClient.count("kafka.error.records.count,type=unknownfields," + statsClient.getBqTags(), 1);
if (failOnUnknownFields) {
throw new UnknownProtoFieldFoundException(message.toString());
}
}
return getMappings(message, mapping);
}
private List<DynamicMessage> getAllNestedMessages(DynamicMessage message, List<DynamicMessage> nestedMessages) {
List<DynamicMessage> children = message.getAllFields().values().stream()
.filter(v -> v instanceof DynamicMessage)
.map(o -> (DynamicMessage) o)
.collect(Collectors.toList());
nestedMessages.addAll(children);
children.forEach(m -> getAllNestedMessages(m, nestedMessages));
return nestedMessages;
}
if (dynamicMessage == null) { | ||
return false; | ||
} | ||
List<DynamicMessage> dynamicMessageFields = new LinkedList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the root message should be there in the dynamicMessageFields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it automatically add every DynamicMessage to accumulator when traversing the each of the DynamicMessage trees, including the very first node (root)
private static void collectNestedFields(DynamicMessage root, List<DynamicMessage> accumulator) {
List<DynamicMessage> nestedChild = root.getAllFields().values().stream()
.filter(v -> v instanceof DynamicMessage)
.map(o -> (DynamicMessage) o)
.collect(Collectors.toList());
nestedChild.forEach(m -> collectNestedFields(m, accumulator));
accumulator.add(root);
}
@@ -34,22 +34,21 @@ public RowMapper(ColumnMapping mappings) { | |||
if (mapping == null) { | |||
throw new ConfigurationException("BQ_PROTO_COLUMN_MAPPING is not configured"); | |||
} | |||
|
|||
if (DynamicMessageUtil.isUnknownFieldExist(message)) { | |||
statsClient.count("kafka.error.records.count,type=unknownfields," + statsClient.getBqTags(), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log the message with a warn when when unknowfields exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will add log
No description provided.