-
Notifications
You must be signed in to change notification settings - Fork 148
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
Cache conditions when applying variables to config #6229
Conversation
Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane) |
9165189
to
83fcb38
Compare
"data": "info", | ||
}}) | ||
|
||
input := NewKey("condition", NewStrVal("${other.data} == 'info'")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a test for the case where the condition is edited for the same input.
As an implementation question does the cache need to be invalidated when this happens, or is a new AST node created so that we don't need to care?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not possible to update the configuration without generating a new AST. That means its not possible for the value of a key to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, if there's already a test that conditions edits (or any configuration edit) results in a new AST node then that covers this.
If there isn't, we should add one. Reusing a cached condition would be quite a difficult bug to track down from an end user report.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ability to modify an AST is very limited to begin with. The only public API to do it is the Insert
function, which only works on Dicts and Lists. I can add a test where I replace a key in a dict and verify the condition doesn't get saved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request is now in conflicts. Could you fix it? 🙏
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
"data": "info", | ||
}}) | ||
|
||
input := NewKey("condition", NewStrVal("${other.data} == 'info'")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not possible to update the configuration without generating a new AST. That means its not possible for the value of a key to change.
# Conflicts: # internal/pkg/agent/transpiler/ast_test.go
83fcb38
to
ff23be4
Compare
Quality Gate passedIssues Measures |
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754)
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754) # Conflicts: # internal/pkg/agent/transpiler/ast_test.go
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754) # Conflicts: # internal/pkg/agent/transpiler/ast_test.go
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754) # Conflicts: # internal/pkg/agent/transpiler/ast_test.go
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754) # Conflicts: # internal/pkg/agent/transpiler/ast_test.go Co-authored-by: Mikołaj Świątek <[email protected]>
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754) Co-authored-by: Mikołaj Świątek <[email protected]>
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754) # Conflicts: # internal/pkg/agent/transpiler/ast_test.go # Conflicts: # internal/pkg/agent/transpiler/ast_test.go
* Cache conditions when applying variables to config # Conflicts: # internal/pkg/agent/transpiler/ast_test.go * Add test for AST insertion (cherry picked from commit cab5754) # Conflicts: # internal/pkg/agent/transpiler/ast_test.go # Conflicts: # internal/pkg/agent/transpiler/ast_test.go Co-authored-by: Mikołaj Świątek <[email protected]>
What does this PR do?
Our configurations can have conditional sections. The conditions are expressed in an EQL-like syntax, and we parse the expressions lazily on evaluation. However, we don't cache the parsed expression, and parse it every time it's evaluated. This change instead only parses the condition expression once, and it's then cached in the AST node.
Why is it important?
When there are a lot of variables from dynamic providers - notably in Kubernetes, on a Node with a lot of Pods - we end up spending significant resources on re-parsing the condition expressions for every var entry.
See benchstat showing the effect of this change on the benchmark from #6180 (not that this includes #6184, as otherwise we just make a copy before applying and never actually use the cache):
Checklist
./changelog/fragments
using the changelog toolHow to test this PR locally
Unit tests are sufficient, the benchmark in #6180 helps as well.
Related issues