Skip to content

Conversation

@Officeyutong
Copy link
Contributor

In the new agent_config design introduced in #371 , construct an agent_config without any argument will make it store strings on a local heap. If a user plan to store strings on shared memory, agent_config should be initialized with boost::interprocess::managed_shared_memory &. The nginx attach example didn't adapt this, this PR fixes it

@codecov
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.70%. Comparing base (fcb6d40) to head (4d340eb).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #384   +/-   ##
=======================================
  Coverage   53.70%   53.70%           
=======================================
  Files         101      101           
  Lines        9736     9736           
  Branches      999      998    -1     
=======================================
  Hits         5229     5229           
  Misses       4507     4507           
Flag Coverage Δ
attach tests (uprobe & syscall trace) 97.96% <ø> (ø)
coverage-example-fedora-false-bashreadline-false 13.73% <ø> (ø)
coverage-example-fedora-false-bashreadline-true 13.73% <ø> (ø)
coverage-example-fedora-false-funclatency-false 11.47% <ø> (ø)
coverage-example-fedora-false-funclatency-true 11.47% <ø> (ø)
coverage-example-fedora-false-malloc-true 12.69% <ø> (ø)
coverage-example-fedora-false-minimal-false 10.43% <ø> (ø)
coverage-example-fedora-false-minimal-true 10.43% <ø> (ø)
coverage-example-fedora-false-mountsnoop-true 14.42% <ø> (ø)
coverage-example-fedora-false-opensnoop-libbpf-tools-true 15.42% <ø> (ø)
coverage-example-fedora-false-opensnoop-true 14.42% <ø> (ø)
coverage-example-fedora-false-sigsnoop-true 23.31% <ø> (ø)
coverage-example-fedora-false-sslsniff-false 15.18% <ø> (ø)
coverage-example-fedora-false-sslsniff-true 15.18% <ø> (ø)
coverage-example-fedora-false-statsnoop-true 15.42% <ø> (ø)
coverage-example-fedora-false-syscount-false 10.15% <ø> (ø)
coverage-example-fedora-false-syscount-true 11.75% <ø> (ø)
coverage-example-fedora-false-tailcall_minimal-true 10.49% <ø> (ø)
coverage-example-fedora-false-usdt_minimal-false 11.43% <ø> (ø)
coverage-example-fedora-false-usdt_minimal-true 11.43% <ø> (ø)
coverage-example-fedora-true-bashreadline-false 13.35% <ø> (ø)
coverage-example-fedora-true-bashreadline-true 13.35% <ø> (ø)
coverage-example-fedora-true-funclatency-false 11.15% <ø> (ø)
coverage-example-fedora-true-funclatency-true 11.15% <ø> (ø)
coverage-example-fedora-true-malloc-true 12.33% <ø> (ø)
coverage-example-fedora-true-minimal-false 10.13% <ø> (ø)
coverage-example-fedora-true-minimal-true 10.13% <ø> (ø)
coverage-example-fedora-true-mountsnoop-true 14.02% <ø> (ø)
coverage-example-fedora-true-opensnoop-libbpf-tools-true 14.98% <ø> (ø)
coverage-example-fedora-true-opensnoop-true 14.02% <ø> (ø)
coverage-example-fedora-true-sigsnoop-true 9.11% <ø> (ø)
coverage-example-fedora-true-sslsniff-false 14.75% <ø> (ø)
coverage-example-fedora-true-sslsniff-true 14.75% <ø> (ø)
coverage-example-fedora-true-statsnoop-true 14.98% <ø> (ø)
coverage-example-fedora-true-syscount-false 8.53% <ø> (ø)
coverage-example-fedora-true-syscount-true 11.42% <ø> (ø)
coverage-example-fedora-true-tailcall_minimal-true 10.20% <ø> (ø)
coverage-example-fedora-true-usdt_minimal-false 11.11% <ø> (ø)
coverage-example-fedora-true-usdt_minimal-true 11.11% <ø> (ø)
coverage-example-ubuntu-false-bashreadline-false 29.39% <ø> (ø)
coverage-example-ubuntu-false-bashreadline-true 29.39% <ø> (ø)
coverage-example-ubuntu-false-funclatency-false 24.60% <ø> (ø)
coverage-example-ubuntu-false-funclatency-true 24.60% <ø> (ø)
coverage-example-ubuntu-false-malloc-true 27.21% <ø> (ø)
coverage-example-ubuntu-false-minimal-false 22.36% <ø> (ø)
coverage-example-ubuntu-false-minimal-true 22.36% <ø> (ø)
coverage-example-ubuntu-false-mountsnoop-true 30.92% <ø> (ø)
coverage-example-ubuntu-false-opensnoop-libbpf-tools-true 32.99% <ø> (ø)
coverage-example-ubuntu-false-opensnoop-true 30.92% <ø> (ø)
coverage-example-ubuntu-false-sigsnoop-true 33.69% <ø> (-4.95%) ⬇️
coverage-example-ubuntu-false-sslsniff-false 32.48% <ø> (ø)
coverage-example-ubuntu-false-sslsniff-true 32.48% <ø> (ø)
coverage-example-ubuntu-false-statsnoop-true 32.99% <ø> (ø)
coverage-example-ubuntu-false-syscount-false 17.82% <ø> (ø)
coverage-example-ubuntu-false-syscount-true 25.19% <ø> (ø)
coverage-example-ubuntu-false-tailcall_minimal-true 22.50% <ø> (ø)
coverage-example-ubuntu-false-usdt_minimal-false 24.17% <ø> (ø)
coverage-example-ubuntu-false-usdt_minimal-true 24.17% <ø> (ø)
coverage-example-ubuntu-true-bashreadline-false 29.39% <ø> (ø)
coverage-example-ubuntu-true-bashreadline-true 29.39% <ø> (ø)
coverage-example-ubuntu-true-funclatency-false 24.60% <ø> (ø)
coverage-example-ubuntu-true-funclatency-true 24.60% <ø> (ø)
coverage-example-ubuntu-true-malloc-true 27.21% <ø> (ø)
coverage-example-ubuntu-true-minimal-false 22.36% <ø> (ø)
coverage-example-ubuntu-true-minimal-true 22.36% <ø> (ø)
coverage-example-ubuntu-true-mountsnoop-true 30.92% <ø> (ø)
coverage-example-ubuntu-true-opensnoop-libbpf-tools-true 32.99% <ø> (ø)
coverage-example-ubuntu-true-opensnoop-true 30.92% <ø> (ø)
coverage-example-ubuntu-true-sigsnoop-true 20.01% <ø> (ø)
coverage-example-ubuntu-true-sslsniff-false 32.48% <ø> (ø)
coverage-example-ubuntu-true-sslsniff-true 32.48% <ø> (ø)
coverage-example-ubuntu-true-statsnoop-true 32.99% <ø> (ø)
coverage-example-ubuntu-true-syscount-false 18.48% <ø> (ø)
coverage-example-ubuntu-true-syscount-true 25.19% <ø> (ø)
coverage-example-ubuntu-true-tailcall_minimal-true 22.50% <ø> (ø)
coverage-example-ubuntu-true-usdt_minimal-false 24.17% <ø> (ø)
coverage-example-ubuntu-true-usdt_minimal-true 24.17% <ø> (ø)
runtime tests 48.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@yunwei37 yunwei37 left a comment

