[Expression] Cached expression can keep their own side effects#216519
[Expression] Cached expression can keep their own side effects#216519dej611 merged 12 commits intoelastic:mainfrom
Conversation
| } | ||
| const transformedRawResponse = cloneDeep(response.rawResponse); | ||
| if (!transformedRawResponse.aggregations) { | ||
| let transformedRawResponse = response.rawResponse; |
There was a problem hiding this comment.
Just a tiny perf improvement
| ) { | ||
| return defer(async () => { | ||
| const { aggs, indexPatterns, searchSource, getNow } = await getStartDependencies(); | ||
| const [{ aggs, indexPatterns, searchSource, getNow }, { handleEsaggsRequest }] = |
There was a problem hiding this comment.
Another tiny perf improvement
|
Pinging @elastic/kibana-visualizations (Team:Visualizations) |
jbudz
left a comment
There was a problem hiding this comment.
packages/kbn-optimizer/limits.yml
| this.responses = responses; | ||
| } | ||
|
|
||
| public reset(): void { |
There was a problem hiding this comment.
Should reset also reset this.responses?
There was a problem hiding this comment.
Due to the WeakMap nature the responses should be empty as soon as the requests get cleared.
| constructor() { | ||
| super(); | ||
| this.requests = new Map(); | ||
| this.responses = new WeakMap(); |
There was a problem hiding this comment.
Why is responses a WeakMap instead of just a map keyed to the request id?
There was a problem hiding this comment.
I thought about that, but:
- there's no need to list the entries
- using the
requestitself saves amapcycle altogether - it could
resetas side effect automatically
Given the use cases it makes no specific difference between the two, other than no providing the iterator API.
nreese
left a comment
There was a problem hiding this comment.
kibana-presentation changes LGTM
code review only
lukasolson
left a comment
There was a problem hiding this comment.
Tested and the behavior seems to be fixed (for Lens visualizations using classic mode).
The bug still happens for ES|QL visualizations on a dashboard using inline editing, so we will need to make the same changes to the esql function.
I wanted to ask a couple of quick questions regarding the approach:
- Could this be fixed by moving the
this.context.inspectorAdapters.requests?.reset();call into theesaggsfunction (prior to making the search request)? It seems odd we're clearing the inspector adapters in the executor but then utilizing them inside the functions themselves. - If we decide this approach is best, can we somehow tie these
sideEffectsinto the same place we register theallowCache: trueso that it's clear they're related? Right now it's not clear if you support caching that you have to also worry about side effects.
Great catch! On it...
Makes sense. I'll try 1) or improve the current code with 2) if it doesn't work. |
|
Starting backport for target branches: 8.16, 8.17, 8.18, 8.x, 9.0 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
…ic#216519) ## Summary Fixes the elastic#207204 This PR introduces a new complementary function for an Expression definition named `sideEffects`, this goes together with the other `fn` function and it is used to restore any side effect when the caching system kicks in.  I haven't found how to programmatically test this. Will add an FTR if it can be reliable to reproduce an expression caching scenario. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### Release notes The request inspector now shows the correct request and response in any successful scenario.
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
…ic#216519) ## Summary Fixes the elastic#207204 This PR introduces a new complementary function for an Expression definition named `sideEffects`, this goes together with the other `fn` function and it is used to restore any side effect when the caching system kicks in.  I haven't found how to programmatically test this. Will add an FTR if it can be reliable to reproduce an expression caching scenario. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### Release notes The request inspector now shows the correct request and response in any successful scenario. (cherry picked from commit 6984530) # Conflicts: # packages/kbn-optimizer/limits.yml
…ic#216519) ## Summary Fixes the elastic#207204 This PR introduces a new complementary function for an Expression definition named `sideEffects`, this goes together with the other `fn` function and it is used to restore any side effect when the caching system kicks in.  I haven't found how to programmatically test this. Will add an FTR if it can be reliable to reproduce an expression caching scenario. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### Release notes The request inspector now shows the correct request and response in any successful scenario. (cherry picked from commit 6984530) # Conflicts: # packages/kbn-optimizer/limits.yml
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…ic#216519) ## Summary Fixes the elastic#207204 This PR introduces a new complementary function for an Expression definition named `sideEffects`, this goes together with the other `fn` function and it is used to restore any side effect when the caching system kicks in.  I haven't found how to programmatically test this. Will add an FTR if it can be reliable to reproduce an expression caching scenario. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### Release notes The request inspector now shows the correct request and response in any successful scenario. (cherry picked from commit 6984530) # Conflicts: # packages/kbn-optimizer/limits.yml
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
5 similar comments
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
…#216519) (#218425) # Backport This will backport the following commits from `main` to `8.18`: - [[Expression] Cached expression can keep their own side effects (#216519)](#216519) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Marco Liberati","email":"dej611@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-11T12:50:47Z","message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:ExpressionLanguage","Team:Visualizations","backport missing","backport:prev-minor","backport:prev-major","v9.1.0","v8.19.0","v8.18.1","v9.0.1"],"title":"[Expression] Cached expression can keep their own side effects","number":216519,"url":"https://github.com/elastic/kibana/pull/216519","mergeCommit":{"message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216519","number":216519,"mergeCommit":{"message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
…216519) (#218419) # Backport This will backport the following commits from `main` to `9.0`: - [[Expression] Cached expression can keep their own side effects (#216519)](#216519) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Marco Liberati","email":"dej611@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-11T12:50:47Z","message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:ExpressionLanguage","Team:Visualizations","backport missing","backport:prev-minor","backport:prev-major","v9.1.0","v8.19.0","v8.18.1","v9.0.1"],"title":"[Expression] Cached expression can keep their own side effects","number":216519,"url":"https://github.com/elastic/kibana/pull/216519","mergeCommit":{"message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216519","number":216519,"mergeCommit":{"message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
…216519) (#218422) # Backport This will backport the following commits from `main` to `8.x`: - [[Expression] Cached expression can keep their own side effects (#216519)](#216519) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Marco Liberati","email":"dej611@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-11T12:50:47Z","message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:ExpressionLanguage","Team:Visualizations","backport missing","backport:prev-minor","backport:prev-major","v9.1.0","v8.19.0","v8.18.1","v9.0.1"],"title":"[Expression] Cached expression can keep their own side effects","number":216519,"url":"https://github.com/elastic/kibana/pull/216519","mergeCommit":{"message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.18","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216519","number":216519,"mergeCommit":{"message":"[Expression] Cached expression can keep their own side effects (#216519)\n\n## Summary\n\nFixes the #207204 \n\nThis PR introduces a new complementary function for an Expression\ndefinition named `sideEffects`, this goes together with the other `fn`\nfunction and it is used to restore any side effect when the caching\nsystem kicks in.\n\n\n\n\nI haven't found how to programmatically test this.\nWill add an FTR if it can be reliable to reproduce an expression caching\nscenario.\n\n### Checklist\n\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n\n### Release notes\n\nThe request inspector now shows the correct request and response in any\nsuccessful scenario.","sha":"6984530aa0ef9d3d5e93ea22f8e816cc2e222a25"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
Summary
Fixes the #207204
This PR introduces a new complementary function for an Expression definition named
sideEffects, this goes together with the otherfnfunction and it is used to restore any side effect when the caching system kicks in.I haven't found how to programmatically test this.
Will add an FTR if it can be reliable to reproduce an expression caching scenario.
Checklist
Release notes
The request inspector now shows the correct request and response in any successful scenario.