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

Jv ebpf deprecation cleanup #1509

Merged
merged 8 commits into from
Feb 7, 2024
Merged

Conversation

JoukoVirtanen
Copy link
Contributor

@JoukoVirtanen JoukoVirtanen commented Jan 19, 2024

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

  • Investigated and inspected CI test results
  • Ran integration tests locally
    - [ ] Updated documentation accordingly

Automated testing
- [ ] Added unit tests
- [ ] Added integration tests
- [ ] Added regression tests

This 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.

@JoukoVirtanen JoukoVirtanen requested a review from a team as a code owner January 19, 2024 00:25
@@ -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.
Copy link
Contributor Author

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.";
      }

Copy link
Contributor

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).

Copy link
Contributor Author

@JoukoVirtanen JoukoVirtanen Feb 7, 2024

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"};
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using mocks again.

Copy link
Contributor

@erthalion erthalion left a 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.
Copy link
Contributor

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"};
Copy link
Contributor

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"};
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@ovalenti ovalenti left a 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...).

https://github.com/stackrox/collector/pull/1509/files#diff-481ca574af93ac9fb58516ac8df6705b55eff51252c30680b711d4f453ab6f44L132-L135

@JoukoVirtanen
Copy link
Contributor Author

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...).

https://github.com/stackrox/collector/pull/1509/files#diff-481ca574af93ac9fb58516ac8df6705b55eff51252c30680b711d4f453ab6f44L132-L135

Done

@JoukoVirtanen JoukoVirtanen merged commit aea6d9d into master Feb 7, 2024
48 checks passed
@JoukoVirtanen JoukoVirtanen deleted the jv-ebpf-deprecation-cleanup branch February 7, 2024 16:35
@erthalion erthalion mentioned this pull request Feb 12, 2024
2 tasks
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.

3 participants