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

lua: add dump lua stack function and extract flb_lua_arraylength #7826

Merged
merged 4 commits into from
Aug 29, 2023

Conversation

nokute78
Copy link
Collaborator

@nokute78 nokute78 commented Aug 13, 2023

I need a debug function to add new feature for flb_lua to fix issue 7708.

This patch is to

  • add flb_lua_dump_stack
  • modify flb_lua_arraylength to be able to pass index of stack
  • add flb_lua_absindex

flb_lua_dump_stack is to dump lua stack for debug.

It needs to modify flb_lua_arraylength since the function expects an array should be on the top of the stack.
flb_lua_dump_stack needs to dump an array in the middle of the stack.

This patch also supports flb_lua_absindex.
In some cases, we use negative index to point from a top of the stack. e.g. lua_next(l, -2) of flb_lua_arraylength.
It can cause an error when the top of stack is added/deleted.
flb_lua_absindex is to prevent it since it returns a positive index from the bottom of the stack.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • [N/A] Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • [N/A] Backport to latest stable release.

Debug/Valgrind output

$ valgrind --leak-check=full bin/flb-it-lua 
==93371== Memcheck, a memory error detector
==93371== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==93371== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==93371== Command: bin/flb-it-lua
==93371== 
Test lua_is_valid_func...                       [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_pushtimetable...                       [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_pushmsgpack...                         [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_pushmpack...                           [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_tomsgpack...                           [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_tompack...                             [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_arraylength...                         [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_arraylength_with_index...              [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
Test lua_arraylength_for_array_contains_nil...  [ OK ]
==93371== Warning: invalid file descriptor -1 in syscall close()
SUCCESS: All unit tests have passed.
==93371== 
==93371== HEAP SUMMARY:
==93371==     in use at exit: 0 bytes in 0 blocks
==93371==   total heap usage: 7,563 allocs, 7,563 frees, 821,606 bytes allocated
==93371== 
==93371== All heap blocks were freed -- no leaks are possible
==93371== 
==93371== For lists of detected and suppressed errors, rerun with: -s
==93371== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
$ valgrind --leak-check=full bin/flb-rt-filter_lua 
==93377== Memcheck, a memory error detector
==93377== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==93377== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==93377== Command: bin/flb-rt-filter_lua
==93377== 
Test hello_world...                             [2023/08/13 10:24:59] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:24:59] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:24:59] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:24:59] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:24:59] [ info] [input:dummy:dummy.0] initializing
[2023/08/13 10:24:59] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2023/08/13 10:24:59] [ info] [output:stdout:stdout.0] worker #0 started
[2023/08/13 10:24:59] [ info] [sp] stream processor started
[2023/08/13 10:24:59] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:24:59] [ info] [input] pausing dummy.0
[2023/08/13 10:24:59] [ info] [engine] service has stopped (0 pending tasks)
[2023/08/13 10:24:59] [ info] [input] pausing dummy.0
[2023/08/13 10:24:59] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2023/08/13 10:24:59] [ info] [output:stdout:stdout.0] thread worker #0 stopped
[ OK ]
Test append_tag...                              [2023/08/13 10:25:00] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:25:00] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:25:00] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:25:00] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:25:00] [ info] [input:lib:lib.0] initializing
[2023/08/13 10:25:00] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/08/13 10:25:00] [ info] [sp] stream processor started
[2023/08/13 10:25:00] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:25:01] [ info] [engine] service has stopped (0 pending tasks)
[ OK ]
Test type_int_key...                            [2023/08/13 10:25:01] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:25:01] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:25:01] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:25:01] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:25:01] [ info] [input:lib:lib.0] initializing
[2023/08/13 10:25:01] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/08/13 10:25:01] [ info] [sp] stream processor started
[2023/08/13 10:25:02] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:25:03] [ info] [engine] service has stopped (0 pending tasks)
[ OK ]
Test type_int_key_multi...                      [2023/08/13 10:25:03] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:25:03] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:25:03] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:25:03] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:25:03] [ info] [input:lib:lib.0] initializing
[2023/08/13 10:25:03] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/08/13 10:25:03] [ info] [sp] stream processor started
[2023/08/13 10:25:04] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:25:05] [ info] [engine] service has stopped (0 pending tasks)
[ OK ]
Test type_array_key...                          [2023/08/13 10:25:05] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:25:05] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:25:05] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:25:05] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:25:05] [ info] [input:lib:lib.0] initializing
[2023/08/13 10:25:05] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/08/13 10:25:05] [ info] [sp] stream processor started
[2023/08/13 10:25:06] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:25:07] [ info] [engine] service has stopped (0 pending tasks)
[ OK ]
Test array_contains_null...                     [2023/08/13 10:25:07] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:25:07] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:25:07] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:25:07] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:25:07] [ info] [input:lib:lib.0] initializing
[2023/08/13 10:25:07] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/08/13 10:25:07] [ info] [sp] stream processor started
[2023/08/13 10:25:08] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:25:09] [ info] [engine] service has stopped (0 pending tasks)
[ OK ]
Test drop_all_records...                        [2023/08/13 10:25:09] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:25:09] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:25:09] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:25:09] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:25:09] [ info] [input:lib:lib.0] initializing
[2023/08/13 10:25:09] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/08/13 10:25:09] [ info] [sp] stream processor started
[2023/08/13 10:25:11] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:25:11] [ info] [engine] service has stopped (0 pending tasks)
[ OK ]
Test split_record...                            [2023/08/13 10:25:11] [ info] [fluent bit] version=2.1.9, commit=7c46a40e17, pid=93377
[2023/08/13 10:25:11] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/08/13 10:25:11] [ info] [cmetrics] version=0.6.3
[2023/08/13 10:25:11] [ info] [ctraces ] version=0.3.1
[2023/08/13 10:25:11] [ info] [input:lib:lib.0] initializing
[2023/08/13 10:25:11] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/08/13 10:25:11] [ info] [sp] stream processor started
[2023/08/13 10:25:13] [ warn] [timeout] elapsed_time: 2005
[2023/08/13 10:25:13] [ warn] [engine] service will shutdown in max 1 seconds
[2023/08/13 10:25:14] [ info] [engine] service has stopped (0 pending tasks)
[ OK ]
SUCCESS: All unit tests have passed.
==93377== 
==93377== HEAP SUMMARY:
==93377==     in use at exit: 0 bytes in 0 blocks
==93377==   total heap usage: 12,532 allocs, 12,532 frees, 5,934,382 bytes allocated
==93377== 
==93377== All heap blocks were freed -- no leaks are possible
==93377== 
==93377== For lists of detected and suppressed errors, rerun with: -s
==93377== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

@nokute78 nokute78 temporarily deployed to pr August 13, 2023 01:28 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr August 13, 2023 01:28 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr August 13, 2023 01:28 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr August 13, 2023 01:53 — with GitHub Actions Inactive
@edsiper
Copy link
Member

edsiper commented Aug 19, 2023

@tarruda can you take a look at this pls ?

Copy link

@tarruda tarruda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@edsiper edsiper merged commit 26e441a into fluent:master Aug 29, 2023
@edsiper
Copy link
Member

edsiper commented Aug 29, 2023

thank you!

@edsiper edsiper added this to the Fluent Bit v2.1.9 milestone Aug 29, 2023
@nokute78 nokute78 deleted the lua_debug branch August 30, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants