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 decode base64 field processor #11914

Merged
merged 10 commits into from
Jun 18, 2019

Conversation

mmatur
Copy link
Contributor

@mmatur mmatur commented Apr 24, 2019

Description

This PR adds a new processor to be able to decode base64.

The decode_base64_field processor decodes field containing Base64 strings.

processors:
 - decode_base64_field:
     field: "field1"
     target: ""

The decode_base64_field processor has the following configuration settings:

  • field:: The field containing Base64 strings to decode.
  • target:: (Optional) The field under which the decoded Base64 will be written. By
    default the decoded Base64 object replaces the string field from which it was
    read.
    target with an empty string (target: ""). Note that the null value (target:)
    is treated as if the field was not set at all.

@mmatur mmatur requested a review from a team as a code owner April 24, 2019 07:38
@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@kvch
Copy link
Contributor

kvch commented Apr 24, 2019

jenkins test this

@ph
Copy link
Contributor

ph commented Apr 24, 2019

jenkins test this please

@mmatur mmatur force-pushed the feature/processor-base64-decode branch 3 times, most recently from 3db61ae to 4f32f09 Compare April 29, 2019 06:35

func (f *decodeBase64Fields) Run(event *beat.Event) (*beat.Event, error) {
data, err := event.GetValue(f.field)
if err != nil && errors.Cause(err) != common.ErrKeyNotFound {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be good to make this configurable, just like in case of other processors. By adding fail_on_error and ignore_missing users could eliminate flooding the logs of Beats if the keys are not present in the event. See the implementation in rename processor: https://github.com/elastic/beats/blob/master/libbeat/processors/actions/rename.go#L36

@mmatur mmatur force-pushed the feature/processor-base64-decode branch 3 times, most recently from 0c1de6a to c864d5f Compare April 30, 2019 15:12
@mmatur mmatur force-pushed the feature/processor-base64-decode branch from c864d5f to 814bd5d Compare May 17, 2019 16:40
@ph
Copy link
Contributor

ph commented May 23, 2019

the code looks good, I am just worried about the usage and the configuration. The current code can work with a single instance of a processors on multiple fields.

I wonder if it's better to make it a 1:1 mapping, each field need to define his own processors. I am thinking about this because the errors handling looks stranges when it's applied on multiple fields.

@kvch in your comments #11914 (comment) were you asking only to add errors handling to the processors or allow a single processor to operate on multiple fields?

@andrewkroh
Copy link
Member

I wonder if it's better to make it a 1:1 mapping, each field need to define his own processors. I am thinking about this because the errors handling looks stranges when it's applied on multiple fields.

So true. This really complicates things in other processors and I think having a 1:1 relationship like Ingest Node has would simplify many things.

@andrewkroh
Copy link
Member

@mmatur Can you please also register this with the script processor so that it can be used there as well. Just need to add a line here:

var constructors = map[string]processors.Constructor{
"AddCloudMetadata": add_cloud_metadata.New,
"AddDockerMetadata": add_docker_metadata.New,
"AddFields": actions.CreateAddFields,

@mmatur mmatur force-pushed the feature/processor-base64-decode branch 2 times, most recently from 3f47bff to 4021509 Compare May 27, 2019 08:36
@kvch
Copy link
Contributor

kvch commented May 27, 2019

@ph Yes, I would let one base64 processor work on multiple fields as in case of other processors. I think confusion around which field lead to an error can be avoided by adding the key name to the error message. WDYT?
My only concern regarding 1:1 mapping is having an unnecessarily long list of processors in configurations.

@mmatur mmatur force-pushed the feature/processor-base64-decode branch from 4021509 to ddb04c9 Compare June 13, 2019 09:47
@mmatur
Copy link
Contributor Author

mmatur commented Jun 13, 2019

@kvch @ph @andrewkroh do I need to keep 1:1 mapping?

@kvch
Copy link
Contributor

kvch commented Jun 13, 2019

Keep it please.

@mmatur
Copy link
Contributor Author

mmatur commented Jun 13, 2019

Thanks @kvch. My PR seems to be ready ;)

Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

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

Almost there 👍 , just added a note for the documentation and a behavior changes when a type assertion fails.

@ph
Copy link
Contributor

ph commented Jun 13, 2019

Jenkins test this please

Copy link
Contributor

@kvch kvch 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!

@ph
Copy link
Contributor

ph commented Jun 14, 2019

Jenkins test this

@ph
Copy link
Contributor

ph commented Jun 14, 2019

@kvch I've retriggerred jenkins build just to make sure.

@ph ph merged commit 4d9b1d0 into elastic:master Jun 18, 2019
@ph ph added the needs_backport PR is waiting to be backported to other branches. label Jun 18, 2019
@ph
Copy link
Contributor

ph commented Jun 18, 2019

Thanks @mmatur for adding this :)

@mmatur mmatur deleted the feature/processor-base64-decode branch June 18, 2019 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libbeat needs_backport PR is waiting to be backported to other branches. review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants