-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[filebeat][httpjson]- Added min & max functions to the template engine #36036
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
Pinging @elastic/security-external-integrations (Team:Security-External Integrations) |
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.
FWIW consul-template (MPL-2.0) has a pretty complete implementation of min and max functions. sprig
also has implementations.
@andrewkroh made the min/max functions generic in a similar fashion. |
This pull request is now in conflicts. Could you fix it? 🙏
|
@efd6 I've reworked the min max functions to be more specific. |
@efd6 made suggested changes. |
@efd6 if all looks ok, are we good for merging atm ? |
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.
We don't have a need to support lists of arguments. It adds complexity so let's simplify down to basic two-parameter functions.
The min
and max
functions should be shortcuts for something that can be expressed via the built-ins. The built-in comparator functions make sane comparisons between like types (see the lt
implementation in text/template).
[[if lt .A .B ]][[ .A ]][[ else ]][[ .B ]] == [[min .A .B]]
[[if gt .A .B ]][[ .A ]][[ else ]][[ .B ]] == [[max .A .B]]
The existing numerical functions expect int64. We could continue that pattern, but as I pointed out in a previous comment this can be difficult to use correctly. It requires the users to know that only int64
values will be accepted. This is similar to creating type specific functions (e.g. minInt
) because users need to know the types involved to select the correct function.
Dan raised a good concern about the some of the comparisons between types in consul-template implementation. I think we should still have a single min
and max
, but only allow comparisons between like types (as is handled in the builtin lt()
func).
My proposal in 4cdc09c re-uses the lt
function to create min
and max
. WDYT?
@andrewkroh The simplification of down to using just 2 values instead of a list makes sense, but this approach again re-introduces the ability to compare values of different ranges and signs, I agree the user would need the knowledge of certain types to implement the current approach but shouldn't we expect the user to have that basic knowledge when using something like httpjson ? Also this is using reflection so the code becomes more complex, similar to the consul code(minor nit-pick). @efd6 What are your thoughts on this ? |
There is a difference. Footnotes |
@andrewkroh alright then, we can go ahead with this approach if everyone's onboard, waiting on you @efd6. |
I much prefer the simpler solution; the possibility of comparing different types is unfortunate, but it is at least consistent with the rest of the templating language in that it is merely an optimisation of an expression that can be made in-language, i.e. |
@andrewkroh I've merged your changes to this PR. @efd Could you review and approve ? |
elastic#36036) * added min/max functions * updated methods to accept integer list * updated the methods to accept atleast 1 arg * extended the min/max functions to be more generic * reworked the min/max implementation * made the min max funcs generic with a custom number ingterface * Implement min/max using text/template lt func --------- Co-authored-by: Andrew Kroh <[email protected]>
Type of change
What does this PR do?
Adds min, max methods to the template engine.
Why is it important?
This is important because it will help solve issues where min max methods are required to extract a certain value to be passed in the requests.
Checklist
- [] I have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs