Skip to content

Commit

Permalink
Fix #13 and solve problem about node created during execution
Browse files Browse the repository at this point in the history
  • Loading branch information
AngeCyp committed Jun 26, 2024
1 parent 196306a commit b395411
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion plugin-k8s/src/cgroup_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fn list_metric_file_in_dir(root_directory_path: &Path) -> anyhow::Result<Vec<Cgr
new_prefix.push_str("-");
let uid = dir_uid_mod.strip_prefix(&new_prefix).unwrap_or(&dir_uid_mod);
path_cloned.push("cpu.stat");
let name_to_seek = uid.strip_prefix("pod").unwrap_or(uid);
let name_to_seek_raw = uid.strip_prefix("pod").unwrap_or(uid);
let name_to_seek = name_to_seek_raw.replace("_", "-");
// let (name, ns) = get_pod_name(name_to_seek.to_owned());
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
Expand Down
4 changes: 3 additions & 1 deletion plugin-k8s/src/k8s_probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ impl alumet::pipeline::Source for K8SProbe {
)
.with_attr("uid", AttributeValue::String(metrics.uid.clone()))
.with_attr("name", AttributeValue::String(metrics.name.clone()))
.with_attr("namespace", AttributeValue::String(metrics.namespace.clone()));
.with_attr("namespace", AttributeValue::String(metrics.namespace.clone()))
.with_attr("node", AttributeValue::String(metrics.node.clone()));

measurements.push(p_sys);
}
Ok(())
Expand Down
24 changes: 21 additions & 3 deletions plugin-k8s/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,37 @@ impl AlumetPlugin for K8sPlugin {
// The events look like the following
// Handle_Event: Ok(Event { kind: Create(Folder), paths: ["/sys/fs/cgroup/kubepods.slice/kubepods-besteffort.slice/TESTTTTT"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None })
// Handle_Event: Ok(Event { kind: Remove(Folder), paths: ["/sys/fs/cgroup/kubepods.slice/kubepods-besteffort.slice/TESTTTTT"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None })
log::debug!("Handle event function");
if let Ok(Event {
kind: EventKind::Create(notify::event::CreateKind::Folder),
paths,
..
}) = event
{
for path in paths {
for mut path in paths {
match path.extension() {
None => {
// Case of no extension found --> I will not find cpu.stat file
return;
},
Some(os_str) => match os_str.to_str() {
Some("slice") => {
// Case of .slice found --> I will find cpu.stat file
log::debug!(".slice extension found, will continue");
},
_ => {
// Case of an other extension than .slice is found --> I will not find cpu.stat file
return;
}
},
};
if let Some(pod_uid) = path.file_name() {
let pod_uid = pod_uid.to_str().unwrap();
// We open a File Descriptor to the newly created file
let mut path_cpu = path.clone();
let name_to_seek = pod_uid.strip_prefix("pod").unwrap_or(pod_uid);
let full_name_to_seek = pod_uid.strip_suffix(".slice").unwrap_or(&pod_uid);
let parts: Vec<&str> = full_name_to_seek.split("pod").collect();
let name_to_seek_raw = *(parts.last().unwrap_or(&full_name_to_seek));
let name_to_seek = name_to_seek_raw.replace("_", "-");
// let (name, ns) = cgroup_v2::get_pod_name(name_to_seek.to_owned());
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
Expand Down

0 comments on commit b395411

Please sign in to comment.