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
add functionality for iteration over lists #2926
Comments
@jszigetvari : could you add example configs? |
Will that make it possible to iterate over messages of a grouping-by or patterndb context? |
@faxm0dem: based on the quick look I took, the template functions |
$(Context-values) returns a list so that can be used together. Also
$(context-lookup) does something similar to this function. Maybe at the
very least the syntax should be consistent
…On Wed, Oct 2, 2019, 15:36 Gábor Nagy ***@***.***> wrote:
@faxm0dem <https://github.com/faxm0dem>: based on the quick look I took,
the template functions $(context-values) and $(context-lookup) do create
the kind of lists we are talking about, but not grouping-by() or patterndb.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2926?email_source=notifications&email_token=AAFOK5TMGAKZ7Q6SB4M6DVTQMSPUXA5CNFSM4IW653AKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAEYL4I#issuecomment-537495025>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFOK5UQXPE6W3CDHVEC6XDQMSPUXANCNFSM4IW653AA>
.
|
Another example here would be metrics. Presently I am doing some back flips to reformat the metrics into something that can be used down stream. |
I have been thinking about this topic lately. We will need two things:
The answer for the first question is easy: The second part is tricky. The most intuitive way would be to pass a template function to the loop constructs. The difficulty from implementation point of view is that, these template functions need to be special: they need to create bindings for the original value. For example
or more ideally
U̶n̶f̶o̶r̶t̶u̶n̶a̶t̶e̶l̶y̶,̶ ̶t̶e̶m̶p̶l̶a̶t̶e̶s̶ ̶i̶n̶ ̶s̶y̶s̶l̶o̶g̶-̶n̶g̶ ̶c̶a̶n̶n̶o̶t̶ ̶e̶s̶t̶a̶b̶l̶i̶s̶h̶ ̶b̶i̶n̶d̶i̶n̶g̶s̶ ̶c̶u̶r̶r̶e̶n̶t̶l̶y̶.̶ I am experimenting with this topic in: #3205. The interesting part in |
There's a $_ value that can be passed from the "outside" when invoking
template functions. Albeit pretty limited but this can be used for this
purpose, like this:
`$(list-iter $(echo $_))`
…On Sun, Mar 29, 2020, 13:53 furiel ***@***.***> wrote:
I have been thinking about this topic lately.
We will need two things:
- What do we mean by iteration?
- How do we instruct the iteration? What should it do with the list?
The answer for the first question is easy: map, filter, reduce.
The second part is tricky. The most intuitive way would be to pass a
template function to the loop constructs. The difficulty from
implementation point of view is that, these template functions need to be
special: they need to create bindings for the original value. For example
$(map $(echo "<something-that-refers-to-the-item>") $list)
or more ideally
$(map $(lambda (x) $(echo $x) $list)
Unfortunately, templates in syslog-ng cannot establish bindings currently.
I am experimenting with this topic in: #3205
<#3205>.
This would refer to the non-lambda version. The list functions could
anaphorically bind the list elements, similarly to aiterate in the linked
PR.
The interesting part in aiterate is that it can be used to loop through
list, though an inefficient way: O(n^2) where n for the length of the
list. You can check the example in the PR.
Still, if we have aiterate, we need to just add a $(take k
<template-function>), that rebuilds the list from the iterator. Then we
would have the "map" functionality.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2926 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFOK5VWCZ3PI3FPGTSK57LRJ4ZDRANCNFSM4IW653AA>
.
|
Indeed, that is exactly what I was looking for. I am rebuilding |
I don't know whether I understand it right, but from the usage examples over in #3205, it seems that this iteration can't be used, in the following use-case: So for example, through the parsing, we would get a list like this: And we would apply a filter pattern for the string "AB" We would use a template like this:
And in the end we would get an output like this: However the current solution seems to use a static list, where the iteration happens over subsequent incoming messages. |
You seem to misunderstand this a bit. the $(context-*) family of functions
indeed operate on message contexts, eg. subsequent series of messages.
This one however will evaluate the specified function every time it is
invoked while keeping the result of the last operation in its state.
The state is simply a string the result of the last evaluation.
…On Tue, Apr 7, 2020, 17:54 Janos SZIGETVARI ***@***.***> wrote:
I don't know whether I understand it right, but from the usage examples
over in #3205 <#3205>, it
seems that this iteration can't be used, in the following use-case:
A message arrives, and through some parsing magic, a list is created,
which belongs to that specific log message.
Through this iteration construct I would have liked for instance to only
print out the list elements that match a certain pattern for example.
So for example, through the parsing, we would get a list like this:
\"ABC\",\"CDE\",\"ABD\"
And we would apply a filter pattern for the string "AB"
We would use a template like this:
template("$MSG <iteration construct where item matches "AB" prefix print
item>")
And in the end we would get an output like this:
content-of-MSG ABC ABD
However the current solution seems to use a static list, where the
iteration happens over subsequent incoming messages.
Sorry for not clearing this up eariler.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2926 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFOK5Q6T3JLNKRBC4V5VQ3RLNED7ANCNFSM4IW653AA>
.
|
@jszigetvari Yes it can be used for filter too. Almost. Creating a series of the matching prefixes is somewhat straightforward. Building a list from them is difficult with
If you know the length of the list, then of course you can consume the iterator manually. For fun and profit, I created an example config that shows the intention. It is very complex, but again, I did not want to use The method is simple: with iterate, I generate a series of indexes that will be used to walk through the parsed list using Some technical difficulties arised that I needed to deal with: I needed to create two copies for most of the functions to avoid multiple evaluation. In the if statement, there was a missing evaluation too: the true-branch only evaluated if the pattern matches, but I always needed to step the iterator. So I manually consumed in the else branch too. This kind of complexities can be addressed with a new
results in
|
After a discussion with @furiel I see now that the planned end-product of this effor will be something that will be useful in my use-case. |
Currently syslog-ng does not offer any built-in functionality that would make it possible to iterate over the elements of a list data structure.
This makes it particularly difficult to perform operations on list elements, like searching, or modification operations.
(At the moment, one has to resort to looping back messages to syslog-ng, to iterate over list elements, which is inconvenient and has a significant performance overhead.)
The text was updated successfully, but these errors were encountered: