Skip to content

Commit 8afc722

Browse files
authored
Replace procinfo with procfs (#2433)
This PR will replace [procinfo](https://crates.io/crates/procinfo) crate which is not maintained for over 5 years with [procfs](https://crates.io/crates/procfs). Signed-off-by: Pranoy Kumar Kundu <pranoy1998k@gmail.com> Fixes linkerd/linkerd2/issues/10819
1 parent c10c4b7 commit 8afc722

File tree

5 files changed

+51
-52
lines changed

5 files changed

+51
-52
lines changed

Cargo.lock

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ version = "0.6.0"
230230
source = "registry+https://github.com/rust-lang/crates.io-index"
231231
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
232232
dependencies = [
233-
"nom 7.1.0",
233+
"nom",
234234
]
235235

236236
[[package]]
@@ -965,7 +965,7 @@ dependencies = [
965965
"pin-project",
966966
"quickcheck",
967967
"regex",
968-
"semver 1.0.17",
968+
"semver",
969969
"serde_json",
970970
"thiserror",
971971
"tokio",
@@ -1793,7 +1793,7 @@ name = "linkerd-system"
17931793
version = "0.1.0"
17941794
dependencies = [
17951795
"libc",
1796-
"procinfo",
1796+
"procfs",
17971797
"tracing",
17981798
]
17991799

@@ -1934,6 +1934,12 @@ dependencies = [
19341934
"tonic",
19351935
]
19361936

1937+
[[package]]
1938+
name = "linux-raw-sys"
1939+
version = "0.1.4"
1940+
source = "registry+https://github.com/rust-lang/crates.io-index"
1941+
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
1942+
19371943
[[package]]
19381944
name = "linux-raw-sys"
19391945
version = "0.3.0"
@@ -2046,12 +2052,6 @@ version = "0.8.3"
20462052
source = "registry+https://github.com/rust-lang/crates.io-index"
20472053
checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
20482054

2049-
[[package]]
2050-
name = "nom"
2051-
version = "2.2.1"
2052-
source = "registry+https://github.com/rust-lang/crates.io-index"
2053-
checksum = "cf51a729ecf40266a2368ad335a5fdde43471f545a967109cd62146ecf8b66ff"
2054-
20552055
[[package]]
20562056
name = "nom"
20572057
version = "7.1.0"
@@ -2218,15 +2218,16 @@ dependencies = [
22182218
]
22192219

22202220
[[package]]
2221-
name = "procinfo"
2222-
version = "0.4.2"
2221+
name = "procfs"
2222+
version = "0.15.1"
22232223
source = "registry+https://github.com/rust-lang/crates.io-index"
2224-
checksum = "6ab1427f3d2635891f842892dda177883dca0639e05fe66796a62c9d2f23b49c"
2224+
checksum = "943ca7f9f29bab5844ecd8fdb3992c5969b6622bb9609b9502fef9b4310e3f1f"
22252225
dependencies = [
2226+
"bitflags 1.3.2",
22262227
"byteorder",
2227-
"libc",
2228-
"nom 2.2.1",
2229-
"rustc_version",
2228+
"hex",
2229+
"lazy_static",
2230+
"rustix 0.36.14",
22302231
]
22312232

22322233
[[package]]
@@ -2419,12 +2420,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
24192420
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
24202421

24212422
[[package]]
2422-
name = "rustc_version"
2423-
version = "0.2.3"
2423+
name = "rustix"
2424+
version = "0.36.14"
24242425
source = "registry+https://github.com/rust-lang/crates.io-index"
2425-
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
2426+
checksum = "14e4d67015953998ad0eb82887a0eb0129e18a7e2f3b7b0f6c422fddcd503d62"
24262427
dependencies = [
2427-
"semver 0.9.0",
2428+
"bitflags 1.3.2",
2429+
"errno",
2430+
"io-lifetimes",
2431+
"libc",
2432+
"linux-raw-sys 0.1.4",
2433+
"windows-sys 0.45.0",
24282434
]
24292435

24302436
[[package]]
@@ -2437,7 +2443,7 @@ dependencies = [
24372443
"errno",
24382444
"io-lifetimes",
24392445
"libc",
2440-
"linux-raw-sys",
2446+
"linux-raw-sys 0.3.0",
24412447
"windows-sys 0.45.0",
24422448
]
24432449

@@ -2500,27 +2506,12 @@ dependencies = [
25002506
"untrusted",
25012507
]
25022508

2503-
[[package]]
2504-
name = "semver"
2505-
version = "0.9.0"
2506-
source = "registry+https://github.com/rust-lang/crates.io-index"
2507-
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
2508-
dependencies = [
2509-
"semver-parser",
2510-
]
2511-
25122509
[[package]]
25132510
name = "semver"
25142511
version = "1.0.17"
25152512
source = "registry+https://github.com/rust-lang/crates.io-index"
25162513
checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
25172514

2518-
[[package]]
2519-
name = "semver-parser"
2520-
version = "0.7.0"
2521-
source = "registry+https://github.com/rust-lang/crates.io-index"
2522-
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
2523-
25242515
[[package]]
25252516
name = "serde"
25262517
version = "1.0.159"
@@ -2630,7 +2621,7 @@ dependencies = [
26302621
"cfg-if",
26312622
"fastrand",
26322623
"redox_syscall 0.3.5",
2633-
"rustix",
2624+
"rustix 0.37.4",
26342625
"windows-sys 0.45.0",
26352626
]
26362627

deny.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ skip = [
6464
{ name = "bitflags", version = "1" },
6565
]
6666
skip-tree = [
67-
# Hasn't seen a new release since 2017. Pulls in an older version of nom.
68-
{ name = "procinfo" },
67+
# right now we have a mix of versions of this crate in the ecosystem
68+
# procfs uses 0.36.14, tempfile uses 0.37.4
69+
{ name = "rustix" },
6970
]
7071

7172
[sources]

linkerd/app/core/src/telemetry/process.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ mod linux {
161161
};
162162

163163
if let Some(mpt) = self.ms_per_tick {
164-
let clock_ticks = stat.utime as u64 + stat.stime as u64;
164+
let clock_ticks = stat.utime + stat.stime;
165165
let cpu_ms = clock_ticks * mpt;
166166
process_cpu_seconds_total.fmt_help(f)?;
167167
process_cpu_seconds_total.fmt_metric(f, &Counter::from(cpu_ms))?;
@@ -170,11 +170,11 @@ mod linux {
170170
}
171171

172172
process_virtual_memory_bytes.fmt_help(f)?;
173-
process_virtual_memory_bytes.fmt_metric(f, &Gauge::from(stat.vsize as u64))?;
173+
process_virtual_memory_bytes.fmt_metric(f, &Gauge::from(stat.vsize))?;
174174

175175
if let Some(ps) = self.page_size {
176176
process_resident_memory_bytes.fmt_help(f)?;
177-
process_resident_memory_bytes.fmt_metric(f, &Gauge::from(stat.rss as u64 * ps))?;
177+
process_resident_memory_bytes.fmt_metric(f, &Gauge::from(stat.rss * ps))?;
178178
} else {
179179
warn!("Could not determine process_resident_memory_bytes");
180180
}
@@ -190,8 +190,7 @@ mod linux {
190190
}
191191

192192
match sys::max_fds() {
193-
Ok(None) => {}
194-
Ok(Some(max_fds)) => {
193+
Ok(max_fds) => {
195194
process_max_fds.fmt_help(f)?;
196195
process_max_fds.fmt_metric(f, &max_fds.into())?;
197196
}

linkerd/system/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ tracing = "0.1"
1414

1515
[target.'cfg(target_os = "linux")'.dependencies]
1616
libc = "0.2"
17-
procinfo = "0.4"
17+
procfs = { version = "0.15.1", default-features = false }

linkerd/system/src/linux.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use libc::{self, pid_t};
2-
use procinfo::pid;
2+
use procfs::{
3+
process::{self, LimitValue, Process},
4+
ProcResult,
5+
};
36
use std::{fs, io};
47
use tracing::{error, warn};
58

6-
pub use procinfo::pid::Stat;
9+
pub use process::Stat;
710

811
pub fn page_size() -> io::Result<u64> {
912
sysconf(libc::_SC_PAGESIZE, "page size")
@@ -24,8 +27,8 @@ pub fn ms_per_tick() -> io::Result<u64> {
2427
Ok(ms_per_tick)
2528
}
2629

27-
pub fn blocking_stat() -> io::Result<Stat> {
28-
pid::stat_self()
30+
pub fn blocking_stat() -> ProcResult<Stat> {
31+
Process::myself()?.stat()
2932
}
3033

3134
pub fn open_fds(pid: pid_t) -> io::Result<u64> {
@@ -38,10 +41,15 @@ pub fn open_fds(pid: pid_t) -> io::Result<u64> {
3841
Ok(open)
3942
}
4043

41-
pub fn max_fds() -> io::Result<Option<u64>> {
42-
let limit = pid::limits_self()?.max_open_files;
43-
let max_fds = limit.soft.or(limit.hard).map(|max| max as u64);
44-
Ok(max_fds)
44+
pub fn max_fds() -> ProcResult<u64> {
45+
let limits = Process::myself()?.limits()?.max_open_files;
46+
match limits.soft_limit {
47+
LimitValue::Unlimited => match limits.hard_limit {
48+
LimitValue::Unlimited => Ok(0),
49+
LimitValue::Value(hard) => Ok(hard),
50+
},
51+
LimitValue::Value(soft) => Ok(soft),
52+
}
4553
}
4654

4755
#[allow(unsafe_code)]

0 commit comments

Comments
 (0)