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

Make it possible to chain Beat processors in the script processor #11680

Merged

Conversation

andrewkroh
Copy link
Member

Prior to this change it was possible to construct individual Beat processors. This adds the ability
to chain them together in a list so that calling a single Run(event) function executes the list of
processors.

var localeProcessor = new processor.AddLocale();

var chain = new processor.Chain()
    .Add(localeProcessor)
    .Rename({
        fields: [
            {from: "event.timezone", to: "timezone"},
        ],
    })
    .Add(function(evt) {
        evt.Put("hello", "world");
    })
    .Build();

function process(evt) {
    return chain.Run(evt);
}

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.

@andrewkroh LGTM, do you want to add support for the new truncate and copy field in another PR?

"DecodeJSONFields": actions.NewDecodeJSONFields,
"Dissect": dissect.NewProcessor,
"DNS": dns.New,
"Rename": actions.NewRenameFields,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to add theses #11297 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'll add them and expose their constructors. I'm not really happy about having this list but until I come up with a better way to reuse the existing processor registry this works.

Copy link
Member Author

Choose a reason for hiding this comment

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

Constructors for copy_fields and truncate_fields are now exposed.

Prior to this change it was possible to construct individual Beat processors. This adds the ability
to chain them together in a list so that calling a single `Run(event)` function executes the list of
processors.

    var localeProcessor = new processor.AddLocale();

    var chain = new processor.Chain()
        .Add(localeProcessor)
        .Rename({
            fields: [
                {from: "event.timezone", to: "timezone"},
            ],
        })
        .Add(function(evt) {
            evt.Put("hello", "world");
        })
        .Build();

    function process(evt) {
        return chain.Run(evt);
    }
@andrewkroh andrewkroh force-pushed the feature/libbeat/chain-processors-in-js branch from 2297f93 to 06cdb0b Compare April 9, 2019 19:55
@andrewkroh andrewkroh merged commit 19e83b1 into elastic:master Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants