forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Add type safety to Painless conditions (elastic#202603)
## π Summary This PR closes elastic/streams-program#18 by adding some basic type checking to the painless output for the Stream conditions. The new code will check to ensure that none of the fields used in the condition are `Map` objects. Then it wraps the if statement in a `try/catch`. ### Condition ```Typescript { and: [ { field: 'log.logger', operator: 'eq' as const, value: 'nginx_proxy' }, { or: [ { field: 'log.level', operator: 'eq' as const, value: 'error' }, { field: 'log.level', operator: 'eq' as const, value: 'ERROR' }, ], }, ], } ``` ### Before ``` (ctx.log?.logger !== null && ctx.log?.logger == "nginx_proxy") && ((ctx.log?.level !== null && ctx.log?.level == "error") || (ctx.log?.level !== null && ctx.log?.level == "ERROR")) ``` ### After ``` if (ctx.log?.logger instanceof Map || ctx.log?.level instanceof Map) { return false; } try { if ((ctx.log?.logger !== null && ctx.log?.logger == "nginx_proxy") && ((ctx.log?.level !== null && ctx.log?.level == "error") || (ctx.log?.level !== null && ctx.log?.level == "ERROR"))) { return true; } return false; } catch (Exception e) { return false; } ```
- Loading branch information
1 parent
d20862f
commit a983938
Showing
3 changed files
with
376 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.