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

Added configConverter which converts conf to yaml #584

Merged
merged 2 commits into from
Nov 13, 2021

Conversation

asifsmohammed
Copy link
Collaborator

@asifsmohammed asifsmohammed commented Nov 12, 2021

Description

Added ConfigConverter which takes .conf file path and returns .yaml file path

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 12, 2021 21:47
@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2021

Codecov Report

Merging #584 (4fb2563) into main (42c5954) will increase coverage by 0.17%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #584      +/-   ##
============================================
+ Coverage     92.12%   92.29%   +0.17%     
  Complexity      569      569              
============================================
  Files            71       71              
  Lines          1727     1727              
  Branches        144      144              
============================================
+ Hits           1591     1594       +3     
+ Misses          105      102       -3     
  Partials         31       31              
Impacted Files Coverage Δ
...java/com/amazon/dataprepper/pipeline/Pipeline.java 92.85% <0.00%> (+4.28%) ⬆️

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 42c5954...4fb2563. Read the comment docs.

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

class LogstashConfigConverterTest {
Copy link
Member

Choose a reason for hiding this comment

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

This test will have some overlap with the integration tests. If we aren't going to mock the internal classes, I think I'd prefer that we remove this test and only have the integration test to cover it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we can only have an integration test for this.

Copy link
Member

Choose a reason for hiding this comment

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

Then let's just remove this test and the input file.


ObjectMapper mapper = new ObjectMapper(factory);

String yamlFilePath = outputDirectory + "logstash.yaml";
Copy link
Member

Choose a reason for hiding this comment

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

Using string append to create paths can be problematic. Please use File or Paths to form this string.


LogstashMapper logstashMapper = new LogstashMapper();
PipelineModel pipelineModel = logstashMapper.mapPipeline(logstashConfiguration);
Map<String, Object> pipeline = Collections.singletonMap("log-pipeline", pipelineModel);
Copy link
Member

Choose a reason for hiding this comment

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

We don't know if the pipeline is a log-pipeline or not. I'd be interested in using the filename as the pipeline name. For example a file named local-log-ingest.yaml might be given the name local-log-ingest.

If we don't take that approach, maybe use a constant value like logstash-converted-pipeline.


ObjectMapper mapper = new ObjectMapper(factory);

String yamlFilePath = outputDirectory + "logstash.yaml";
Copy link
Member

Choose a reason for hiding this comment

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

Should we use the name of the original file in the generated file?

e.g. my-configuration-file.conf -> my-configuration-file.yaml.

Copy link
Collaborator Author

@asifsmohammed asifsmohammed Nov 12, 2021

Choose a reason for hiding this comment

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

That makes sense because the user knows their file name, so they can just look for .yaml file for their .conf file

@@ -0,0 +1,56 @@
package org.opensearch.dataprepper.logstash.parser;
Copy link
Member

Choose a reason for hiding this comment

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

Also, I think this should be in the org.opensearch.dataprepper.logstash package. You will need to update your usage of LogstashVisitor with the full package name.

Like this:

org.opensearch.dataprepper.logstash.parser.LogstashVisitor visitor = new org.opensearch.dataprepper.logstash.parser.LogstashVisitor();

LogstashParser parser = new LogstashParser(tokens);
ParseTree tree = parser.config();

org.opensearch.dataprepper.logstash.parser.LogstashVisitor visitor = new LogstashVisitor();
Copy link
Member

Choose a reason for hiding this comment

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

You need to have the fully qualified name on the right-side of the assignment, along with the new.

org.opensearch.dataprepper.logstash.parser.LogstashVisitor visitor = new org.opensearch.dataprepper.logstash.parser.LogstashVisitor();

factory.disable(YAMLGenerator.Feature.SPLIT_LINES);
factory.enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE);

ObjectMapper mapper = new ObjectMapper(factory);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify this by using the Builder pattern like:

ObjectMapper mapper = new ObjectMapper(YAMLFactory.builder()
                .disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
                .disable(YAMLGenerator.Feature.SPLIT_LINES)
                .enable(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR)
                .enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)
                .build());

.enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)
.build());

String confFileName = configurationFilePath.getFileName().toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have all the fields that should not be changed final?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, will update it

Copy link
Collaborator

@chenqi0805 chenqi0805 left a comment

Choose a reason for hiding this comment

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

Checked comments from @sshivanii addressed.

@asifsmohammed asifsmohammed merged commit 6412e9b into opensearch-project:main Nov 13, 2021
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.

5 participants