-
Notifications
You must be signed in to change notification settings - Fork 24
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
Jv ebpf deprecation cleanup #1509
Conversation
@@ -52,33 +52,18 @@ class MockHostInfoHeuristics : public HostInfo { | |||
MOCK_METHOD0(GetDistro, std::string&()); | |||
}; | |||
|
|||
// Note that in every test below, ProcessHostHeuristics will be called first | |||
// with creation of a config mock, which is somewhat annoying, but doesn't | |||
// cause any serious issues. |
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.
This did create a serious issue when the default collection method was changed to CORE_BPF. This is because ProcessHostHeuristics calls Process, which runs the following when the collection method is CORE_BPF
if (!host.HasBPFRingBufferSupport()) {
CLOG(FATAL) << "Missing RingBuffer support, core_bpf is not available. "
<< "HINT: Change collection method to eBPF with collector.collectionMethod=EBPF.";
}
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 not possible to mock out Process
as well? I'm not sure it's the best solution to go through config setup directly, because it makes unit tests less "unit", in the sense that they now less isolated and a bit dependent on the outside world (in the form of env vars).
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 ended up solving this by moving most of the CollectorConfig constructor into an InitCollectorConfig function, including ProcessHostHeuristics, which called Process and caused the fatal error. I feel like the constructor for CollectorConfig was doing too much and splitting it into two is an improvement.
I considered alternatives such as moving ProcessHostHeuristics into either the HostHeuristics or CollectorConfig classes. Neither option seemed very good. I also considered creating a new class for ProcessHostHeuristics.
TEST(HostHeuristicsTest, TestS390XRHEL84) { | ||
MockS390xHeuristics s390xHeuristics; | ||
MockHostInfoHeuristics host; | ||
KernelVersion version = KernelVersion("4.18.0-305.88.1.el8_4.s390x", "", "s390x"); | ||
CollectorArgs* args = CollectorArgs::getInstance(); | ||
MockCollectorConfig config(args); | ||
int argc = 3; | ||
const char* argv[] = {"collector", "--collection-method", "ebpf"}; |
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 collection method has to be set here, because CollectorConfig config(args)
results in a call to ProcessHostHeuristics
and in turn Process
. If the collection method is set to the default CORE_BPF
in Process
a fatal error will be triggered.
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.
Even if it's better than using a mock, it should be refactored to be more reusable.
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 am now using the mock again.
const char* argv[] = {"collector", "--collection-method", "ebpf"}; | ||
int exitCode = 0; | ||
args->parse(argc, const_cast<char**>(argv), exitCode); | ||
CollectorConfig config_(args); |
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.
Same as for the HostHeuristicsTests.
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.
Using mocks again.
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.
Thanks for the PR, few comments below. Also, I've noticed there are couple of
outdated mentions of ebpf in our docs, in "how to start" and "references"
sections -- could you address them as well?
@@ -52,33 +52,18 @@ class MockHostInfoHeuristics : public HostInfo { | |||
MOCK_METHOD0(GetDistro, std::string&()); | |||
}; | |||
|
|||
// Note that in every test below, ProcessHostHeuristics will be called first | |||
// with creation of a config mock, which is somewhat annoying, but doesn't | |||
// cause any serious issues. |
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 not possible to mock out Process
as well? I'm not sure it's the best solution to go through config setup directly, because it makes unit tests less "unit", in the sense that they now less isolated and a bit dependent on the outside world (in the form of env vars).
TEST(HostHeuristicsTest, TestS390XRHEL84) { | ||
MockS390xHeuristics s390xHeuristics; | ||
MockHostInfoHeuristics host; | ||
KernelVersion version = KernelVersion("4.18.0-305.88.1.el8_4.s390x", "", "s390x"); | ||
CollectorArgs* args = CollectorArgs::getInstance(); | ||
MockCollectorConfig config(args); | ||
int argc = 3; | ||
const char* argv[] = {"collector", "--collection-method", "ebpf"}; |
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.
Even if it's better than using a mock, it should be refactored to be more reusable.
@@ -92,10 +77,13 @@ TEST(HostHeuristicsTest, TestARM64Heuristic) { | |||
MockHostInfoHeuristics host; | |||
KernelVersion version = KernelVersion("6.5.5-200.fc38.aarch64", "", "aarch64"); | |||
CollectorArgs* args = CollectorArgs::getInstance(); | |||
MockCollectorConfig config(args); | |||
int argc = 3; | |||
const char* argv[] = {"collector", "--collection-method", "ebpf"}; |
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 is it configured to use ebpf
everywhere?
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.
These tests originally specified ebpf as the collection method. I have not changed that. When we remove ebpf these tests will be changed or removed.
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.
Even if it's better than using a mock, it should be refactored to be more reusable.
I am using mocks now, so this comment is 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.
We probably want to default to core_bpf in the case where the collectionMethod provided by the user is not valid (or no more valid...).
…ng MockCollectorConfig again in tests
Done |
Description
Sets the default collection method to CORE_BPF for collector and the integration tests. Fixed unit tests that broke as a result of changing the default collection method to CORE_BPF. Also removed the hardfail config option for CORE_BPF. The code now behaves as though it is always true.
Checklist
- [ ] Updated documentation accordinglyAutomated testing
- [ ] Added unit tests- [ ] Added integration tests- [ ] Added regression testsThis changes the default collection method so testing it is not needed.
If any of these don't apply, please comment below.
Testing Performed
TODO(replace-me)
Use this space to explain how you tested your PR, or, if you didn't test it, why you did not do so. (Valid reasons include "CI is sufficient" or "No testable changes")
In addition to reviewing your code, reviewers must also review your testing instructions, and make sure they are sufficient.
For more details, ref the Confluence page about this section.