Skip to content

Added support of newline in output codec#6423

Merged
oeyh merged 3 commits into
opensearch-project:mainfrom
Subrahmanyam-Gollapalli:newline-output-codec
Feb 18, 2026
Merged

Added support of newline in output codec#6423
oeyh merged 3 commits into
opensearch-project:mainfrom
Subrahmanyam-Gollapalli:newline-output-codec

Conversation

@Subrahmanyam-Gollapalli
Copy link
Copy Markdown
Contributor

@Subrahmanyam-Gollapalli Subrahmanyam-Gollapalli commented Jan 23, 2026

Description

Added support of newline in the output codec

Issues Resolved

This new support hasn't resolved anything. It gives support to use newline in the output codec. We have this in Logstash, and we need it in Data Prepper. Test cases are also added.

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

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.

Signed-off-by: Subrahmanyam-Gollapalli <subrahmanyam.gollapalli@freshworks.com>
Copy link
Copy Markdown
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.

Thank you @Subrahmanyam-Gollapalli for making this contribution! I have a few comments, but overall this looks like a good change.

if (event.containsKey(MESSAGE_FIELD)) {
Object messageObj = event.get(MESSAGE_FIELD, Object.class);
if (messageObj != null) {
message = messageObj.toString();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tend to think that we should only write this if it is a string. If there is an object here like an array, you'd get some Java identifier that is not very helpful.

Maybe this could be a configuration. But, I think the default should be to only use known types.

}

// If message is null or empty, write empty string
if (message == null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the default behavior should be not to write anything if the data is empty. You could add a configuration to write empty events.

Perhaps a configuration named include_empty_objects similar to the ndjson input codec. Here is that configuration:

/**
* By default, we will not create events for empty objects. However, we will
* permit users to include them if they desire.
*/
@JsonProperty("include_empty_objects")
private boolean includeEmptyObjects = false;
public boolean isIncludeEmptyObjects() {
return includeEmptyObjects;
}


@Override
public void writeEvent(final Event event, final OutputStream outputStream) throws IOException {
Objects.requireNonNull(event);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can this call doWriteEvent to consolidate the logic?

@@ -0,0 +1,123 @@
/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have an updated license header format. Please update all the files.

See: https://github.com/opensearch-project/data-prepper/blob/main/CONTRIBUTING.md#license-headers

final OutputCodecContext codecContext = new OutputCodecContext();

final Map<String, Object> eventData = new HashMap<>();
eventData.put("message", "r_id=2bb2bd0aeece11f0bea286fb87d48915-ticket_update,tp=00-13a3bb055e6b589dbc0f952e0d75020a-1f2e986790c19742-01");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather than this static string, generate the value as a new UUID. This is a pattern found throughout the project. Then compare against that.

Signed-off-by: Subrahmanyam-Gollapalli <subrahmanyam.gollapalli@freshworks.com>
@dlvenable
Copy link
Copy Markdown
Member

## ⚠️ License Header Violations Found\\n\\nThe following newly added files are missing required license headers:\\n\\n- `data-prepper-plugins/newline-codecs/src/test/java/org/opensearch/dataprepper/plugins/codec/newline/NewlineDelimitedOutputCodecTest.java`\\n\\nPlease add the appropriate license header to each file and push your changes.\\n\\n**See the license header requirements:** https://github.com/opensearch-project/data-prepper/blob/main/CONTRIBUTING.md#license-headers

Please update the license headers per the comment above.

Signed-off-by: Subrahmanyam-Gollapalli <subrahmanyam.gollapalli@freshworks.com>
return NEWLINE;
}

private static void doWriteEvent(final OutputStream outputStream, final Event event, final OutputCodecContext codecContext, final boolean includeEmptyObjects) throws IOException {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codecContext is not used anywhere in this method.

@oeyh oeyh merged commit 00d41cb into opensearch-project:main Feb 18, 2026
71 of 72 checks passed
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