Skip to content

Commit 779cdf4

Browse files
committed
Add GetLinuxHeadersStatus UDTF and update GetAgentStatus UDTF to include kernel_headers_installed
Signed-off-by: Dom Del Nano <[email protected]>
1 parent f817a59 commit 779cdf4

File tree

11 files changed

+103
-15
lines changed

11 files changed

+103
-15
lines changed

src/vizier/funcs/md_udtfs/md_udtfs.cc

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void RegisterFuncsOrDie(const VizierFuncFactoryContext& ctx, carnot::udf::Regist
3737
registry->RegisterFactoryOrDie<GetProfilerSamplingPeriodMS,
3838
UDTFWithMDFactory<GetProfilerSamplingPeriodMS>>(
3939
"GetProfilerSamplingPeriodMS", ctx);
40+
registry->RegisterFactoryOrDie<GetLinuxHeadersStatus, UDTFWithMDFactory<GetLinuxHeadersStatus>>(
41+
"GetLinuxHeadersStatus", ctx);
4042

4143
registry->RegisterOrDie<GetDebugMDState>("_DebugMDState");
4244
registry->RegisterFactoryOrDie<GetDebugMDWithPrefix, UDTFWithMDFactory<GetDebugMDWithPrefix>>(

src/vizier/funcs/md_udtfs/md_udtfs_impl.h

+63-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ namespace px {
4343
namespace vizier {
4444
namespace funcs {
4545
namespace md {
46+
47+
constexpr std::string_view kKernelHeadersInstalledDesc =
48+
"Whether the agent had linux headers pre-installed";
49+
4650
template <typename TUDTF>
4751
class UDTFWithMDFactory : public carnot::udf::UDTFFactory {
4852
public:
@@ -295,7 +299,9 @@ class GetAgentStatus final : public carnot::udf::UDTF<GetAgentStatus> {
295299
ColInfo("create_time", types::DataType::TIME64NS, types::PatternType::GENERAL,
296300
"The creation time of the agent"),
297301
ColInfo("last_heartbeat_ns", types::DataType::INT64, types::PatternType::GENERAL,
298-
"Time (in nanoseconds) since the last heartbeat"));
302+
"Time (in nanoseconds) since the last heartbeat"),
303+
ColInfo("kernel_headers_installed", types::DataType::BOOLEAN, types::PatternType::GENERAL,
304+
kKernelHeadersInstalledDesc));
299305
}
300306

301307
Status Init(FunctionContext*) {
@@ -330,6 +336,8 @@ class GetAgentStatus final : public carnot::udf::UDTF<GetAgentStatus> {
330336
rw->Append<IndexOf("agent_state")>(StringValue(magic_enum::enum_name(agent_status.state())));
331337
rw->Append<IndexOf("create_time")>(agent_info.create_time_ns());
332338
rw->Append<IndexOf("last_heartbeat_ns")>(agent_status.ns_since_last_heartbeat());
339+
rw->Append<IndexOf("kernel_headers_installed")>(
340+
agent_info.info().host_info().kernel_headers_installed());
333341

334342
++idx_;
335343
return idx_ < resp_->info_size();
@@ -396,6 +404,60 @@ class GetProfilerSamplingPeriodMS final : public carnot::udf::UDTF<GetProfilerSa
396404
std::function<void(grpc::ClientContext*)> add_context_authentication_func_;
397405
};
398406

407+
/**
408+
* This UDTF retrieves the status of the agents' Linux headers installation.
409+
*/
410+
class GetLinuxHeadersStatus final : public carnot::udf::UDTF<GetLinuxHeadersStatus> {
411+
public:
412+
using MDSStub = vizier::services::metadata::MetadataService::Stub;
413+
using SchemaResponse = vizier::services::metadata::SchemaResponse;
414+
GetLinuxHeadersStatus() = delete;
415+
GetLinuxHeadersStatus(std::shared_ptr<MDSStub> stub,
416+
std::function<void(grpc::ClientContext*)> add_context_authentication)
417+
: idx_(0), stub_(stub), add_context_authentication_func_(add_context_authentication) {}
418+
419+
static constexpr auto Executor() { return carnot::udfspb::UDTFSourceExecutor::UDTF_ONE_KELVIN; }
420+
421+
static constexpr auto OutputRelation() {
422+
return MakeArray(
423+
ColInfo("asid", types::DataType::INT64, types::PatternType::GENERAL, "The Agent Short ID"),
424+
ColInfo("kernel_headers_installed", types::DataType::BOOLEAN, types::PatternType::GENERAL,
425+
kKernelHeadersInstalledDesc));
426+
}
427+
428+
Status Init(FunctionContext*) {
429+
px::vizier::services::metadata::AgentInfoRequest req;
430+
resp_ = std::make_unique<px::vizier::services::metadata::AgentInfoResponse>();
431+
432+
grpc::ClientContext ctx;
433+
add_context_authentication_func_(&ctx);
434+
auto s = stub_->GetAgentInfo(&ctx, req, resp_.get());
435+
if (!s.ok()) {
436+
return error::Internal("Failed to make RPC call to GetAgentInfo");
437+
}
438+
return Status::OK();
439+
}
440+
441+
bool NextRecord(FunctionContext*, RecordWriter* rw) {
442+
const auto& agent_metadata = resp_->info(idx_);
443+
const auto& agent_info = agent_metadata.agent();
444+
445+
const auto asid = agent_info.asid();
446+
const auto kernel_headers_installed = agent_info.info().host_info().kernel_headers_installed();
447+
rw->Append<IndexOf("asid")>(asid);
448+
rw->Append<IndexOf("kernel_headers_installed")>(kernel_headers_installed);
449+
450+
++idx_;
451+
return idx_ < resp_->info_size();
452+
}
453+
454+
private:
455+
int idx_ = 0;
456+
std::unique_ptr<px::vizier::services::metadata::AgentInfoResponse> resp_;
457+
std::shared_ptr<MDSStub> stub_;
458+
std::function<void(grpc::ClientContext*)> add_context_authentication_func_;
459+
};
460+
399461
namespace internal {
400462
inline rapidjson::GenericStringRef<char> StringRef(std::string_view s) {
401463
return rapidjson::GenericStringRef<char>(s.data(), s.size());

src/vizier/services/agent/kelvin/kelvin_main.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ int main(int argc, char** argv) {
9191
LOG(INFO) << absl::Substitute("Pixie Kelvin. Version: $0, id: $1, kernel: $2",
9292
px::VersionInfo::VersionString(), agent_id.str(),
9393
kernel_version.ToString());
94-
auto manager = KelvinManager::Create(agent_id, FLAGS_pod_name, FLAGS_host_ip, addr,
95-
FLAGS_rpc_port, FLAGS_nats_url, mds_addr, kernel_version)
96-
.ConsumeValueOrDie();
94+
auto manager =
95+
KelvinManager::Create(agent_id, FLAGS_pod_name, FLAGS_host_ip, addr, FLAGS_rpc_port,
96+
FLAGS_nats_url, mds_addr, kernel_version, /* kernel_headers_installed */ false)
9797

9898
TerminationHandler::set_manager(manager.get());
9999

src/vizier/services/agent/kelvin/kelvin_manager.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ class KelvinManager : public Manager {
4444
KelvinManager() = delete;
4545
KelvinManager(sole::uuid agent_id, std::string_view pod_name, std::string_view host_ip,
4646
std::string_view addr, int grpc_server_port, std::string_view nats_url,
47-
std::string_view mds_url, system::KernelVersion kernel_version)
47+
std::string_view mds_url, system::KernelVersion kernel_version,
48+
bool kernel_headers_installed)
4849
: Manager(agent_id, pod_name, host_ip, grpc_server_port, KelvinManager::Capabilities(),
49-
KelvinManager::Parameters(), nats_url, mds_url, kernel_version) {
50+
KelvinManager::Parameters(), nats_url, mds_url, kernel_version,
51+
kernel_headers_installed) {
5052
info()->address = std::string(addr);
5153
}
5254

src/vizier/services/agent/pem/pem_main.cc

+17-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "src/common/base/base.h"
2626
#include "src/common/signal/signal.h"
2727
#include "src/common/system/kernel_version.h"
28+
#include "src/common/system/linux_headers_utils.h"
2829
#include "src/shared/version/version.h"
2930

3031
DEFINE_string(nats_url, gflags::StringFromEnv("PL_NATS_URL", "pl-nats"),
@@ -41,6 +42,8 @@ using ::px::vizier::agent::DefaultDeathHandler;
4142
using ::px::vizier::agent::PEMManager;
4243
using ::px::vizier::agent::TerminationHandler;
4344

45+
constexpr std::string_view kLinuxHeadersPath = "/lib/modules";
46+
4447
int main(int argc, char** argv) {
4548
px::EnvironmentGuard env_guard(&argc, argv);
4649

@@ -68,9 +71,20 @@ int main(int argc, char** argv) {
6871
LOG(INFO) << absl::Substitute("Pixie PEM. Version: $0, id: $1, kernel version: $2",
6972
px::VersionInfo::VersionString(), agent_id.str(),
7073
kernel_version.ToString());
71-
auto manager =
72-
PEMManager::Create(agent_id, FLAGS_pod_name, FLAGS_host_ip, FLAGS_nats_url, kernel_version)
73-
.ConsumeValueOrDie();
74+
75+
auto kernel_headers_installed = false;
76+
auto uname = px::system::GetUname();
77+
if (uname.ok()) {
78+
const auto host_path = px::system::Config::GetInstance().ToHostPath(absl::Substitute("$0/$1/$2", kLinuxHeadersPath, uname.ConsumeValueOrDie(), "build"));
79+
80+
const auto resolved_host_path = px::system::ResolvePossibleSymlinkToHostPath(host_path);
81+
LOG(WARNING) << "Resolved host path: " << resolved_host_path.ToString();
82+
kernel_headers_installed = resolved_host_path.ok();
83+
}
84+
85+
auto manager = PEMManager::Create(agent_id, FLAGS_pod_name, FLAGS_host_ip, FLAGS_nats_url,
86+
kernel_version, kernel_headers_installed)
87+
.ConsumeValueOrDie();
7488

7589
TerminationHandler::set_manager(manager.get());
7690

src/vizier/services/agent/pem/pem_manager.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,19 @@ class PEMManager : public Manager {
5353
protected:
5454
PEMManager() = delete;
5555
PEMManager(sole::uuid agent_id, std::string_view pod_name, std::string_view host_ip,
56-
std::string_view nats_url, px::system::KernelVersion kernel_version)
56+
std::string_view nats_url, px::system::KernelVersion kernel_version,
57+
bool kernel_headers_installed)
5758
: PEMManager(agent_id, pod_name, host_ip, nats_url,
5859
px::stirling::Stirling::Create(px::stirling::CreateSourceRegistryFromFlag()),
59-
kernel_version) {}
60+
kernel_version, kernel_headers_installed) {}
6061

6162
// Constructor which creates the HostInfo for an agent (runs once per node).
6263
PEMManager(sole::uuid agent_id, std::string_view pod_name, std::string_view host_ip,
6364
std::string_view nats_url, std::unique_ptr<stirling::Stirling> stirling,
64-
px::system::KernelVersion kernel_version)
65+
px::system::KernelVersion kernel_version, bool kernel_headers_installed)
6566
: Manager(agent_id, pod_name, host_ip, /*grpc_server_port*/ 0, PEMManager::Capabilities(),
6667
PEMManager::Parameters(), nats_url,
67-
/*mds_url*/ "", kernel_version),
68+
/*mds_url*/ "", kernel_version, kernel_headers_installed),
6869
stirling_(std::move(stirling)),
6970
node_available_memory_(prometheus::BuildGauge()
7071
.Name("node_available_memory")

src/vizier/services/agent/shared/base/info.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct Info {
4444
std::string pod_name;
4545
std::string host_ip;
4646
system::KernelVersion kernel_version;
47+
bool kernel_headers_installed = false;
4748
services::shared::agent::AgentCapabilities capabilities;
4849
services::shared::agent::AgentParameters parameters;
4950
};

src/vizier/services/agent/shared/manager/manager.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ std::shared_ptr<services::metadata::CronScriptStoreService::Stub> CreateCronScri
9898
Manager::Manager(sole::uuid agent_id, std::string_view pod_name, std::string_view host_ip,
9999
int grpc_server_port, services::shared::agent::AgentCapabilities capabilities,
100100
services::shared::agent::AgentParameters parameters, std::string_view nats_url,
101-
std::string_view mds_url, system::KernelVersion kernel_version)
101+
std::string_view mds_url, system::KernelVersion kernel_version,
102+
bool kernel_headers_installed)
102103
: grpc_channel_creds_(SSL::DefaultGRPCClientCreds()),
103104
time_system_(std::make_unique<px::event::RealTimeSystem>()),
104105
api_(std::make_unique<px::event::APIImpl>(time_system_.get())),
@@ -135,6 +136,7 @@ Manager::Manager(sole::uuid agent_id, std::string_view pod_name, std::string_vie
135136
info_.pod_name = std::string(pod_name);
136137
info_.host_ip = std::string(host_ip);
137138
info_.kernel_version = kernel_version;
139+
info_.kernel_headers_installed = kernel_headers_installed;
138140
}
139141

140142
Status Manager::Init() {

src/vizier/services/agent/shared/manager/manager.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class Manager : public BaseManager {
109109
Manager(sole::uuid agent_id, std::string_view pod_name, std::string_view host_ip,
110110
int grpc_server_port, services::shared::agent::AgentCapabilities capabilities,
111111
services::shared::agent::AgentParameters parameters, std::string_view nats_url,
112-
std::string_view mds_url, system::KernelVersion kernel_version);
112+
std::string_view mds_url, system::KernelVersion kernel_version,
113+
bool kernel_headers_installed);
113114
Status Init();
114115

115116
Status RegisterMessageHandler(MsgCase c, std::shared_ptr<MessageHandler> handler,

src/vizier/services/agent/shared/manager/registration.cc

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Status RegistrationHandler::DispatchRegistration() {
9292
host_info->set_host_ip(agent_info()->host_ip);
9393
auto kernel_version_proto = KernelToProto(agent_info()->kernel_version);
9494
host_info->mutable_kernel()->CopyFrom(kernel_version_proto);
95+
host_info->set_kernel_headers_installed(agent_info()->kernel_headers_installed);
9596
*req_info->mutable_capabilities() = agent_info()->capabilities;
9697
*req_info->mutable_parameters() = agent_info()->parameters;
9798

src/vizier/services/shared/agentpb/agent.proto

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ message HostInfo {
6262
string host_ip = 3 [ (gogoproto.customname) = "HostIP" ];
6363
// Version of the kernel running on the host.
6464
KernelVersion kernel = 4;
65+
// Whether kernel headers were preinstalled on the host.
66+
bool kernel_headers_installed = 5;
6567
}
6668

6769
// Agent contains information about a specific agent instance.

0 commit comments

Comments
 (0)