Skip to content

Commit b4b6486

Browse files
committed
test fix
Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent c1de391 commit b4b6486

File tree

1 file changed

+29
-3
lines changed
  • lading/src/observer/linux/cgroup

1 file changed

+29
-3
lines changed

lading/src/observer/linux/cgroup/v2.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
use std::{io, path::PathBuf};
1+
use std::{
2+
io,
3+
path::{Path, PathBuf},
4+
};
25

36
use metrics::gauge;
47
use tokio::fs;
8+
use tracing::debug;
59

610
#[derive(thiserror::Error, Debug)]
711
pub enum Error {
@@ -68,7 +72,7 @@ pub(crate) async fn poll(path: PathBuf, labels: &[(String, String)]) -> Result<(
6872
gauge!(metric_prefix, labels).set(value);
6973
} else {
7074
// Key-value pairs
71-
if kv_pairs(content, &metric_prefix, labels).is_err() {
75+
if kv_pairs(&file_path, content, &metric_prefix, labels).is_err() {
7276
// File may fail to parse, for instance cgroup.controllers
7377
// is a list of strings.
7478
continue;
@@ -80,9 +84,31 @@ pub(crate) async fn poll(path: PathBuf, labels: &[(String, String)]) -> Result<(
8084
Ok(())
8185
}
8286

83-
fn kv_pairs(content: &str, metric_prefix: &str, labels: &[(String, String)]) -> Result<(), Error> {
87+
fn kv_pairs(
88+
file_path: &Path,
89+
content: &str,
90+
metric_prefix: &str,
91+
labels: &[(String, String)],
92+
) -> Result<(), Error> {
8493
for line in content.lines() {
8594
let mut parts = line.split_whitespace();
95+
if let Some(key) = parts.next() {
96+
if let Some(value_str) = parts.next() {
97+
let value: f64 = value_str.parse()?;
98+
let metric_name = format!("{metric_prefix}.{key}");
99+
gauge!(metric_name, labels).set(value);
100+
} else {
101+
debug!(
102+
"[{path}] missing value in key/value pair: {content}",
103+
path = file_path.to_string_lossy(),
104+
);
105+
}
106+
} else {
107+
debug!(
108+
"[{path} missing key in key/value pair: {content}",
109+
path = file_path.to_string_lossy(),
110+
);
111+
}
86112
let key = parts.next().expect("malformed key-value pair");
87113
let value_str = parts.next().expect("malformed key-value pair");
88114
let value: f64 = value_str.parse()?;

0 commit comments

Comments
 (0)