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

copying argprinters funcs under libbpfgo #493

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

mtcherni95
Copy link
Contributor

@mtcherni95 mtcherni95 commented Feb 1, 2021

Please note, after consulting with @itaysk , we decided that is better to close this issue with a two-phase commit.
In the first commit (this one) we will simply copy functions in libbpfgo so that tests will pass. In the second commit we will use libbpfgo funcs (under linuxhelpers package) and remove not relevant functions under tracee package (argprinters.go).

Copy link
Collaborator

@itaysk itaysk left a comment

Choose a reason for hiding this comment

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

Thanks @mtcherni95 . you should move the tests as well

@grantseltzer
Copy link
Contributor

grantseltzer commented Feb 3, 2021

Since this is exported API we should use this opportunity to think about our naming conventions. All these functions start with 'Print' but none of them do any printing, they return strings. I would rather rename them to things like:

PrintOpenFlags -> OpenFlagsToString or SprintOpenFlags

Also the package name linuxhelpers I feel can be changed to just helpers, or maybe bpfhelpers. We can also just put them in the main libbpfgo package alongside TracePrint().

What do you think @mtcherni95 @itaysk ?

@itaysk
Copy link
Collaborator

itaysk commented Feb 3, 2021

good point. wdyt of ParseXXX?

I don't think all of the helpers should live in the same package as libbpfgo, I'm fine with renaming the package. @yanivagman wdyt?

@grantseltzer
Copy link
Contributor

ParseXXX sounds good to me. And different package but with different name is also good by me.

@yanivagman
Copy link
Collaborator

yanivagman commented Feb 4, 2021

Funny @grantseltzer that the names that you suggest where the ones used in the original tracee python version (e.g. open_flags_to_str) :-)
I agree that the Print prefix is misleading.
Sprint prefix is a good option (Parse feels too much, isn't it?)
Agree about the package - we should separate libbpf wrappers from other helpers functionality (including the new TracePrint() function). I don't think bpfhelpers is a good name, as not all of this stuff is related to bpf. helpers or linuxhelpers are fine with me

@itaysk
Copy link
Collaborator

itaysk commented Feb 4, 2021

I don't see the problem with Parse (Parse: analyze (a string or text) into logical syntactic components), and sprintf sounds too technical. but whatever you decide as long as it's in a separate package

@yanivagman yanivagman mentioned this pull request Feb 9, 2021
4 tasks
@grantseltzer
Copy link
Contributor

@mtcherni95 Could you rename all the functions to ParseXXX, and bring in TracePrint from libbpfgo?

@itaysk
Copy link
Collaborator

itaysk commented Feb 17, 2021

hi @mtcherni95 are you still working on this?

@itaysk itaysk added this to To do in libbpfgo Mar 3, 2021
@itaysk itaysk removed this from To do in libbpfgo Mar 3, 2021
@grantseltzer
Copy link
Contributor

Hi @mtcherni95 do you still want to work on this? If not is it cool with you if I pick it up to close this out?

@grantseltzer
Copy link
Contributor

@itaysk @yanivagman

After talking with @mtcherni95 I went ahead and pushed the requested changes to this, I will follow up with the second PR described in Michael's original comment right after this merges.

@grantseltzer grantseltzer self-assigned this Mar 16, 2021
@grantseltzer
Copy link
Contributor

@simar7 Can you please take a look at this?

"os"
)

func ExampleTracePipeListen_usage() {
Copy link
Member

Choose a reason for hiding this comment

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

This file is named as argParsers_test.go but none of the functions are actually test functions themselves. If it's more of an example/toy program to demonstrate usage of TracePipe(), I would suggest renaming the file.

Otherwise we should make TracePipeListen() injectable with a param, something like: TracePipeListen(path string), path being something we can inject during a test. We can further use "/sys/kernel/debug/tracing/trace_pipe" as the default if no args are specified (the real world usage) to alleviate the need for passing in the path for the library user.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea on making that function testable, I'd like to go through a lot of these helpers and write tests, will do I that in a follow up PR (I swear, I will!)

I've gone ahead and renamed this file to example_tracelisten_test.go. The _test suffix is necessary for the example to show up in godoc, but it seems an example_ prefix is idiomatic in the standard library (for example: code and docs).

Copy link
Collaborator

Choose a reason for hiding this comment

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

the tests in tracee-ebpf/tracee/tracee_test.go are mostly testing these argprinters. I think we can move them here (argparsers_test.go)

also, TracePipeListen doesn't feel like it belongs in the argParsers file, can we move it into another helpers file? if we do that, I think it's ok to rename example_tracelisten_test.go to helpers_test.go (it's common in go to put examples with test right?). wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

@itaysk I don't follow, the only test I see in tracee_test.go is for readArgFromBuff().

I am all for separating out TracePipeListen to its own file and renaming the test file though. I'm about to open a PR with helpers for CO:RE stuff, I'll do that change as part of that PR.

Copy link
Member

@simar7 simar7 left a comment

Choose a reason for hiding this comment

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

Just left a clarification comment but otherwise 🚢 it!

@grantseltzer grantseltzer force-pushed the tracee-issue-485 branch 2 times, most recently from 045960e to 8bf51a2 Compare March 18, 2021 03:15
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
@grantseltzer grantseltzer merged commit f66f7be into aquasecurity:main Mar 18, 2021
@mtcherni95 mtcherni95 deleted the tracee-issue-485 branch May 25, 2021 08:46
@mtcherni95 mtcherni95 restored the tracee-issue-485 branch May 25, 2021 08:46
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.

None yet

5 participants