Skip to content

Commit

Permalink
Add ARM64 heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
Molter73 committed Oct 20, 2023
1 parent eba80b8 commit 83a09f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions collector/lib/HostHeuristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,23 @@ class S390XHeuristic : public Heuristic {
}
};

class ARM64Heuristic : public Heuristic {
public:
void Process(HostInfo& host, const CollectorConfig& config, HostConfig* hconfig) const {
auto kernel = host.GetKernelVersion();

if (kernel.machine == "aarch64" && config.GetCollectionMethod() == CollectionMethod::EBPF) {
CLOG(WARNING) << "eBPF collection method is not supported on ARM, switching to CO-RE BPF collection method.";
hconfig->SetCollectionMethod(CollectionMethod::CORE_BPF);
}
}
};

const std::unique_ptr<Heuristic> g_host_heuristics[] = {
std::unique_ptr<Heuristic>(new CollectionHeuristic),
std::unique_ptr<Heuristic>(new DockerDesktopHeuristic),
std::unique_ptr<Heuristic>(new S390XHeuristic),
std::unique_ptr<Heuristic>(new ARM64Heuristic),
};

} // namespace
Expand Down
30 changes: 30 additions & 0 deletions collector/test/HostHeuristicsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class MockS390xHeuristics : public S390XHeuristic {
MockS390xHeuristics() = default;
};

class MockARM64Heuristics : public ARM64Heuristic {
public:
MockARM64Heuristics() = default;
};

class MockHostInfoHeuristics : public HostInfo {
public:
MockHostInfoHeuristics() = default;
Expand All @@ -56,6 +61,13 @@ class MockCollectorConfig : public CollectorConfig {
: CollectorConfig(collectorArgs){};

MOCK_CONST_METHOD0(UseEbpf, bool());

void SetCollectionMethod(CollectionMethod cm) {
if (host_config_.HasCollectionMethod()) {
host_config_.SetCollectionMethod(cm);
}
collection_method_ = cm;
}
};

TEST(HostHeuristicsTest, TestS390XRHEL84) {
Expand All @@ -66,6 +78,7 @@ TEST(HostHeuristicsTest, TestS390XRHEL84) {
MockCollectorConfig config(args);
HostConfig hconfig;

config.SetCollectionMethod(CollectionMethod::EBPF);
hconfig.SetCollectionMethod(CollectionMethod::EBPF);
EXPECT_CALL(host, GetKernelVersion()).WillOnce(Return(version));

Expand All @@ -74,4 +87,21 @@ TEST(HostHeuristicsTest, TestS390XRHEL84) {
EXPECT_EQ(hconfig.GetCollectionMethod(), CollectionMethod::CORE_BPF);
}

TEST(HostHeuristicsTest, TestARM64Heuristic) {
MockARM64Heuristics heuristic;
MockHostInfoHeuristics host;
KernelVersion version = KernelVersion("6.5.5-200.fc38.aarch64", "", "aarch64");
CollectorArgs* args = CollectorArgs::getInstance();
MockCollectorConfig config(args);
HostConfig hconfig;

config.SetCollectionMethod(CollectionMethod::EBPF);
hconfig.SetCollectionMethod(CollectionMethod::EBPF);
EXPECT_CALL(host, GetKernelVersion()).WillOnce(Return(version));

heuristic.Process(host, config, &hconfig);

EXPECT_EQ(hconfig.GetCollectionMethod(), CollectionMethod::CORE_BPF);
}

} // namespace collector

0 comments on commit 83a09f8

Please sign in to comment.