Choose a reason for hiding this comment

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

I prefer to fix the SIGSEGV issue rather than downgrading the implementation, I'll fix it

I think sometimes keep it simple and stupid would be better? If the agent needs shm to init and become complex, and requires user to Initialize it with special approachs to avoid error, it will

  1. make software maintainance harder
  2. make library user confuse

I still think maybe using raw char buffer would be better, easiler to understand and maintain.

@Officeyutong
Copy link
Contributor Author

Officeyutong commented Apr 26, 2025

I prefer to fix the SIGSEGV issue rather than downgrading the implementation, I'll fix it

I think sometimes keep it simple and stupid would be better? If the agent needs shm to init and become complex, and requires user to Initialize it with special approachs to avoid error, it will

  1. make software maintainance harder

  2. make library user confuse

I still think maybe using raw char buffer would be better, easiler to understand and maintain.

What if the buffer overflows?

  • Also, I can change agent_config to make it default to store stuff on shared memory (i.e when constructed with no arguments, things will be stored on shared memory)
  • Also, storing boost strings are very common in bpftime, since we can't assume how long a string a user will provide, while storing a char[] are very rare

@yunwei37
Copy link
Member

What if the buffer overflows?

We can add wrapper functions to help people setup it.

Also, storing boost strings are very common in bpftime, since we can't assume how long a string a user will provide, while storing a char[] are very rare

Do you think a library user may need to setup the agent_config mannually? If yes, put things in shm may increase their difficulty.

@yunwei37
Copy link
Member

(I will rebase this to the latest one, please do not close it)

@Officeyutong
Copy link
Contributor Author

Officeyutong commented Apr 28, 2025

What if the buffer overflows?

We can add wrapper functions to help people setup it.

Also, storing boost strings are very common in bpftime, since we can't assume how long a string a user will provide, while storing a char[] are very rare

