From 3b8884d646b3b73e4f88097f6899e2b27d8e61b4 Mon Sep 17 00:00:00 2001 From: yuanchao Date: Tue, 11 Feb 2025 18:53:50 +0800 Subject: [PATCH] fix: too many core files --- agent/crates/public/src/consts.rs | 2 + agent/src/collector/collector.rs | 50 +++++++++---------- agent/src/collector/l7_quadruple_generator.rs | 7 +-- agent/src/collector/mod.rs | 21 ++++++++ agent/src/collector/quadruple_generator.rs | 7 +-- agent/src/utils/environment/linux.rs | 8 +-- 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/agent/crates/public/src/consts.rs b/agent/crates/public/src/consts.rs index 1df52cf0bc4..96dc27cae93 100644 --- a/agent/crates/public/src/consts.rs +++ b/agent/crates/public/src/consts.rs @@ -18,6 +18,8 @@ use std::time::Duration; #[cfg(any(target_os = "linux", target_os = "android"))] pub const PROCESS_NAME: &str = "deepflow-agent"; +#[cfg(any(target_os = "linux", target_os = "android"))] +pub const PROCESS_NAME_SECONDARY: &str = "trident"; #[cfg(target_os = "windows")] pub const PROCESS_NAME: &str = "deepflow-agent.exe"; pub const DAEMONSET_NAME: &str = "deepflow-agent"; diff --git a/agent/src/collector/collector.rs b/agent/src/collector/collector.rs index 9c63f32c85e..c6bf5aca747 100644 --- a/agent/src/collector/collector.rs +++ b/agent/src/collector/collector.rs @@ -32,8 +32,9 @@ use log::{debug, info, warn}; use super::{ consts::{QUEUE_BATCH_SIZE, RCV_TIMEOUT}, + reset_delay_seconds, types::{AppMeterWithFlow, FlowMeterWithFlow, MiniFlow}, - MetricsType, FLOW_METRICS_PEER_DST, FLOW_METRICS_PEER_SRC, + MetricsType, FLOW_METRICS_PEER_DST, FLOW_METRICS_PEER_SRC, SECONDS_IN_MINUTE, }; use crate::{ common::{ @@ -58,8 +59,6 @@ use public::{ utils::net::MacAddr, }; -const MINUTE: u64 = 60; - #[derive(Default)] pub struct CollectorCounter { window_delay: AtomicI64, @@ -357,8 +356,9 @@ impl Stash { }; let start_time = Duration::from_secs( - get_timestamp(ctx.ntp_diff.load(Ordering::Relaxed)).as_secs() / MINUTE * MINUTE - - 2 * MINUTE, + get_timestamp(ctx.ntp_diff.load(Ordering::Relaxed)).as_secs() / SECONDS_IN_MINUTE + * SECONDS_IN_MINUTE + - 2 * SECONDS_IN_MINUTE, ); let inner = HashMap::with_capacity(Self::MIN_STASH_CAPACITY); let stash_init_capacity = inner.capacity(); @@ -396,7 +396,7 @@ impl Stash { if acc_flow.is_none() && time_in_second >= self.context.delay_seconds { match self.context.metric_type { MetricsType::SECOND => time_in_second -= self.context.delay_seconds, - _ => time_in_second -= self.context.delay_seconds - MINUTE, + _ => time_in_second -= self.context.delay_seconds - SECONDS_IN_MINUTE, } } @@ -646,7 +646,7 @@ impl Stash { if meter.is_none() && time_in_second >= self.context.delay_seconds { match self.context.metric_type { MetricsType::SECOND => time_in_second -= self.context.delay_seconds, - _ => time_in_second -= self.context.delay_seconds - MINUTE, + _ => time_in_second -= self.context.delay_seconds - SECONDS_IN_MINUTE, } } @@ -1196,6 +1196,20 @@ pub struct Collector { context: Context, } +fn metric_type_to_tag( + metric_type: MetricsType, + delay_seconds: u64, +) -> (&'static str, &'static str, u64) { + match metric_type { + MetricsType::MINUTE => ( + "minute", + "minute_collector", + reset_delay_seconds(delay_seconds), + ), + _ => ("second", "second_collector", delay_seconds), + } +} + impl Collector { pub fn new( id: u32, @@ -1208,16 +1222,7 @@ impl Collector { ntp_diff: Arc, agent_mode: RunningMode, ) -> Self { - let (kind, name) = match metric_type { - MetricsType::MINUTE => { - if delay_seconds < MINUTE || delay_seconds >= MINUTE * 2 { - panic!("delay_seconds必须在[60, 120)秒内"); - } - ("minute", "minute_collector") - } - _ => ("second", "second_collector"), - }; - + let (kind, name, delay_seconds) = metric_type_to_tag(metric_type, delay_seconds); let running = Arc::new(AtomicBool::new(false)); let counter = Arc::new(CollectorCounter { running: running.clone(), @@ -1349,16 +1354,7 @@ impl L7Collector { ntp_diff: Arc, agent_mode: RunningMode, ) -> Self { - let (kind, name) = match metric_type { - MetricsType::MINUTE => { - if delay_seconds < MINUTE || delay_seconds >= MINUTE * 2 { - panic!("delay_seconds必须在[60, 120)秒内"); - } - ("minute", "minute_collector") - } - _ => ("second", "second_collector"), - }; - + let (kind, name, delay_seconds) = metric_type_to_tag(metric_type, delay_seconds); let running = Arc::new(AtomicBool::new(false)); let counter = Arc::new(CollectorCounter { running: running.clone(), diff --git a/agent/src/collector/l7_quadruple_generator.rs b/agent/src/collector/l7_quadruple_generator.rs index 0376602b151..d0a346541d6 100644 --- a/agent/src/collector/l7_quadruple_generator.rs +++ b/agent/src/collector/l7_quadruple_generator.rs @@ -29,7 +29,7 @@ use thread::JoinHandle; use super::{ check_active, consts::*, - round_to_minute, + reset_delay_seconds, round_to_minute, types::{AppMeterWithFlow, MiniFlow}, MetricsType, QgStats, }; @@ -529,10 +529,7 @@ impl L7QuadrupleGenerator { ) -> Self { let collector_config = config.load(); info!("new l7 quadruple_generator id: {}, second_delay: {}, minute_delay: {}, l7_metrics_enabled: {}, vtap_flow_1s_enabled: {} collector_enabled: {}", id, second_delay_seconds, minute_delay_seconds, collector_config.l7_metrics_enabled, collector_config.vtap_flow_1s_enabled, collector_config.enabled); - if minute_delay_seconds < SECONDS_IN_MINUTE || minute_delay_seconds >= SECONDS_IN_MINUTE * 2 - { - panic!("minute_delay_seconds must be in [60, 120)s") - } + let minute_delay_seconds = reset_delay_seconds(minute_delay_seconds); let second_slots = second_delay_seconds as usize; let minute_slots = 2 as usize; diff --git a/agent/src/collector/mod.rs b/agent/src/collector/mod.rs index 8e1a95ee989..6ffb4cc9c68 100644 --- a/agent/src/collector/mod.rs +++ b/agent/src/collector/mod.rs @@ -28,6 +28,7 @@ use std::time::Duration; pub use collector::{Collector, L7Collector}; use bitflags::bitflags; +use log::info; use crate::{ common::endpoint::EPC_INTERNET, @@ -62,6 +63,26 @@ pub fn check_active( ) } +pub fn reset_delay_seconds(delay_seconds: u64) -> u64 { + if (SECONDS_IN_MINUTE..SECONDS_IN_MINUTE * 2).contains(&delay_seconds) { + delay_seconds + } else if delay_seconds < SECONDS_IN_MINUTE { + info!( + "delay_seconds {} < {}, reset delay_seconds to {}.", + delay_seconds, SECONDS_IN_MINUTE, SECONDS_IN_MINUTE + ); + SECONDS_IN_MINUTE + } else { + info!( + "delay_seconds {} >= {}, reset delay_seconds to {}.", + delay_seconds, + SECONDS_IN_MINUTE * 2, + SECONDS_IN_MINUTE * 2 - 1 + ); + SECONDS_IN_MINUTE * 2 - 1 + } +} + pub fn check_active_host( now: u64, possible_host: &mut Option, diff --git a/agent/src/collector/quadruple_generator.rs b/agent/src/collector/quadruple_generator.rs index 75e11a86a3d..b57aea2324c 100644 --- a/agent/src/collector/quadruple_generator.rs +++ b/agent/src/collector/quadruple_generator.rs @@ -30,7 +30,7 @@ use thread::JoinHandle; use super::{ check_active_host, consts::*, - round_to_minute, + reset_delay_seconds, round_to_minute, types::{FlowMeterWithFlow, MiniFlow}, MetricsType, QgStats, }; @@ -774,10 +774,7 @@ impl QuadrupleGenerator { ) -> Self { let conf = config.load(); info!("new quadruple_generator id: {}, second_delay: {}, minute_delay: {}, l7_metrics_enabled: {}, vtap_flow_1s_enabled: {} collector_enabled: {}", id, second_delay_seconds, minute_delay_seconds, conf.l7_metrics_enabled, conf.vtap_flow_1s_enabled, conf.enabled); - if minute_delay_seconds < SECONDS_IN_MINUTE || minute_delay_seconds >= SECONDS_IN_MINUTE * 2 - { - panic!("minute_delay_seconds须在[60, 120)秒内") - } + let minute_delay_seconds = reset_delay_seconds(minute_delay_seconds); let second_slots = second_delay_seconds as usize; let minute_slots = 2 as usize; diff --git a/agent/src/utils/environment/linux.rs b/agent/src/utils/environment/linux.rs index af8ef0b7482..7889354e02b 100644 --- a/agent/src/utils/environment/linux.rs +++ b/agent/src/utils/environment/linux.rs @@ -37,7 +37,7 @@ use public::utils::net::get_link_enabled_features; use super::{get_k8s_namespace, running_in_container, running_in_k8s}; use crate::{ - common::{CONTAINER_NAME, DAEMONSET_NAME, PROCESS_NAME}, + common::{CONTAINER_NAME, DAEMONSET_NAME, PROCESS_NAME, PROCESS_NAME_SECONDARY}, error::{Error, Result}, exception::ExceptionHandler, }; @@ -182,9 +182,9 @@ pub fn core_file_check() { } let elf_data = &mut elf_data[..n.unwrap()]; unsafe { - if String::from_utf8_unchecked(elf_data.to_vec()) - .find(PROCESS_NAME) - .is_none() + let context = String::from_utf8_unchecked(elf_data.to_vec()); + if context.find(PROCESS_NAME).is_none() + && context.find(PROCESS_NAME_SECONDARY).is_none() { continue; }