Skip to content

Commit 2c8b908

Browse files
yuanchaoarvql
authored andcommitted
refactor: Configuration item adjusted to hot update
1 parent 84032d6 commit 2c8b908

9 files changed

Lines changed: 127 additions & 143 deletions

File tree

agent/src/config/config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,7 @@ pub struct CircuitBreakers {
25122512
#[serde(default)]
25132513
pub struct Tunning {
25142514
pub cpu_affinity: Vec<usize>,
2515-
pub process_scheduling_priority: usize,
2515+
pub process_scheduling_priority: isize,
25162516
pub idle_memory_trimming: bool,
25172517
pub swap_disabled: bool,
25182518
pub page_cache_reclaim_percentage: u8,
@@ -2647,14 +2647,12 @@ pub struct Profile {
26472647
pub struct Debug {
26482648
pub enabled: bool,
26492649
pub local_udp_port: u16,
2650-
pub debug_metrics_enabled: bool,
26512650
}
26522651

26532652
impl Default for Debug {
26542653
fn default() -> Self {
26552654
Self {
26562655
local_udp_port: 0,
2657-
debug_metrics_enabled: false,
26582656
enabled: true,
26592657
}
26602658
}

agent/src/config/handler.rs

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub struct EnvironmentConfig {
234234
pub free_disk_circuit_breaker_percentage_threshold: u8,
235235
pub free_disk_circuit_breaker_absolute_threshold: u64,
236236
pub free_disk_circuit_breaker_directories: Vec<String>,
237+
pub idle_memory_trimming: bool,
237238
}
238239

239240
#[derive(Clone, PartialEq, Eq, Debug)]
@@ -302,8 +303,6 @@ pub struct OsProcScanConfig {
302303
// whether to sync os socket and proc info
303304
// only make sense when process_info_enabled() == true
304305
pub os_proc_sync_enabled: bool,
305-
// sync os socket and proc info only when the process has been tagged.
306-
pub os_proc_sync_tagged_only: bool,
307306
}
308307
#[cfg(target_os = "windows")]
309308
#[derive(Clone, PartialEq, Eq, Debug)]
@@ -1761,6 +1760,7 @@ impl TryFrom<(Config, UserConfig)> for ModuleConfig {
17611760
v.dedup();
17621761
v
17631762
},
1763+
idle_memory_trimming: conf.global.tunning.idle_memory_trimming,
17641764
},
17651765
synchronizer: SynchronizerConfig {
17661766
sync_interval: conf.global.communication.proactive_request_interval,
@@ -1986,19 +1986,6 @@ impl TryFrom<(Config, UserConfig)> for ModuleConfig {
19861986
os_app_tag_exec_user: conf.inputs.proc.tag_extraction.exec_username.clone(),
19871987
os_app_tag_exec: conf.inputs.proc.tag_extraction.script_command.clone(),
19881988
os_proc_sync_enabled: conf.inputs.proc.enabled,
1989-
os_proc_sync_tagged_only: conf
1990-
.inputs
1991-
.proc
1992-
.process_matcher
1993-
.iter()
1994-
.find(|m| {
1995-
m.enabled_features
1996-
.iter()
1997-
.find(|s| s.as_str() == "proc.gprocess_info")
1998-
.is_some()
1999-
&& m.only_with_tag
2000-
})
2001-
.is_some(),
20021989
},
20031990
#[cfg(target_os = "windows")]
20041991
os_proc_scan_conf: OsProcScanConfig {},
@@ -2418,7 +2405,7 @@ impl ConfigHandler {
24182405
}
24192406

24202407
#[cfg(any(target_os = "linux", target_os = "android"))]
2421-
fn set_process_scheduling_priority(process_scheduling_priority: usize) {
2408+
fn set_process_scheduling_priority(process_scheduling_priority: isize) {
24222409
let pid = std::process::id();
24232410
unsafe {
24242411
if libc::setpriority(
@@ -2613,7 +2600,7 @@ impl ConfigHandler {
26132600
}
26142601
}
26152602

2616-
fn set_log_retention(
2603+
fn set_log_retention_and_path(
26172604
logger_handle: &mut Option<LoggerHandle>,
26182605
log_retention: &Duration,
26192606
log_file: &String,
@@ -2789,13 +2776,6 @@ impl ConfigHandler {
27892776
let mut restart_agent = false;
27902777
#[cfg(target_os = "windows")]
27912778
let capture_mode = new_config.user_config.inputs.cbpf.common.capture_mode;
2792-
let log_file = new_config
2793-
.user_config
2794-
.global
2795-
.self_monitoring
2796-
.log
2797-
.log_file
2798-
.clone();
27992779
let logger_handle = &mut self.logger_handle;
28002780
#[cfg(any(target_os = "linux", target_os = "android"))]
28012781
let mut cpu_set = CpuSet::new();
@@ -3729,7 +3709,6 @@ impl ConfigHandler {
37293709
proc.min_lifetime, new_proc.min_lifetime
37303710
);
37313711
proc.min_lifetime = new_proc.min_lifetime;
3732-
restart_agent = !first_run;
37333712
}
37343713
let mut process_matcher_update = false;
37353714
if proc.proc_dir_path != new_proc.proc_dir_path {
@@ -3739,7 +3718,6 @@ impl ConfigHandler {
37393718
);
37403719
proc.proc_dir_path = new_proc.proc_dir_path.clone();
37413720
process_matcher_update = true;
3742-
restart_agent = !first_run;
37433721
}
37443722
if proc.process_blacklist != new_proc.process_blacklist {
37453723
info!(
@@ -3748,7 +3726,6 @@ impl ConfigHandler {
37483726
);
37493727
proc.process_blacklist = new_proc.process_blacklist.clone();
37503728
process_matcher_update = true;
3751-
restart_agent = !first_run;
37523729
}
37533730
if proc.process_matcher != new_proc.process_matcher {
37543731
info!(
@@ -3757,7 +3734,6 @@ impl ConfigHandler {
37573734
);
37583735
proc.process_matcher = new_proc.process_matcher.clone();
37593736
process_matcher_update = true;
3760-
restart_agent = !first_run;
37613737
}
37623738
if proc.symbol_table != new_proc.symbol_table {
37633739
info!(
@@ -3773,7 +3749,6 @@ impl ConfigHandler {
37733749
proc.socket_info_sync_interval, new_proc.socket_info_sync_interval
37743750
);
37753751
proc.socket_info_sync_interval = new_proc.socket_info_sync_interval;
3776-
restart_agent = !first_run;
37773752
}
37783753

37793754
let tag = &mut proc.tag_extraction;
@@ -3785,7 +3760,6 @@ impl ConfigHandler {
37853760
);
37863761
tag.exec_username = new_tag.exec_username.clone();
37873762
process_matcher_update = true;
3788-
restart_agent = !first_run;
37893763
}
37903764
if tag.script_command != new_tag.script_command {
37913765
info!(
@@ -3794,7 +3768,6 @@ impl ConfigHandler {
37943768
);
37953769
tag.script_command = new_tag.script_command.clone();
37963770
process_matcher_update = true;
3797-
restart_agent = !first_run;
37983771
}
37993772

38003773
if process_matcher_update {
@@ -4103,16 +4076,13 @@ impl ConfigHandler {
41034076

41044077
let limits = &mut config.global.limits;
41054078
let new_limits = &mut new_config.user_config.global.limits;
4079+
let mut update_log_retention_and_path = false;
41064080
if limits.local_log_retention != new_limits.local_log_retention {
41074081
info!(
41084082
"Update global.limits.local_log_retention from {:?} to {:?}.",
41094083
limits.local_log_retention, new_limits.local_log_retention
41104084
);
4111-
if Self::set_log_retention(logger_handle, &new_limits.local_log_retention, &log_file) {
4112-
limits.local_log_retention = new_limits.local_log_retention;
4113-
} else {
4114-
new_limits.local_log_retention = limits.local_log_retention;
4115-
}
4085+
update_log_retention_and_path = true;
41164086
}
41174087
if limits.max_local_log_file_size != new_limits.max_local_log_file_size {
41184088
info!(
@@ -4222,14 +4192,6 @@ impl ConfigHandler {
42224192
);
42234193
debug.enabled = debug.enabled;
42244194
}
4225-
if debug.debug_metrics_enabled != new_debug.debug_metrics_enabled {
4226-
info!(
4227-
"Update global.self_monitoring.debug.debug_metrics_enabled from {:?} to {:?}.",
4228-
debug.debug_metrics_enabled, new_debug.debug_metrics_enabled
4229-
);
4230-
debug.debug_metrics_enabled = debug.debug_metrics_enabled;
4231-
restart_agent = !first_run;
4232-
}
42334195
if debug.local_udp_port != new_debug.local_udp_port {
42344196
info!(
42354197
"Update global.self_monitoring.debug.local_udp_port from {:?} to {:?}.",
@@ -4276,8 +4238,7 @@ impl ConfigHandler {
42764238
"Update global.self_monitoring.log.log_file from {:?} to {:?}.",
42774239
log.log_file, new_log.log_file
42784240
);
4279-
log.log_file = new_log.log_file.clone();
4280-
restart_agent = !first_run;
4241+
update_log_retention_and_path = true;
42814242
}
42824243
if log.log_level != new_log.log_level {
42834244
info!(
@@ -4326,7 +4287,6 @@ impl ConfigHandler {
43264287
tunning.idle_memory_trimming, new_tunning.idle_memory_trimming
43274288
);
43284289
tunning.idle_memory_trimming = new_tunning.idle_memory_trimming;
4329-
restart_agent = !first_run;
43304290
}
43314291
if tunning.swap_disabled != new_tunning.swap_disabled {
43324292
info!(
@@ -4362,15 +4322,13 @@ impl ConfigHandler {
43624322
tunning.process_scheduling_priority = new_tunning.process_scheduling_priority;
43634323
#[cfg(any(target_os = "linux", target_os = "android"))]
43644324
Self::set_process_scheduling_priority(tunning.process_scheduling_priority);
4365-
restart_agent = !first_run;
43664325
}
43674326
if tunning.resource_monitoring_interval != new_tunning.resource_monitoring_interval {
43684327
info!(
43694328
"Update global.tunning.resource_monitoring_interval from {:?} to {:?}.",
43704329
tunning.resource_monitoring_interval, new_tunning.resource_monitoring_interval
43714330
);
43724331
tunning.resource_monitoring_interval = new_tunning.resource_monitoring_interval;
4373-
restart_agent = !first_run;
43744332
}
43754333
if tunning.page_cache_reclaim_percentage != new_tunning.page_cache_reclaim_percentage {
43764334
info!(
@@ -4380,6 +4338,19 @@ impl ConfigHandler {
43804338
tunning.page_cache_reclaim_percentage = new_tunning.page_cache_reclaim_percentage;
43814339
}
43824340

4341+
if update_log_retention_and_path {
4342+
let new_retention = &new_config.user_config.global.limits.local_log_retention;
4343+
let new_log_file = &new_config.user_config.global.self_monitoring.log.log_file;
4344+
if Self::set_log_retention_and_path(logger_handle, new_retention, new_log_file) {
4345+
config.global.limits.local_log_retention = *new_retention;
4346+
config.global.self_monitoring.log.log_file = new_log_file.clone();
4347+
} else {
4348+
new_config.user_config.global.limits.local_log_retention =
4349+
config.global.limits.local_log_retention;
4350+
new_config.user_config.global.self_monitoring.log.log_file =
4351+
config.global.self_monitoring.log.log_file.clone();
4352+
}
4353+
}
43834354
// dev
43844355
let dev = &mut config.dev;
43854356
let new_dev = &mut new_config.user_config.dev;
@@ -4850,31 +4821,27 @@ impl ConfigHandler {
48504821
timeouts.closing_rst, new_timeouts.closing_rst
48514822
);
48524823
timeouts.closing_rst = new_timeouts.closing_rst;
4853-
restart_agent = !first_run;
48544824
}
48554825
if timeouts.established != new_timeouts.established {
48564826
info!(
48574827
"Update processors.flow_log.conntrack.timeouts.established from {:?} to {:?}.",
48584828
timeouts.established, new_timeouts.established
48594829
);
48604830
timeouts.established = new_timeouts.established;
4861-
restart_agent = !first_run;
48624831
}
48634832
if timeouts.opening_rst != new_timeouts.opening_rst {
48644833
info!(
48654834
"Update processors.flow_log.conntrack.timeouts.opening_rst from {:?} to {:?}.",
48664835
timeouts.opening_rst, new_timeouts.opening_rst
48674836
);
48684837
timeouts.opening_rst = new_timeouts.opening_rst;
4869-
restart_agent = !first_run;
48704838
}
48714839
if timeouts.others != new_timeouts.others {
48724840
info!(
48734841
"Update processors.flow_log.conntrack.timeouts.others from {:?} to {:?}.",
48744842
timeouts.others, new_timeouts.others
48754843
);
48764844
timeouts.others = new_timeouts.others;
4877-
restart_agent = !first_run;
48784845
}
48794846

48804847
let time_window = &mut flow_log.time_window;

agent/src/platform/platform_synchronizer/linux_socket.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ mod tests {
500500
os_app_tag_exec_user: "".to_string(),
501501
os_app_tag_exec: vec![],
502502
os_proc_sync_enabled: true,
503-
os_proc_sync_tagged_only: false,
504503
};
505504
let (_, mut getter) = Policy::new(1, 0, 1 << 10, 1 << 14, false, false);
506505
let pids = procfs::process::all_processes()

agent/src/trident.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,12 +840,6 @@ impl Trident {
840840
exception_handler.clone(),
841841
cgroup_mount_path,
842842
is_cgroup_v2,
843-
config_handler
844-
.candidate_config
845-
.user_config
846-
.global
847-
.tunning
848-
.idle_memory_trimming,
849843
cgroups_disabled,
850844
) {
851845
Ok(g) => g,

agent/src/utils/guard.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ pub struct Guard {
262262
exception_handler: ExceptionHandler,
263263
cgroup_mount_path: String,
264264
is_cgroup_v2: bool,
265-
memory_trim_disabled: bool,
266265
system: Arc<Mutex<System>>,
267266
pid: Pid,
268267
cgroups_disabled: bool,
@@ -276,7 +275,6 @@ impl Guard {
276275
exception_handler: ExceptionHandler,
277276
cgroup_mount_path: String,
278277
is_cgroup_v2: bool,
279-
memory_trim_enabled: bool,
280278
cgroups_disabled: bool,
281279
) -> Result<Self, &'static str> {
282280
let Ok(pid) = get_current_pid() else {
@@ -293,7 +291,6 @@ impl Guard {
293291
exception_handler,
294292
cgroup_mount_path,
295293
is_cgroup_v2,
296-
memory_trim_disabled: !memory_trim_enabled,
297294
system: Arc::new(Mutex::new(System::new())),
298295
pid,
299296
cgroups_disabled,
@@ -533,8 +530,6 @@ impl Guard {
533530
let mut under_sys_free_memory_limit = false; // Below the limit, it does not meet expectations
534531
let cgroup_mount_path = self.cgroup_mount_path.clone();
535532
let is_cgroup_v2 = self.is_cgroup_v2;
536-
#[cfg(all(target_os = "linux", target_env = "gnu"))]
537-
let memory_trim_disabled = self.memory_trim_disabled;
538533
let mut check_cgroup_result = true; // It is used to determine whether subsequent checks are required. If the first check fails, the check is stopped
539534
let system = self.system.clone();
540535
let pid: Pid = self.pid.clone();
@@ -635,7 +630,7 @@ impl Guard {
635630
}
636631

637632
#[cfg(all(target_os = "linux", target_env = "gnu"))]
638-
if !memory_trim_disabled {
633+
if config.idle_memory_trimming {
639634
feed.add(FeedTitle::MallocTrim);
640635
unsafe { let _ = malloc_trim(0); }
641636
}

0 commit comments

Comments
 (0)