Skip to content

Commit

Permalink
convert youki to use tracing
Browse files Browse the repository at this point in the history
Signed-off-by: yihuaf <yihuaf@unkies.org>
  • Loading branch information
yihuaf committed May 10, 2023
1 parent 69efb97 commit 1514559
Show file tree
Hide file tree
Showing 69 changed files with 348 additions and 335 deletions.
120 changes: 115 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/libcgroups/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ cgroupsv2_devices = ["rbpf", "libbpf-sys", "errno", "libc"]
[dependencies]
nix = "0.26.2"
procfs = "0.15.1"
log = "0.4"
oci-spec = { version = "^0.6.0", features = ["runtime"] }
dbus = { version = "0.9.7", optional = true }
fixedbitset = "0.4.2"
Expand All @@ -32,6 +31,7 @@ libbpf-sys = { version = "1.1.1", optional = true }
errno = { version = "0.3.1", optional = true }
libc = { version = "0.2.144", optional = true }
thiserror = "1.0.40"
tracing = { version = "0.1.37", features = ["attributes"]}

[dev-dependencies]
anyhow = "1.0"
Expand Down
8 changes: 4 additions & 4 deletions crates/libcgroups/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ pub fn create_cgroup_manager<P: Into<PathBuf>>(
fn create_v1_cgroup_manager(
cgroup_path: PathBuf,
) -> Result<v1::manager::Manager, v1::manager::V1ManagerError> {
log::info!("cgroup manager V1 will be used");
tracing::info!("cgroup manager V1 will be used");
v1::manager::Manager::new(cgroup_path)
}

Expand All @@ -362,7 +362,7 @@ fn create_v1_cgroup_manager(_cgroup_path: PathBuf) -> Result<Box<dyn CgroupManag
fn create_v2_cgroup_manager(
cgroup_path: PathBuf,
) -> Result<v2::manager::Manager, v2::manager::V2ManagerError> {
log::info!("cgroup manager V2 will be used");
tracing::info!("cgroup manager V2 will be used");
v2::manager::Manager::new(DEFAULT_CGROUP_ROOT.into(), cgroup_path)
}

Expand All @@ -384,7 +384,7 @@ fn create_systemd_cgroup_manager(

let use_system = nix::unistd::geteuid().is_root();

log::info!(
tracing::info!(
"systemd cgroup manager with system bus {} will be used",
use_system
);
Expand All @@ -405,7 +405,7 @@ fn create_systemd_cgroup_manager(
}

pub fn get_all_pids(path: &Path) -> Result<Vec<Pid>, WrappedIoError> {
log::debug!("scan pids in folder: {:?}", path);
tracing::debug!("scan pids in folder: {:?}", path);
let mut result = vec![];
walk_dir(path, &mut |p| {
let file_path = p.join(CGROUP_PROCS);
Expand Down
2 changes: 1 addition & 1 deletion crates/libcgroups/src/systemd/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Controller for Cpu {
properties: &mut HashMap<&str, Box<dyn RefArg>>,
) -> Result<(), Self::Error> {
if let Some(cpu) = options.resources.cpu() {
log::debug!("Applying cpu resource restrictions");
tracing::debug!("Applying cpu resource restrictions");
Self::apply(cpu, properties)?;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/libcgroups/src/systemd/cpuset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Controller for CpuSet {
properties: &mut HashMap<&str, Box<dyn RefArg>>,
) -> Result<(), Self::Error> {
if let Some(cpu) = options.resources.cpu() {
log::debug!("Applying cpuset resource restrictions");
tracing::debug!("Applying cpuset resource restrictions");
return Self::apply(cpu, systemd_version, properties);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/libcgroups/src/systemd/dbus/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl SystemdClient for Client {
properties.push(("DefaultDependencies", Variant(Box::new(false))));
properties.push(("PIDs", Variant(Box::new(vec![pid]))));

log::debug!("Starting transient unit: {:?}", properties);
tracing::debug!("Starting transient unit: {:?}", properties);
proxy
.start_transient_unit(unit_name, "replace", properties, vec![])
.map_err(|err| SystemdClientError::FailedTransient {
Expand Down
8 changes: 4 additions & 4 deletions crates/libcgroups/src/systemd/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl Manager {
while let Some(component) = components.next() {
current_path = current_path.join(component);
if !current_path.exists() {
log::warn!(
tracing::warn!(
"{:?} does not exist. Resource restrictions might not work correctly",
current_path
);
Expand Down Expand Up @@ -357,7 +357,7 @@ impl CgroupManager for Manager {
return Ok(());
}

log::debug!("Starting {:?}", self.unit_name);
tracing::debug!("Starting {:?}", self.unit_name);
self.client.start_transient_unit(
&self.container_name,
pid.as_raw() as u32,
Expand Down Expand Up @@ -394,7 +394,7 @@ impl CgroupManager for Manager {
}

Unified::apply(controller_opt, systemd_version, &mut properties)?;
log::debug!("{:?}", properties);
tracing::debug!("{:?}", properties);

if !properties.is_empty() {
self.ensure_controllers_attached()?;
Expand All @@ -407,7 +407,7 @@ impl CgroupManager for Manager {
}

fn remove(&self) -> Result<(), Self::Error> {
log::debug!("remove {}", self.unit_name);
tracing::debug!("remove {}", self.unit_name);
if self.client.transient_unit_exists(&self.unit_name) {
self.client.stop_transient_unit(&self.unit_name)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/libcgroups/src/systemd/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Controller for Memory {
properties: &mut HashMap<&str, Box<dyn RefArg>>,
) -> Result<(), Self::Error> {
if let Some(memory) = options.resources.memory() {
log::debug!("applying memory resource restrictions");
tracing::debug!("applying memory resource restrictions");
return Self::apply(memory, properties);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/libcgroups/src/systemd/pids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Controller for Pids {
properties: &mut HashMap<&str, Box<dyn RefArg>>,
) -> Result<(), Self::Error> {
if let Some(pids) = options.resources.pids() {
log::debug!("Applying pids resource restrictions");
tracing::debug!("Applying pids resource restrictions");
Self::apply(pids, properties);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/libcgroups/src/systemd/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Controller for Unified {
properties: &mut HashMap<&str, Box<dyn RefArg>>,
) -> Result<(), Self::Error> {
if let Some(unified) = options.resources.unified() {
log::debug!("applying unified resource restrictions");
tracing::debug!("applying unified resource restrictions");
Self::apply(unified, systemd_version, properties)?;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ impl Unified {
properties.insert(pids::TASKS_MAX, Box::new(pids as u64));
}

unknown => log::warn!("could not apply {}. Unknown property.", unknown),
unknown => tracing::warn!("could not apply {}. Unknown property.", unknown),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/libcgroups/src/v1/blkio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Controller for Blkio {
type Resource = LinuxBlockIo;

fn apply(controller_opt: &ControllerOpt, cgroup_root: &Path) -> Result<(), Self::Error> {
log::debug!("Apply blkio cgroup config");
tracing::debug!("Apply blkio cgroup config");

if let Some(blkio) = Self::needs_to_handle(controller_opt) {
Self::apply(cgroup_root, blkio)?;
Expand Down
Loading

0 comments on commit 1514559

Please sign in to comment.