Do you think a library user may need to setup the agent_config mannually? If yes, put things in shm may increase their difficulty.

We can change agent_config default to store things on shared memory, with no arguments on constructor, or just keep your changes which uses char[], what do you think?

@yunwei37
Copy link
Member

We can change agent_config default to store things on shared memory, with no arguments on constructor.

If the setup config has clear API interface and user don't need to directly deal with the shm API, use shm string approach would be better. Don't make it has two options, you can do always store things on shared memory.

Do you think we can make the init API more clear and easy to use? it seems like user need to do many things carefully in their library, and we don't have documents to explain them, like:

https://github.com/eunomia-bpf/bpftime/blob/1c89400981b1fd41497e562b31f2f9e05bea2cc0/example/attach_implementation/nginx_plugin_adaptor/nginx_plugin_adaptor.cpp#L1C1-L148C2

Can we simpilfy some API and provide some comments?

@Officeyutong
Copy link
Contributor Author

Officeyutong commented Apr 30, 2025 via email

@Officeyutong
Copy link
Contributor Author

Officeyutong commented Apr 30, 2025 via email

@Officeyutong
Copy link
Contributor Author

We can change agent_config default to store things on shared memory, with no arguments on constructor.

If the setup config has clear API interface and user don't need to directly deal with the shm API, use shm string approach would be better. Don't make it has two options, you can do always store things on shared memory.

Do you think we can make the init API more clear and easy to use? it seems like user need to do many things carefully in their library, and we don't have documents to explain them, like:

https://github.com/eunomia-bpf/bpftime/blob/1c89400981b1fd41497e562b31f2f9e05bea2cc0/example/attach_implementation/nginx_plugin_adaptor/nginx_plugin_adaptor.cpp#L1C1-L148C2

Can we simpilfy some API and provide some comments?

I can create some wrapper API to make creating attach implementation more easier, but to archive maximum custimization, the original API should be kept

@Officeyutong
Copy link
Contributor Author

We can change agent_config default to store things on shared memory, with no arguments on constructor.

If the setup config has clear API interface and user don't need to directly deal with the shm API, use shm string approach would be better. Don't make it has two options, you can do always store things on shared memory.

Do you think we can make the init API more clear and easy to use? it seems like user need to do many things carefully in their library, and we don't have documents to explain them, like:

https://github.com/eunomia-bpf/bpftime/blob/1c89400981b1fd41497e562b31f2f9e05bea2cc0/example/attach_implementation/nginx_plugin_adaptor/nginx_plugin_adaptor.cpp#L1C1-L148C2

Can we simpilfy some API and provide some comments?

After a thorough check, I got the following conclusion:

  • agent_config should be kept to be able to store strings both on shared memory and local heap, since many scenes we use it doesn't have a shared memory initialized (such as, the head of bpftime_shm::bpftime_shm(const char *shm_name, shm_open_type type))
  • I will update agent_config to make it default to store things on shared memory. Storing things on local heap is only for internal use. Users won't actually use it
  • I'll update attach related parts and add some wrapper and helper functions so the user will be more easier to register an attach implementation

What do you think? @yunwei37

@yunwei37
Copy link
Member

agent_config should be kept to be able to store strings both on shared memory and local heap

If that's true, I think it would be better if we can just use char[] buffer with functions to avoid overflow.

@Officeyutong
Copy link
Contributor Author

agent_config should be kept to be able to store strings both on shared memory and local heap

If that's true, I think it would be better if we can just use char[] buffer with functions to avoid overflow.

C-arrays are not able to expand, so if a user want to store more things (such as a very long log output path), the user will fail, can this be accepted?

@Officeyutong
Copy link
Contributor Author

agent_config should be kept to be able to store strings both on shared memory and local heap

If that's true, I think it would be better if we can just use char[] buffer with functions to avoid overflow.

Also, do you have any suggestions about I'll update attach related parts and add some wrapper and helper functions so the user will be more easier to register an attach implementation?

@yunwei37
Copy link
Member

C-arrays are not able to expand, so if a user want to store more things (such as a very long log output path), the user will fail, can this be accepted?

Typically Linux has a maximum path length of 4096 characters. So we don't need to worry about that.

@yunwei37
Copy link
Member

Also, do you have any suggestions about I'll update attach related parts and add some wrapper and helper functions so the user will be more easier to register an attach implementation?

I think that's a good idea!

@Officeyutong Officeyutong changed the title adapt nginx attach example with new agent_config [NOT PLANNED]adapt nginx attach example with new agent_config May 5, 2025
@yunwei37 yunwei37 force-pushed the master branch 2 times, most recently from cbcb1e9 to 20acd88 Compare October 1, 2025 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants