-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
filebeat/input/journald: allow specifying since when to read journald entries #35408
Conversation
2226034
to
151f14a
Compare
26c3686
to
a0d669b
Compare
Pinging @elastic/security-external-integrations (Team:Security-External Integrations) |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
fb104e2
to
0d44d80
Compare
This comment was marked as outdated.
This comment was marked as outdated.
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.
Do we have existing integration/e2e tests working with journald? If so we need to update them in order to test this new option. If not, we need to file an issue to add them ASAP.
func sameError(a, b error) bool { | ||
switch { | ||
case a == nil && b == nil: | ||
return true | ||
case a == nil, b == nil: | ||
return false | ||
default: | ||
return a.Error() == b.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.
Why not require.ErrorIs
?
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 avoid assertion libraries for the reasons stated in the Go wiki.
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.
@efd6 this is a very strange statement to make since our entire codebase is using the testify
library and it makes our tests more concise. Even this file is importing both assert
and require
and they're used in another test.
I've read the reasons stated in the wiki and I think it's coming from misunderstanding how testify works:
assert
does not stop the test and lets it run further but fails it at the end of the runrequire
fails the test immediately and does not run further.
so, developers are free to choose the behaviour when necessary.
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.
The final part is the most sigificant:
Assert libraries make it too easy to write imprecise tests and inevitably end up duplicating features already in the language, like expression evaluation, comparisons, sometimes even more. Strive to write tests that are precise both about what went wrong and what went right, and make use of Go itself instead of creating a mini-language inside Go.
My experience with assert libraries, particularly testify, is that they make test failure outputs needlessly complex as the cost for the concision that is gained. It's important that comprehensibility, rather than concision is the goal for test code. Test should should really be completely transparent, concise code is often not this is an excellent decades-long study in that. The other issue is that as the quoted text above says, they make it easy for authors to write imprecise tests; this often presents as a test which says nothing other than where the failure happened and what the comparands were. Assert libraries usually (testify does) provide a format/args list to decorate failures with; in my experience, these are almost never used because the author favours the proximate terness and concision over the long term clarity that a well though out test provides.
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.
That still sounds like a personal preference and not argumentation. The whole code base is using testify, the decision was made and the new tests should maintain consistency, thank you.
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.
The only last thing I'm missing is a test to ensure the feature works, especially that the pointer deference does not panic.
There is a test on https://github.com/elastic/beats/blob/main/filebeat/input/journald/input_test.go that you can use as a start point.
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.
The new changes look good, thanks!
However I'm still missing a test that actually tests the functionality of using the Since
value when reading the journal. Could you add this last one, please?
Aren't we then testing the behaviour of journald which was rejected here? |
They're two different things, at least the way I see them. #35408 (comment) was a general comment about the ideal way of testing our code. This one is about having some sort of tests that actually run the implemented code in the input (the run function). It is about having some test ensuring the added code does not break anything, ideally it would not rely on journald, but if it does, it's also ok. We can always improve add more tests later, but it is important to have some tests actually running the implemented code. |
From what I can see it is not possible to test Run without involving journald. This is because the only way we can get to the path here is after calling |
This pull request is now in conflicts. Could you fix it? 🙏
|
Add two test cases that verify "seek: since" and "cursor_seek_fallback: since" are working.
@belimawr I pushed in two test cases to verify that |
…d entries (elastic#35408) Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
What does this PR do?
This allows users to specify a relative time offset for starting to read journald entries, or as a fallback for cursor restarts.
Why is it important?
This is required for an integration enhancement.
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Checklist
How to test this PR locally
Related issues
Ignore older than
setting integrations#6060.Use cases
Screenshots
Logs