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

Add support for using expressions with formatString in JacksonEvent, use for index in OpenSearch sink #3032

Merged

Conversation

graytaylor0
Copy link
Member

@graytaylor0 graytaylor0 commented Jul 14, 2023

Description

This change adds support for using Data Prepper expressions in the formatString method for JacksonEvent, and uses this functionality for the index parameter in the OpenSearch sink. For example, the index can now be

index: "test-${some_key}-${some_data_prepper_expression}"

which will inject the value of some_key from the Event, and inject the result of the evaluated some_data_prepper_expression

Issues Resolved

Resolves #2864

Check List

  • New functionality includes testing.
  • New functionality has been documented.
    • 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.

…use for index in OpenSearch sink

Signed-off-by: Taylor Gray <[email protected]>
document_id_field: "document_id"
index: "copied-${index}"
document_id_field: "getMetadata(\"opensearch-document_id\")"
index: "${getMetadata(\"opensearch-index\"}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

WHat's the difference between index and document_id_field? Is ${} required?

Copy link
Member Author

Choose a reason for hiding this comment

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

document_id_field currently only supports a single field in the Event. It does not support formatting the document id like is done in index. We could add later potentially but right now document id either supports a field in the Event or it supports an expression


Object val;
if (Objects.nonNull(expressionEvaluator) && expressionEvaluator.isValidExpressionStatement(name)) {
val = expressionEvaluator.evaluate(name, this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can val here be null? If yes, the statement in line 342(below) will result in null pointer exception. Probably good idea to put null check in line 337 outside of if statement.

Copy link
Member Author

Choose a reason for hiding this comment

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

if the result of the evaluate method is null, should be just have it be literal string "null"? Or should we just leave it out of the format string?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a null check around the appending to the result

Signed-off-by: Taylor Gray <[email protected]>
@graytaylor0 graytaylor0 merged commit 8785bbf into opensearch-project:main Jul 18, 2023
44 checks passed
chenqi0805 pushed a commit that referenced this pull request Jul 19, 2023
…use for index in OpenSearch sink (#3032)

Add support for using expressions with formatString in JacksonEvent, use for index in OpenSearch sink

Signed-off-by: Taylor Gray <[email protected]>

---------

Signed-off-by: Taylor Gray <[email protected]>
Signed-off-by: George Chen <[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.

Ability to use Data Prepper expressions in the OpenSearch sink index and document_id_field
3 participants