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

Configurable MIME type for mustache template encoding on set processor #65314

Merged

Conversation

danhermann
Copy link
Contributor

The set processor permits the value that it sets to be specified with a Mustache template snippet. Our Mustache script engine allows three different MIME encodings to be used when writing the value that the snippet evaluates to but the Set processor was hard-coded to always use the application/json MIME type. This adds an optional mime_type property to the Set processor that may be set to any of the three MIME types (application/json, text/plain, application/x-www-form-urlencoded) that the Mustache script engine supports. The default type remains application/json.

Closes #65115

@danhermann danhermann added >enhancement :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP v8.0.0 v7.11.0 labels Nov 20, 2020
@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Nov 20, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (Team:Core/Features)

@danhermann
Copy link
Contributor Author

@elasticmachine update branch

@probakowski probakowski self-requested a review December 3, 2020 16:12
Copy link
Contributor

@probakowski probakowski left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @danhermann !
We should add documentation for this new property either in this PR or in the follow up

@danhermann
Copy link
Contributor Author

Thank you, @probakowski! I will open another PR shortly with documentation for this option.

@danhermann danhermann merged commit eddab39 into elastic:master Jan 7, 2021
@danhermann danhermann deleted the 65115_set_processor_escape_chars branch January 7, 2021 13:41
Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

I left some questions which might be related to my work here #66857
I am mostly concerned about the mime_type name and that we duplicate the media types allowed by our templating engine

@@ -110,10 +111,11 @@ public SetProcessor create(Map<String, Processor.Factory> registry, String proce
String description, Map<String, Object> config) throws Exception {
String field = ConfigurationUtils.readStringProperty(TYPE, processorTag, config, "field");
String copyFrom = ConfigurationUtils.readOptionalStringProperty(TYPE, processorTag, config, "copy_from");
String mimeType = ConfigurationUtils.readMimeTypeProperty(TYPE, processorTag, config, "mime_type", "application/json");
Copy link
Contributor

Choose a reason for hiding this comment

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

are we sure we want mime_type as a name here? I thought mime was replace with media_type
but wouldn't content_type be more consistent with what we have in mustache templating engine?

Copy link
Contributor

@pgomulka pgomulka Jan 7, 2021

Choose a reason for hiding this comment

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

or we could consider to rename the content_type to media_type (in mustache template engine)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to rename to whatever is most appropriate. I went with mime_type because that is what was used in CustomMustacheFactory but I would agree that media_type or possibly content_type would be better.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to follow up with a change to media_type to be more correct.

@@ -49,6 +49,7 @@

public static final String TAG_KEY = "tag";
public static final String DESCRIPTION_KEY = "description";
public static final String[] VALID_MIME_TYPES = {"application/json", "text/plain", "application/x-www-form-urlencoded"};
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 want the se hardcoded? What if someone specifies application/json; charset=utf-8 ?
Would it be of any help if this bit was unified with what CustomMustacheFactory defines? I made an attempt here https://github.com/elastic/elasticsearch/pull/66857/files#diff-207cacc1e4a5b24109a693c0b63dd762156452bb5984b5ce04499b28e6c191e8R28

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that unifying this set of options would be good. I can do that after you merge that PR. I don't believe that we want to allow the specification of a particular character set for the use case of the ingest processor, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that #66857 has been closed in favor of #67677, I believe the only improvement that can be made here is changing content_type to media_type. I'll go ahead and open a PR for that.

@danhermann
Copy link
Contributor Author

@elastic/es-ui, is there work required on the UI side to update Kibana auto-complete with the new media_type option on this processor?

@cjcenizal
Copy link
Contributor

@danhermann Yes, we'll update Console to autocomplete with this new option when we regenerate all of the autocomplete definitions for 7.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP >enhancement Team:Data Management Meta label for data/management team v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The set processor introduces unwanted escape characters (backslashes) when using templated fields
7 participants