Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Conversation

@fzrvic
Copy link
Contributor

@fzrvic fzrvic commented Jul 23, 2021

No description provided.

return getMappings(message, mapping);
}

private List<DynamicMessage> getDynamicMessageFields(DynamicMessage message) {
Copy link
Contributor

@sravankorumilli sravankorumilli Jul 28, 2021

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<>();
Copy link
Contributor

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

Copy link
Contributor Author

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);
    }

}

if (DynamicMessageUtil.isUnknownFieldExist(message)) {
statsClient.count("kafka.error.records.count,type=unknownfields," + statsClient.getBqTags(), 1);
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will add log

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants