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

fix unknown fields error count metric, change exception message #80

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

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

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

@@ -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);
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.

None yet

2 participants