From c7f97f993dea465064538e518907e3152191bd17 Mon Sep 17 00:00:00 2001 From: JoukoVirtanen Date: Fri, 20 Mar 2026 10:10:18 -0700 Subject: [PATCH 1/2] X-Smart-Branch-Parent: main From 790682ff96b1fef7178088fe4586b36707669f58 Mon Sep 17 00:00:00 2001 From: JoukoVirtanen Date: Fri, 20 Mar 2026 10:26:26 -0700 Subject: [PATCH 2/2] Updated edition to 2024 and fixed format --- fact/Cargo.toml | 2 +- fact/build.rs | 2 +- fact/src/bpf/checks.rs | 2 +- fact/src/bpf/mod.rs | 12 ++++++------ fact/src/config/mod.rs | 10 +++------- fact/src/config/reloader.rs | 4 ++-- fact/src/endpoints.rs | 2 +- fact/src/event/mod.rs | 12 ++++++------ fact/src/event/process.rs | 8 ++++---- fact/src/host_info.rs | 8 ++++---- fact/src/host_scanner.rs | 4 ++-- fact/src/lib.rs | 6 +++--- fact/src/metrics/exporter.rs | 2 +- fact/src/output/grpc.rs | 4 ++-- fact/src/pre_flight.rs | 2 +- 15 files changed, 38 insertions(+), 42 deletions(-) diff --git a/fact/Cargo.toml b/fact/Cargo.toml index 2641ee9f..a2b946f6 100644 --- a/fact/Cargo.toml +++ b/fact/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "fact" version = "0.3.0-dev" -edition = "2021" +edition = "2024" license.workspace = true diff --git a/fact/build.rs b/fact/build.rs index 48a15b1e..131bcee7 100644 --- a/fact/build.rs +++ b/fact/build.rs @@ -1,6 +1,6 @@ use std::{path::PathBuf, process::Command}; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; fn main() -> anyhow::Result<()> { println!("cargo::rerun-if-changed=../.git/HEAD"); diff --git a/fact/src/bpf/checks.rs b/fact/src/bpf/checks.rs index 10690fc4..1686fdfc 100644 --- a/fact/src/bpf/checks.rs +++ b/fact/src/bpf/checks.rs @@ -1,5 +1,5 @@ use anyhow::Context; -use aya::{programs::Lsm, Btf}; +use aya::{Btf, programs::Lsm}; use log::debug; pub(super) struct Checks { diff --git a/fact/src/bpf/mod.rs b/fact/src/bpf/mod.rs index 44d832ad..167a420c 100644 --- a/fact/src/bpf/mod.rs +++ b/fact/src/bpf/mod.rs @@ -1,10 +1,10 @@ use std::{io, path::PathBuf}; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; use aya::{ - maps::{HashMap, LpmTrie, MapData, PerCpuArray, RingBuf}, - programs::{lsm::LsmLink, Program}, Btf, Ebpf, + maps::{HashMap, LpmTrie, MapData, PerCpuArray, RingBuf}, + programs::{Program, lsm::LsmLink}, }; use checks::Checks; use globset::{Glob, GlobSet, GlobSetBuilder}; @@ -18,7 +18,7 @@ use tokio::{ use crate::{event::Event, host_info, metrics::EventCounter}; -use fact_ebpf::{event_t, inode_key_t, inode_value_t, metrics_t, path_prefix_t, LPM_SIZE_MAX}; +use fact_ebpf::{LPM_SIZE_MAX, event_t, inode_key_t, inode_value_t, metrics_t, path_prefix_t}; mod checks; @@ -273,8 +273,8 @@ mod bpf_tests { use tokio::{sync::watch, time::timeout}; use crate::{ - config::{reloader::Reloader, FactConfig}, - event::{process::Process, EventTestData}, + config::{FactConfig, reloader::Reloader}, + event::{EventTestData, process::Process}, host_info, metrics::exporter::Exporter, }; diff --git a/fact/src/config/mod.rs b/fact/src/config/mod.rs index 4091477f..ca832572 100644 --- a/fact/src/config/mod.rs +++ b/fact/src/config/mod.rs @@ -7,10 +7,10 @@ use std::{ time::Duration, }; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; use clap::Parser; use log::info; -use yaml_rust2::{yaml, Yaml, YamlLoader}; +use yaml_rust2::{Yaml, YamlLoader, yaml}; pub mod reloader; #[cfg(test)] @@ -47,11 +47,7 @@ impl FactConfig { .iter() .filter_map(|p| { let p = Path::new(p); - if p.exists() { - Some(p) - } else { - None - } + if p.exists() { Some(p) } else { None } }) .map(|p| { let content = diff --git a/fact/src/config/reloader.rs b/fact/src/config/reloader.rs index 1f33c37a..e5a764ea 100644 --- a/fact/src/config/reloader.rs +++ b/fact/src/config/reloader.rs @@ -4,12 +4,12 @@ use std::{ use log::{debug, info, warn}; use tokio::{ - sync::{watch, Notify}, + sync::{Notify, watch}, task::JoinHandle, time::interval, }; -use super::{EndpointConfig, FactConfig, GrpcConfig, CONFIG_FILES}; +use super::{CONFIG_FILES, EndpointConfig, FactConfig, GrpcConfig}; pub struct Reloader { config: FactConfig, diff --git a/fact/src/endpoints.rs b/fact/src/endpoints.rs index 0fafe593..cc97415a 100644 --- a/fact/src/endpoints.rs +++ b/fact/src/endpoints.rs @@ -2,10 +2,10 @@ use std::{future::Future, pin::Pin}; use http_body_util::Full; use hyper::{ + Method, Request, Response, StatusCode, body::{Bytes, Incoming}, server::conn::http1, service::Service, - Method, Request, Response, StatusCode, }; use hyper_util::rt::TokioIo; use log::{info, warn}; diff --git a/fact/src/event/mod.rs b/fact/src/event/mod.rs index 98a70162..9087f5ab 100644 --- a/fact/src/event/mod.rs +++ b/fact/src/event/mod.rs @@ -9,7 +9,7 @@ use std::{ use globset::GlobSet; use serde::Serialize; -use fact_ebpf::{event_t, file_activity_type_t, inode_key_t, PATH_MAX}; +use fact_ebpf::{PATH_MAX, event_t, file_activity_type_t, inode_key_t}; use crate::host_info; use process::Process; @@ -43,11 +43,11 @@ fn sanitize_d_path(s: &[c_char]) -> PathBuf { // Take the file name of the path and remove the " (deleted)" suffix // if present. - if let Some(file_name) = p.file_name() { - if let Some(file_name) = file_name.to_string_lossy().strip_suffix(" (deleted)") { - // The file name needed to be sanitized - return p.parent().map(|p| p.join(file_name)).unwrap_or_default(); - } + if let Some(file_name) = p.file_name() + && let Some(file_name) = file_name.to_string_lossy().strip_suffix(" (deleted)") + { + // The file name needed to be sanitized + return p.parent().map(|p| p.join(file_name)).unwrap_or_default(); } p.to_path_buf() diff --git a/fact/src/event/process.rs b/fact/src/event/process.rs index 3dc6fd4b..f295ac66 100644 --- a/fact/src/event/process.rs +++ b/fact/src/event/process.rs @@ -244,16 +244,16 @@ mod tests { Some("2bc55a8cae17".to_string()), ), ( - "/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podce705797_e47e_11e9_bd71_42010a000002.slice/docker-6525e65814a99d431b6978e8f8c895013176c6c58173b56639d4b020c14e6022.scope", - Some("6525e65814a9".to_string()), + "/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podce705797_e47e_11e9_bd71_42010a000002.slice/docker-6525e65814a99d431b6978e8f8c895013176c6c58173b56639d4b020c14e6022.scope", + Some("6525e65814a9".to_string()), ), ( "/machine.slice/libpod-b6e375cfe46efa5cd90d095603dec2de888c28b203285819233040b5cf1212ac.scope/container", Some("b6e375cfe46e".to_string()), ), ( - "/machine.slice/libpod-cbdfa0f1f08763b1963c30d98e11e1f052cb67f1e9b7c0ab8a6ca6c70cbcad69.scope/container/kubelet.slice/kubelet-kubepods.slice/kubelet-kubepods-besteffort.slice/kubelet-kubepods-besteffort-pod6eab3b7b_f0a6_4bb8_bff2_d5bc9017c04b.slice/cri-containerd-5ebf11e02dbde102cda4b76bc0e3849a65f9edac7a12bdabfd34db01b9556101.scope", - Some("5ebf11e02dbd".to_string()), + "/machine.slice/libpod-cbdfa0f1f08763b1963c30d98e11e1f052cb67f1e9b7c0ab8a6ca6c70cbcad69.scope/container/kubelet.slice/kubelet-kubepods.slice/kubelet-kubepods-besteffort.slice/kubelet-kubepods-besteffort-pod6eab3b7b_f0a6_4bb8_bff2_d5bc9017c04b.slice/cri-containerd-5ebf11e02dbde102cda4b76bc0e3849a65f9edac7a12bdabfd34db01b9556101.scope", + Some("5ebf11e02dbd".to_string()), ), ]; diff --git a/fact/src/host_info.rs b/fact/src/host_info.rs index fdc0a718..b00531d4 100644 --- a/fact/src/host_info.rs +++ b/fact/src/host_info.rs @@ -3,8 +3,8 @@ use log::{debug, warn}; use std::{ collections::HashMap, env, - ffi::{c_char, CStr, CString}, - fs::{read_to_string, File}, + ffi::{CStr, CString, c_char}, + fs::{File, read_to_string}, io::{BufRead, BufReader}, mem, path::{Path, PathBuf}, @@ -12,8 +12,8 @@ use std::{ }; use libc::{ - clockid_t, statx, timespec, uname, AT_FDCWD, AT_NO_AUTOMOUNT, AT_STATX_SYNC_AS_STAT, - CLOCK_BOOTTIME, CLOCK_REALTIME, STATX_INO, + AT_FDCWD, AT_NO_AUTOMOUNT, AT_STATX_SYNC_AS_STAT, CLOCK_BOOTTIME, CLOCK_REALTIME, STATX_INO, + clockid_t, statx, timespec, uname, }; pub fn get_host_mount() -> &'static PathBuf { diff --git a/fact/src/host_scanner.rs b/fact/src/host_scanner.rs index ad7db6f9..05d22e75 100644 --- a/fact/src/host_scanner.rs +++ b/fact/src/host_scanner.rs @@ -26,12 +26,12 @@ use std::{ time::Duration, }; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; use aya::maps::MapData; use fact_ebpf::{inode_key_t, inode_value_t}; use log::{debug, info, warn}; use tokio::{ - sync::{broadcast, mpsc, watch, Notify}, + sync::{Notify, broadcast, mpsc, watch}, task::JoinHandle, }; diff --git a/fact/src/lib.rs b/fact/src/lib.rs index 422df3b2..f7bf1087 100644 --- a/fact/src/lib.rs +++ b/fact/src/lib.rs @@ -2,12 +2,12 @@ use std::{borrow::BorrowMut, io::Write, str::FromStr}; use anyhow::Context; use bpf::Bpf; -use host_info::{get_distro, get_hostname, SystemInfo}; +use host_info::{SystemInfo, get_distro, get_hostname}; use host_scanner::HostScanner; -use log::{debug, info, warn, LevelFilter}; +use log::{LevelFilter, debug, info, warn}; use metrics::exporter::Exporter; use tokio::{ - signal::unix::{signal, SignalKind}, + signal::unix::{SignalKind, signal}, sync::{mpsc, watch}, }; diff --git a/fact/src/metrics/exporter.rs b/fact/src/metrics/exporter.rs index 03bf20fb..a3a4b772 100644 --- a/fact/src/metrics/exporter.rs +++ b/fact/src/metrics/exporter.rs @@ -6,7 +6,7 @@ use prometheus_client::{encoding::text::encode, registry::Registry}; use fact_ebpf::metrics_t; -use super::{kernel_metrics::KernelMetrics, Metrics}; +use super::{Metrics, kernel_metrics::KernelMetrics}; #[derive(Clone)] pub struct Exporter { diff --git a/fact/src/output/grpc.rs b/fact/src/output/grpc.rs index 35d29648..178a4f39 100644 --- a/fact/src/output/grpc.rs +++ b/fact/src/output/grpc.rs @@ -1,6 +1,6 @@ use std::{sync::Arc, time::Duration}; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; use fact_api::file_activity_service_client::FileActivityServiceClient; use hyper_tls::HttpsConnector; use hyper_util::client::legacy::connect::HttpConnector; @@ -13,8 +13,8 @@ use tokio::{ time::sleep, }; use tokio_stream::{ - wrappers::{errors::BroadcastStreamRecvError, BroadcastStream}, StreamExt, + wrappers::{BroadcastStream, errors::BroadcastStreamRecvError}, }; use tonic::transport::Channel; diff --git a/fact/src/pre_flight.rs b/fact/src/pre_flight.rs index 99c0f10b..ffff0fe4 100644 --- a/fact/src/pre_flight.rs +++ b/fact/src/pre_flight.rs @@ -1,6 +1,6 @@ use std::fs::read_to_string; -use anyhow::{bail, Context}; +use anyhow::{Context, bail}; use crate::host_info::get_host_mount;