Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] π Add type safety to Painless conditions (elastic#202603) (elasβ¦
β¦tic#203104) # Backport This will backport the following commits from `main` to `8.x`: - [π Add type safety to Painless conditions (elastic#202603)](elastic#202603) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Chris Cowan","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-05T13:58:36Z","message":"π Add type safety to Painless conditions (elastic#202603)\n\n## π Summary\r\n\r\nThis PR closes elastic/streams-program#18 by\r\nadding some basic type checking to the painless output for the Stream\r\nconditions. The new code will check to ensure that none of the fields\r\nused in the condition are `Map` objects. Then it wraps the if statement\r\nin a `try/catch`.\r\n\r\n### Condition\r\n```Typescript\r\n{\r\n and: [\r\n { field: 'log.logger', operator: 'eq' as const, value: 'nginx_proxy' },\r\n {\r\n or: [\r\n { field: 'log.level', operator: 'eq' as const, value: 'error' },\r\n { field: 'log.level', operator: 'eq' as const, value: 'ERROR' },\r\n ],\r\n },\r\n ],\r\n}\r\n```\r\n\r\n### Before\r\n\r\n```\r\n(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\"))\r\n```\r\n\r\n### After\r\n\r\n```\r\nif (ctx.log?.logger instanceof Map || ctx.log?.level instanceof Map) {\r\n return false;\r\n}\r\ntry {\r\n 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\"))) {\r\n return true;\r\n }\r\n return false;\r\n} catch (Exception e) {\r\n return false;\r\n}\r\n```","sha":"fe56d6d90af45b971ff82731c1ec7eb4c4c0eff3","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","v8.18.0","Feature:Streams"],"title":"π Add type safety to Painless conditions","number":202603,"url":"https://github.com/elastic/kibana/pull/202603","mergeCommit":{"message":"π Add type safety to Painless conditions (elastic#202603)\n\n## π Summary\r\n\r\nThis PR closes elastic/streams-program#18 by\r\nadding some basic type checking to the painless output for the Stream\r\nconditions. The new code will check to ensure that none of the fields\r\nused in the condition are `Map` objects. Then it wraps the if statement\r\nin a `try/catch`.\r\n\r\n### Condition\r\n```Typescript\r\n{\r\n and: [\r\n { field: 'log.logger', operator: 'eq' as const, value: 'nginx_proxy' },\r\n {\r\n or: [\r\n { field: 'log.level', operator: 'eq' as const, value: 'error' },\r\n { field: 'log.level', operator: 'eq' as const, value: 'ERROR' },\r\n ],\r\n },\r\n ],\r\n}\r\n```\r\n\r\n### Before\r\n\r\n```\r\n(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\"))\r\n```\r\n\r\n### After\r\n\r\n```\r\nif (ctx.log?.logger instanceof Map || ctx.log?.level instanceof Map) {\r\n return false;\r\n}\r\ntry {\r\n 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\"))) {\r\n return true;\r\n }\r\n return false;\r\n} catch (Exception e) {\r\n return false;\r\n}\r\n```","sha":"fe56d6d90af45b971ff82731c1ec7eb4c4c0eff3"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202603","number":202603,"mergeCommit":{"message":"π Add type safety to Painless conditions (elastic#202603)\n\n## π Summary\r\n\r\nThis PR closes elastic/streams-program#18 by\r\nadding some basic type checking to the painless output for the Stream\r\nconditions. The new code will check to ensure that none of the fields\r\nused in the condition are `Map` objects. Then it wraps the if statement\r\nin a `try/catch`.\r\n\r\n### Condition\r\n```Typescript\r\n{\r\n and: [\r\n { field: 'log.logger', operator: 'eq' as const, value: 'nginx_proxy' },\r\n {\r\n or: [\r\n { field: 'log.level', operator: 'eq' as const, value: 'error' },\r\n { field: 'log.level', operator: 'eq' as const, value: 'ERROR' },\r\n ],\r\n },\r\n ],\r\n}\r\n```\r\n\r\n### Before\r\n\r\n```\r\n(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\"))\r\n```\r\n\r\n### After\r\n\r\n```\r\nif (ctx.log?.logger instanceof Map || ctx.log?.level instanceof Map) {\r\n return false;\r\n}\r\ntry {\r\n 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\"))) {\r\n return true;\r\n }\r\n return false;\r\n} catch (Exception e) {\r\n return false;\r\n}\r\n```","sha":"fe56d6d90af45b971ff82731c1ec7eb4c4c0eff3"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Chris Cowan <[email protected]>
- Loading branch information