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
Refactor flags in tracee-rules #500
Refactor flags in tracee-rules #500
Conversation
Thoughts on default options being reading Also for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some small comments, but the big one is to properly handle EOT flag. I've commented on the issue, let's first make sure you understand the requirement first (this is crucial to how tracee-ebpf->rules work)
@itaysk I addressed your feedback, can you also verify my usage of |
I believe that based on the discussion in #508 this is ready for further review and the final question I have is what the default behavior should be for tracee-rules. I think it should be reading gob format from standard input. |
@grantseltzer the code in this PR doesn't implement the revised logic suggested in #508 , did you mean to say that it is? regarding the defaults, if you want to include #508 in this PR, then:
|
@itaysk I figured I would make that a separate PR but certainly can into this one. |
I'm actually going to open it as a second PR, the two things are related but it's a different part of the repo. |
no that's fine, I just understood it this way because you mentioned the discussion. so now, for gob you read until EOT but for JSON you don't. I'm not sure this is what we wanted, but we can let it slide because that's changing soon anyway |
if opts.inputFormat == jsonInputFormat { | ||
return setupTraceeJSONInputSource(opts) | ||
} | ||
f, err := os.Open(traceeFilePath) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid file: %s", traceeFilePath) | ||
|
||
if opts.inputFormat == gobInputFormat { | ||
return setupTraceeGobInputSource(opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Consider replacing with a switch statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's all the same to you, I think this looks cleaner than this:
switch opts.inputFormat {
case jsonInputFormat:
return setupTraceeJSONInputSource(opts)
case gobInputFormat:
return setupTraceeGobInputSource(opts)
default:
return nil, errors.New("could not set up input source")
}
// TODO: investigate impact of this and research alternatives | ||
time.Sleep(time.Millisecond * 150) | ||
continue | ||
break | ||
} else { | ||
log.Printf("Error while decoding event: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for the input file to be closed when we get here? If that happens we will be stuck in a loop forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I realize it's not a change of logic here but it's just me looking at this with a fresh set of eyes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, that is a good point but i'm not sure how it would?
return nil, errors.New("could not set up input source") | ||
} | ||
|
||
func setupTraceeGobInputSource(opts *traceeInputOptions) (chan types.Event, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function tested somewhere else? Maybe we could write a simple test like:
func Test_setupTraceeGobInputSource(t *testing.T) {
f, err := ioutil.TempFile("", "Test_setupTraceeGobInputSource-*")
require.NoError(t, err)
defer func() {
_ = f.Close()
_ = os.RemoveAll(f.Name())
}()
// write to file
e := gob.NewEncoder(f)
event := tracee.Event{
EventName: "foo",
}
require.NoError(t, e.Encode(event))
f.Seek(0, io.SeekStart)
opts := traceeInputOptions{
inputFile: f,
inputFormat: gobInputFormat,
}
res, err := setupTraceeGobInputSource(&opts)
require.NoError(t, err)
assert.Equal(t, "foo", (<-res).(tracee.Event).EventName)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the interest of unblocking Itay I'm going to include this in a follow up PR, but yes you do make a good point, testing these like how you suggested would be a big win.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: #517
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also update the readme accordingly and squash before you merge
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
…ob from stdin) Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
Signed-off-by: Simarpreet Singh <simar@linux.com>
Co-authored-by: Simarpreet Singh <simar@linux.com>
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
This addresses some of the points in #499. In particular:
--trace-file
, and--stdin-as
flags.--input-trace
that allows the user to specify the input file and input format for events to tracee-rules.Still need to address:
Need to add unit tests for the above parsing logicUpdate tracee-rules UX to align with tracee-ebpf #499 (comment)Signed-off-by: grantseltzer grantseltzer@gmail.com