Skip to content
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

filter_lua: allow to return an array of messages. #811

Merged
merged 1 commit into from
Oct 30, 2018

Conversation

manuelluis
Copy link
Contributor

No description provided.

Signed-off-by: Manuel Luis Sanmartín Rozada <[email protected]>
@manuelluis
Copy link
Contributor Author

To allow to split a message in multiple messages in the lua filter, the result can be a map or an array of maps.

$ cat test.conf 
[Input]
	Name stdin

[Filter]
	Name lua
	Match *
	script  test.lua
	call    cb_print

[Output]
	Name stdout
	Match *
$ cat test.lua 
function cb_print(tag, timestamp, record)
   if record["x"] ~= nil then
      return 1, timestamp, record["x"]
   else 
      return 1, timestamp, record
   end 
end
$ cat test.json 
{"x": [ {"a1":"aa", "z1": "zz"}, {"b1":"bb", "x1": "xx"}, {"c1":"cc"}]}
{"x": [ {"a2":"aa", "z2": "zz"}, {"b2":"bb", "x2": "xx"}, {"c2":"cc"}]}
{"a3":"aa", "z3": "zz", "b3":"bb", "x3": "xx", "c3":"cc"}
$ cat test.json | ./fluent-bit -f1 -c test.conf -q
[0] stdin.0: [1538435928.310583591, {"a1"=>"aa", "z1"=>"zz"}]
[1] stdin.0: [1538435928.310583591, {"x1"=>"xx", "b1"=>"bb"}]
[2] stdin.0: [1538435928.310583591, {"c1"=>"cc"}]
[3] stdin.0: [1538435928.310588359, {"z2"=>"zz", "a2"=>"aa"}]
[4] stdin.0: [1538435928.310588359, {"b2"=>"bb", "x2"=>"xx"}]
[5] stdin.0: [1538435928.310588359, {"c2"=>"cc"}]
[6] stdin.0: [1538435928.310589790, {"z3"=>"zz", "x3"=>"xx", "c3"=>"cc", "a3"=>"aa", "b3"=>"bb"}]

@edsiper edsiper merged commit 0c81802 into fluent:master Oct 30, 2018
@edsiper
Copy link
Member

edsiper commented Oct 30, 2018

thanks

bluebike pushed a commit to bluebike/fluent-bit that referenced this pull request Nov 2, 2018
@liweitianux
Copy link

liweitianux commented Dec 17, 2020

Awesome! This is just what I want. I've looked the Fluent Bit docs but found nothing about this feature. Google search also returned nothing.

Thank you for the nice work. By the way, I'll make a patch to update the lua filter doc.

liweitianux pushed a commit to liweitianux/fluent-bit-docs that referenced this pull request Dec 18, 2020
Add description about that the Lua callback can return an array of
records, i.e., the third return value of the callback function can be an
array of tables.  This feature enables this Lua filter to split an input
record into multiple records.  Document the record split feature as a
new subsection and add an example about it.

See also fluent/fluent-bit#811 .

While there, variosu minor grammar and format fixes.

Signed-off-by: Aaron LI <[email protected]>
liweitianux added a commit to liweitianux/fluent-bit-docs that referenced this pull request Dec 13, 2021
Add description about that the Lua callback can return an array of
records, i.e., the third return value of the callback function can be an
array of tables.  This feature enables this Lua filter to split an input
record into multiple records.  Document the record split feature as a
new subsection and add an example about it.

See also fluent/fluent-bit#811 .

While there, variosu minor grammar and format fixes.

Signed-off-by: Weitian LI <[email protected]>
lecaros pushed a commit to fluent/fluent-bit-docs that referenced this pull request Dec 16, 2021
Add description about that the Lua callback can return an array of
records, i.e., the third return value of the callback function can be an
array of tables.  This feature enables this Lua filter to split an input
record into multiple records.  Document the record split feature as a
new subsection and add an example about it.

See also fluent/fluent-bit#811 .

While there, variosu minor grammar and format fixes.

Signed-off-by: Weitian LI <[email protected]>
rawahars pushed a commit to rawahars/fluent-bit that referenced this pull request Oct 24, 2022
@geisbruch
Copy link

Hi guys ! one question, Which take will take on each emitted record ? I am trying to return a table where the records should match different tags, is it possible ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants