Skip to content

Commit

Permalink
fix: too many core files
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchaoa authored and rvql committed Feb 12, 2025
1 parent 6178494 commit 3b8884d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 41 deletions.
2 changes: 2 additions & 0 deletions agent/crates/public/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
50 changes: 23 additions & 27 deletions agent/src/collector/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -58,8 +59,6 @@ use public::{
utils::net::MacAddr,
};

const MINUTE: u64 = 60;

#[derive(Default)]
pub struct CollectorCounter {
window_delay: AtomicI64,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
Expand All @@ -1208,16 +1222,7 @@ impl Collector {
ntp_diff: Arc<AtomicI64>,
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(),
Expand Down Expand Up @@ -1349,16 +1354,7 @@ impl L7Collector {
ntp_diff: Arc<AtomicI64>,
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(),
Expand Down
7 changes: 2 additions & 5 deletions agent/src/collector/l7_quadruple_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions agent/src/collector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<PossibleHost>,
Expand Down
7 changes: 2 additions & 5 deletions agent/src/collector/quadruple_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions agent/src/utils/environment/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3b8884d

Please sign in to comment.