Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent: Fix an issue reporting OOM events by mistake #8773

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/agent/rustjail/src/cgroups/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
// SPDX-License-Identifier: Apache-2.0
//

use anyhow::{anyhow, Context, Result};
use eventfd::{eventfd, EfdFlags};
use nix::sys::eventfd;
use std::fs::{self, File};
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::path::Path;

use crate::pipestream::PipeStream;
use anyhow::{anyhow, Context, Result};
use eventfd::{eventfd, EfdFlags};
use futures::StreamExt as _;
use inotify::{Inotify, WatchMask};
use nix::sys::eventfd;
use tokio::io::AsyncReadExt;
use tokio::sync::mpsc::{channel, Receiver};

use crate::pipestream::PipeStream;

// Convenience function to obtain the scope logger.
fn sl() -> slog::Logger {
slog_scope::logger().new(o!("subsystem" => "cgroups_notifier"))
Expand Down Expand Up @@ -165,22 +166,22 @@ async fn register_memory_event(

tokio::spawn(async move {
loop {
let sender = sender.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the line deleted ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cuz clone() is unnecessary here.

let mut buf = [0u8; 8];
match eventfd_stream.read(&mut buf).await {
Err(err) => {
warn!(sl(), "failed to read from eventfd: {:?}", err);
return;
}
Ok(_) => {
let content = fs::read_to_string(path.clone());
info!(
sl(),
"cgroup event for container: {}, path: {:?}, content: {:?}",
&containere_id,
&path,
content
);
if let Ok(times) = get_value_from_cgroup(&path, "oom_kill") {
if times < 1 {
// Do not send an OOM event in the case where no OOM has occurred
continue;
}
}
// Send an OOM event in two cases:
// 1. The value is not empty && times > 0: OOM kill has occurred.
// 2. The value is empty: Do what previous implemention did.
}
}

Expand Down