Skip to content

Commit

Permalink
Update procfs to 0.17
Browse files Browse the repository at this point in the history
This commit updates procfs dependency to 0.17. #1096 is now redundant.

Signed-off-by: Brian L. Troutwine <[email protected]>
  • Loading branch information
blt committed Dec 2, 2024
1 parent fef9151 commit 63f1ce0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 113 deletions.
107 changes: 15 additions & 92 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 lading/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ zstd = "0.13.1"

[target.'cfg(target_os = "linux")'.dependencies]
cgroups-rs = { version = "0.3", default-features = false, features = [] }
procfs = { version = "0.15", default-features = false, features = [] }
procfs = { version = "0.17", default-features = false, features = [] }
async-pidfd = "0.1"

[dev-dependencies]
Expand Down
6 changes: 4 additions & 2 deletions lading/src/bin/lading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum Error {
#[error("Failed to deserialize Lading config: {0}")]
SerdeYaml(#[from] serde_yaml::Error),
#[error("Lading failed to sync servers {0}")]
Send(#[from] tokio::sync::broadcast::error::SendError<Option<u32>>),
Send(#[from] tokio::sync::broadcast::error::SendError<Option<i32>>),
#[error("Maximum RSS bytes limit exceeds u64::MAX {0}")]
Meta(#[from] lading::target::MetaError),
#[error("Parsing Prometheus address failed: {0}")]
Expand Down Expand Up @@ -267,7 +267,9 @@ fn get_config(ops: &Opts, config: Option<String>) -> Result<Config, Error> {
let target = if ops.no_target {
None
} else if let Some(pid) = ops.target_pid {
Some(target::Config::Pid(target::PidConfig { pid }))
Some(target::Config::Pid(target::PidConfig {
pid: pid.try_into().expect("Could not convert pid to i32"),
}))
} else if let Some(name) = &ops.target_container {
Some(target::Config::Docker(target::DockerConfig {
name: name.clone(),
Expand Down
10 changes: 4 additions & 6 deletions lading/src/observer/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{collections::VecDeque, io, path::Path, sync::atomic::Ordering};
use cgroups_rs::cgroup::Cgroup;
use metrics::gauge;
use nix::errno::Errno;
use procfs::process::Process;
use procfs::ProcError::PermissionDenied;
use procfs::{process::Process, Current};
use rustc_hash::{FxHashMap, FxHashSet};
use tracing::{error, warn};

Expand Down Expand Up @@ -89,8 +89,8 @@ impl Gauge {
}

impl Sampler {
pub(crate) fn new(parent_pid: u32) -> Result<Self, Error> {
let parent = Process::new(parent_pid.try_into().expect("PID coercion failed"))?;
pub(crate) fn new(parent_pid: i32) -> Result<Self, Error> {
let parent = Process::new(parent_pid)?;

Ok(Self {
parent,
Expand Down Expand Up @@ -126,9 +126,7 @@ impl Sampler {
// later for calculating per-process uptime. Because we capture this one
// we will be slightly out of date with each subsequent iteration of the
// loop. We do not believe this to be an issue.
let uptime_seconds: f64 = procfs::Uptime::new()
.expect("could not query machine uptime")
.uptime; // seconds since boot
let uptime_seconds: f64 = procfs::Uptime::current()?.uptime; // seconds since boot
let uptime_ticks: u64 = uptime_seconds.round() as u64 * self.ticks_per_second; // CPU-ticks since boot

// Clear values from previous sample run. This ensures that processes
Expand Down
24 changes: 12 additions & 12 deletions lading/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::{
io,
num::NonZeroU32,
num::NonZeroI32,
path::PathBuf,
process::{ExitStatus, Stdio},
sync::atomic::{AtomicU64, Ordering},
Expand Down Expand Up @@ -45,10 +45,10 @@ pub(crate) static RSS_BYTES_LIMIT: AtomicU64 = AtomicU64::new(u64::MAX);

/// Type used to receive the target PID once it is running.
#[allow(clippy::module_name_repetitions)]
pub type TargetPidReceiver = tokio::sync::broadcast::Receiver<Option<u32>>;
pub type TargetPidReceiver = tokio::sync::broadcast::Receiver<Option<i32>>;

#[allow(clippy::module_name_repetitions)]
type TargetPidSender = tokio::sync::broadcast::Sender<Option<u32>>;
type TargetPidSender = tokio::sync::broadcast::Sender<Option<i32>>;

/// Errors produced by [`Meta`]
#[derive(thiserror::Error, Debug, Clone, Copy)]
Expand Down Expand Up @@ -112,13 +112,13 @@ pub enum Error {
SigTerm(Errno),
/// The target PID does not exist or is invalid
#[error("PID not found: {0}")]
PidNotFound(u32),
PidNotFound(i32),
/// The target process exited unexpectedly
#[error("target exited unexpectedly: {0:?}")]
TargetExited(Option<ExitStatus>),
/// See [`SendError`]
#[error(transparent)]
Send(#[from] tokio::sync::broadcast::error::SendError<Option<u32>>),
Send(#[from] tokio::sync::broadcast::error::SendError<Option<i32>>),
/// Process already finished error
#[error("Child has already been polled to completion")]
ProcessFinished,
Expand All @@ -140,7 +140,7 @@ pub struct DockerConfig {
#[derive(Debug, PartialEq, Eq)]
pub struct PidConfig {
/// PID to watch
pub pid: NonZeroU32,
pub pid: NonZeroI32,
}

/// Configuration for binary launch mode
Expand Down Expand Up @@ -352,11 +352,7 @@ impl Server {
) -> Result<(), Error> {
// Convert pid config value to a plain i32 (no truncation concerns;
// PID_MAX_LIMIT is 2^22)
let raw_pid: i32 = config
.pid
.get()
.try_into()
.map_err(|_| Error::PidNotFound(config.pid.get()))?;
let raw_pid: i32 = config.pid.get();
let pid = Pid::from_raw(raw_pid);

// Verify that the given PID is valid
Expand Down Expand Up @@ -443,7 +439,11 @@ impl Server {
.envs(config.environment_variables.iter());
let mut target_child = target_cmd.spawn().map_err(Error::TargetSpawn)?;
let target_id = target_child.id().ok_or(Error::ProcessFinished)?;
pid_snd.send(Some(target_id))?;
pid_snd.send(Some(
target_id
.try_into()
.expect("could not convert target pid to i32"),
))?;
drop(pid_snd);
target_running.signal();

Expand Down

0 comments on commit 63f1ce0

Please sign in to comment.