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

feat: Enable agent after first guard check #8751

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 15 additions & 36 deletions agent/src/rpc/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub struct Synchronizer {
pub agent_id: Arc<RwLock<AgentId>>,
pub status: Arc<RwLock<Status>>,

agent_state: AgentState,
agent_state: Arc<AgentState>,

session: Arc<Session>,
// 策略模块和NPB带宽检测会用到
Expand All @@ -515,7 +515,7 @@ impl Synchronizer {
pub fn new(
runtime: Arc<Runtime>,
session: Arc<Session>,
agent_state: AgentState,
agent_state: Arc<AgentState>,
version_info: &'static VersionInfo,
agent_id: AgentId,
controller_ip: String,
Expand Down Expand Up @@ -877,23 +877,13 @@ impl Synchronizer {
status_guard.first = false;
drop(status_guard);

let (agent_state, cvar) = &**agent_state;
if !user_config.global.common.enabled
|| exception_handler.has(Exception::SystemLoadCircuitBreaker)
|| exception_handler.has(Exception::FreeMemExceeded)
{
*agent_state.lock().unwrap() =
trident::State::Disabled(Some((user_config, resp.dynamic_config.unwrap())));
} else {
*agent_state.lock().unwrap() = trident::State::ConfigChanged(ChangedConfig {
user_config,
blacklist,
vm_mac_addrs: macs,
gateway_vmac_addrs,
tap_types: resp.capture_network_types,
});
}
cvar.notify_one();
agent_state.update_config(ChangedConfig {
user_config,
blacklist,
vm_mac_addrs: macs,
gateway_vmac_addrs,
tap_types: resp.capture_network_types,
});
}

fn grpc_failed_log(grpc_failed_count: &mut usize, detail: String) {
Expand Down Expand Up @@ -1031,9 +1021,7 @@ impl Synchronizer {
// channel closed
Ok(None) => return,
Err(_) => {
let (ts, cvar) = &*agent_state;
*ts.lock().unwrap() = trident::State::Disabled(None);
cvar.notify_one();
agent_state.disable();
warn!("as max escape time expired, deepflow-agent restart...");
// 与控制器失联的时间超过设置的逃逸时间,这里直接重启主要有两个原因:
// 1. 如果仅是停用系统无法回收全部的内存资源
Expand Down Expand Up @@ -1437,17 +1425,10 @@ impl Synchronizer {

max_memory.store(user_config.global.limits.max_memory, Ordering::Relaxed);
let new_sync_interval = user_config.global.communication.proactive_request_interval;
let (agent_state, cvar) = &*agent_state;
if !user_config.global.common.enabled {
*agent_state.lock().unwrap() =
trident::State::Disabled(Some((user_config, dynamic_config)));
} else {
*agent_state.lock().unwrap() = trident::State::ConfigChanged(ChangedConfig {
user_config,
..Default::default()
});
}
cvar.notify_one();
agent_state.update_config(ChangedConfig {
user_config,
..Default::default()
});

if sync_interval != new_sync_interval {
sync_interval = new_sync_interval;
Expand Down Expand Up @@ -1569,9 +1550,7 @@ impl Synchronizer {
} else {
match Self::upgrade(&running, &session, &revision, &id).await {
Ok(_) => {
let (ts, cvar) = &*agent_state;
*ts.lock().unwrap() = trident::State::Terminated;
cvar.notify_one();
agent_state.terminate();
warn!("agent upgrade is successful and restarts normally, deepflow-agent restart...");
crate::utils::notify_exit(NORMAL_EXIT_WITH_RESTART);
return;
Expand Down
Loading
Loading