-
Notifications
You must be signed in to change notification settings - Fork 425
feat(agent): add basic macOS platform support #11449
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
Open
zy84338719
wants to merge
1
commit into
deepflowio:main
Choose a base branch
from
zy84338719:feat/macos-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| 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()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Querierimportsget_hostname/get_ip_addressfromcrate::utils::command, butagent/src/utils/command/mod.rsonly exports implementations forlinux|androidandwindows(nomacosmodule). As-is, macOS builds will fail with unresolved imports. Add a macOS implementation (e.g.,command/macos.rs) and update thecfggates incommand/mod.rsto includetarget_os = "macos"(and implementget_ip_addressusingifconfig/system APIs).