Skip to content
Open
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
11 changes: 11 additions & 0 deletions agent/crates/public/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub const PROCESS_NAME: &str = "deepflow-agent";
pub const PROCESS_NAME_SECONDARY: &str = "trident";
#[cfg(target_os = "windows")]
pub const PROCESS_NAME: &str = "deepflow-agent.exe";
#[cfg(target_os = "macos")]
pub const PROCESS_NAME: &str = "deepflow-agent";
pub const DAEMONSET_NAME: &str = "deepflow-agent";
pub const CONTAINER_NAME: &str = "deepflow-agent";

Expand Down Expand Up @@ -79,6 +81,15 @@ mod platform_consts {
pub const COREFILE_FORMAT: &'static str = "dump";
}

#[cfg(target_os = "macos")]
mod platform_consts {
pub const DEFAULT_LOG_FILE: &'static str = "/var/log/deepflow-agent/deepflow-agent.log";
pub const DEFAULT_CONF_FILE: &'static str = "/etc/deepflow-agent.yaml";
pub const DEFAULT_TRIDENT_CONF_FILE: &'static str = "/etc/trident.yaml";
pub const COREFILE_FORMAT: &'static str = "core";
pub const DEFAULT_COREFILE_PATH: &'static str = "/tmp";
}

pub use platform_consts::*;

pub const FIELD_OFFSET_DA: usize = 0;
Expand Down
2 changes: 1 addition & 1 deletion agent/src/dispatcher/recv_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Default for RecvEngine {
}
}

#[cfg(target_os = "windows")]
#[cfg(any(target_os = "windows", target_os = "macos"))]
impl Default for RecvEngine {
fn default() -> Self {
Self::Libpcap(None)
Expand Down
2 changes: 2 additions & 0 deletions agent/src/platform/platform_synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ cfg_if::cfg_if! {
pub use linux_process::{ProcessData, ProcessDataOp, get_os_app_tag_by_exec, OsAppTag};
} else if #[cfg(target_os = "windows")] {
pub struct ProcessData {}
} else if #[cfg(target_os = "macos")] {
pub struct ProcessData {}
}
}

Expand Down
3 changes: 3 additions & 0 deletions agent/src/platform/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ cfg_if::cfg_if! {
} else if #[cfg(target_os = "windows")] {
mod windows;
pub use windows::Querier;
} else if #[cfg(target_os = "macos")] {
mod macos;
pub use macos::Querier;
}
}
115 changes: 115 additions & 0 deletions agent/src/platform/querier/macos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2024 Yunshan Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use std::hash::Hasher;

use ahash::AHasher;
use log::{debug, trace};

use crate::{
config::handler::PlatformConfig,
utils::command::{get_hostname, get_ip_address},
};

use public::proto::agent as pb;

Comment on lines +21 to +28
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Querier imports get_hostname/get_ip_address from crate::utils::command, but agent/src/utils/command/mod.rs only exports implementations for linux|android and windows (no macos module). As-is, macOS builds will fail with unresolved imports. Add a macOS implementation (e.g., command/macos.rs) and update the cfg gates in command/mod.rs to include target_os = "macos" (and implement get_ip_address using ifconfig/system APIs).

Suggested change
use crate::{
config::handler::PlatformConfig,
utils::command::{get_hostname, get_ip_address},
};
use public::proto::agent as pb;
use std::process::Command;
use crate::config::handler::PlatformConfig;
use public::proto::agent as pb;
fn get_hostname() -> std::io::Result<String> {
let output = Command::new("hostname").output()?;
let hostname = String::from_utf8_lossy(&output.stdout).trim().to_string();
Ok(hostname)
}
fn get_ip_address() -> std::io::Result<String> {
let output = Command::new("ifconfig").arg("-a").output()?;
let ip_info = String::from_utf8_lossy(&output.stdout).to_string();
Ok(ip_info)
}

Copilot uses AI. Check for mistakes.
pub struct Querier {
override_os_hostname: Option<String>,

digest: u64,

raw_hostname: Option<String>,
raw_ip_addr: String,
}

impl Querier {
pub fn new(override_os_hostname: Option<String>) -> Self {
Self {
override_os_hostname,

digest: Default::default(),

raw_hostname: Default::default(),
raw_ip_addr: Default::default(),
}
}

pub fn digest(&self) -> u64 {
self.digest
}

// returns digest
pub fn update(&mut self, _: &PlatformConfig) -> u64 {
let mut hasher = AHasher::default();

self.update_raw_hostname(&mut hasher);
self.update_raw_ip_addr(&mut hasher);

self.digest = hasher.finish();
self.digest()
}

pub fn generate_message(&self, config: &PlatformConfig) -> pb::GenesisSyncRequest {
let platform_data = pb::GenesisPlatformData {
platform_enabled: Some(config.enabled),
raw_hostname: self.raw_hostname.clone(),
raw_ip_netns: vec!["default".into()],
raw_ip_addrs: vec![self.raw_ip_addr.clone()],
..Default::default()
};

pb::GenesisSyncRequest {
platform_data: Some(platform_data),
..Default::default()
}
}

fn update_raw_hostname(&mut self, hasher: &mut AHasher) {
if let Some(hostname) = self.override_os_hostname.as_ref() {
if self.raw_hostname.is_none() {
self.raw_hostname = Some(hostname.clone());
}
return;
}
match get_hostname() {
Ok(hostname) => {
debug!("get_hostname() = {}", hostname);
hasher.write(hostname.as_bytes());
trace!("digest={:016x}", hasher.finish());
self.raw_hostname = Some(hostname);
}
Err(e) => debug!("get_hostname failed: {}", e),
}
}

fn update_raw_ip_addr(&mut self, hasher: &mut AHasher) {
let raw_host_ip_addr = get_ip_address()
.map_err(|err| debug!("get_ip_address error:{}", err))
.ok();
if let Some(ip_addr) = raw_host_ip_addr.as_ref() {
for line in ip_addr.lines() {
// 忽略可能变化的行避免version频繁更新
if line.contains("valid_lft") {
continue;
}
hasher.write(line.as_bytes());
}
}
self.raw_ip_addr = raw_host_ip_addr.unwrap_or_default();
debug!("updated ip addresses");
trace!("digest={:016x}", hasher.finish());
}
}
Loading