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

Updated Logstash attributes mapper to use template pattern #617

Merged
merged 2 commits into from
Nov 17, 2021

Conversation

asifsmohammed
Copy link
Collaborator

@asifsmohammed asifsmohammed commented Nov 17, 2021

Signed-off-by: Asif Sohail Mohammed [email protected]

Description

Added AbstractLogstashPluginAttributesMapper which leverages template pattern
Cleaned ModelConvertingLogstashVisitorTest class

Issues Resolved

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@asifsmohammed asifsmohammed requested a review from a team as a code owner November 17, 2021 06:08
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2021

Codecov Report

Merging #617 (293a3ba) into main (54f8ce7) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               main     #617   +/-   ##
=========================================
  Coverage     91.70%   91.70%           
  Complexity      571      571           
=========================================
  Files            72       72           
  Lines          1747     1747           
  Branches        145      145           
=========================================
  Hits           1602     1602           
  Misses          113      113           
  Partials         32       32           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54f8ce7...293a3ba. Read the comment docs.

Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

Overall this looks like great. I made a few comments that I'd like to see addressed.

return pluginSettings;
}

abstract void mapCustomAttributes(List<LogstashAttribute> logstashAttributes, LogstashAttributesMappings logstashAttributesMappings, Map<String, Object> pluginSettings);
Copy link
Member

Choose a reason for hiding this comment

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

This method and the other abstract method should be protected so that they are accessible to inheriting classes.

import java.util.Map;
import java.util.LinkedHashMap;

abstract class AbstractLogstashPluginAttributesMapper implements LogstashPluginAttributesMapper {
Copy link
Member

Choose a reason for hiding this comment

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

This class should be public so that classes in other packages can inherit it.

import java.util.Map;
import java.util.LinkedHashMap;

abstract class AbstractLogstashPluginAttributesMapper implements LogstashPluginAttributesMapper {
Copy link
Member

Choose a reason for hiding this comment

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

This class can have Javadocs for it.

import java.util.Map;
import java.util.LinkedHashMap;

abstract class AbstractLogstashPluginAttributesMapper implements LogstashPluginAttributesMapper {
Copy link
Member

Choose a reason for hiding this comment

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

You can write a unit test for this class and use Mockito spy's to verify the correct behavior.

One example: mock getCustomMappedAttributeNames to return a field and then verify that field was not mapped. Another example: Verify that mapCustomAttributes is called in when it there are custom attributes names and not called otherwise.

return pluginSettings;
}

abstract void mapCustomAttributes(List<LogstashAttribute> logstashAttributes, LogstashAttributesMappings logstashAttributesMappings, Map<String, Object> pluginSettings);
Copy link
Member

Choose a reason for hiding this comment

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

These two abstract methods should have Javadocs to explain their purpose to inheritors.

final Map<String, Object> pluginSettings = new LinkedHashMap<>(logstashAttributesMappings.getAdditionalAttributes());
final Map<String, String> mappedAttributeNames = logstashAttributesMappings.getMappedAttributeNames();

Collection<String> customMappedAttributeNames = getCustomMappedAttributeNames();
Copy link
Member

Choose a reason for hiding this comment

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

It might be a good idea to create a new HashSet here since the collection need not be a Set.

@asifsmohammed asifsmohammed merged commit 5f5cb41 into opensearch-project:main Nov 17, 2021
dapowers87 pushed a commit to dapowers87/data-prepper that referenced this pull request Nov 18, 2021
…h-project#617)

* Updated Logstash attributes mapper to use template pattern

Signed-off-by: Asif Sohail Mohammed <[email protected]>

Co-authored-by: Asif Sohail Mohammed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants