Skip to content

Commit

Permalink
[AGENT] Use AgentId in plugin load
Browse files Browse the repository at this point in the history
  • Loading branch information
rvql authored and sharang committed Aug 17, 2023
1 parent 5175b7d commit aab7b98
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
19 changes: 6 additions & 13 deletions agent/src/config/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use public::{
netns::{self, NsFile},
};

use crate::utils::cgroups::is_kernel_available_for_cgroups;
use crate::{trident::AgentId, utils::cgroups::is_kernel_available_for_cgroups};
#[cfg(target_os = "windows")]
use public::utils::net::links_by_name_regex;
use public::utils::net::MacAddr;
Expand Down Expand Up @@ -2239,15 +2239,9 @@ impl ConfigHandler {
callbacks
}

pub fn load_plugin(
&mut self,
rt: &Arc<Runtime>,
session: &Arc<Session>,
ctrl_ip: &str,
ctrl_mac: &str,
) {
pub fn load_plugin(&mut self, rt: &Arc<Runtime>, session: &Arc<Session>, agent_id: &AgentId) {
self.candidate_config
.fill_plugin_prog_from_server(rt, session, ctrl_ip, ctrl_mac);
.fill_plugin_prog_from_server(rt, session, agent_id);
self.current_config
.store(Arc::new(self.candidate_config.clone()));
}
Expand All @@ -2274,8 +2268,7 @@ impl ModuleConfig {
&mut self,
rt: &Arc<Runtime>,
session: &Arc<Session>,
ctrl_ip: &str,
ctrl_mac: &str,
agent_id: &AgentId,
) {
let mut wasm = vec![];
#[cfg(target_os = "windows")]
Expand All @@ -2285,7 +2278,7 @@ impl ModuleConfig {
rt.block_on(async {
for i in self.yaml_config.wasm_plugins.iter() {
match session
.get_plugin(i.as_str(), trident::PluginType::Wasm, ctrl_ip, ctrl_mac)
.get_plugin(i.as_str(), trident::PluginType::Wasm, agent_id)
.await
{
Ok(prog) => wasm.push((i.clone(), prog)),
Expand All @@ -2301,7 +2294,7 @@ impl ModuleConfig {
rt.block_on(async {
for i in self.yaml_config.so_plugins.iter() {
match session
.get_plugin(i.as_str(), trident::PluginType::So, ctrl_ip, ctrl_mac)
.get_plugin(i.as_str(), trident::PluginType::So, agent_id)
.await
{
Ok(prog) => match load_plugin(prog.as_slice(), i) {
Expand Down
4 changes: 2 additions & 2 deletions agent/src/flow_generator/flow_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ impl FlowMap {
let (l7_perf_stats, l7_protocol) =
perf.copy_and_reset_l7_perf_data(l7_timeout_count as u32);

let mut flow_perf_stats = flow.flow_perf_stats.as_mut().unwrap();
let flow_perf_stats = flow.flow_perf_stats.as_mut().unwrap();
flow_perf_stats.l7.sequential_merge(&l7_perf_stats);
flow_perf_stats.l7_protocol = l7_protocol;
l7_stats.stats = l7_perf_stats;
Expand Down Expand Up @@ -1726,7 +1726,7 @@ impl FlowMap {
let (l7_perf_stats, l7_protocol) =
perf.copy_and_reset_l7_perf_data(l7_timeout_count as u32);

let mut flow_perf_stats = flow.flow_perf_stats.as_mut().unwrap();
let flow_perf_stats = flow.flow_perf_stats.as_mut().unwrap();
flow_perf_stats.l7.sequential_merge(&l7_perf_stats);
flow_perf_stats.l7_protocol = l7_protocol;
if flow.flow_key.proto == IpProtocol::Tcp
Expand Down
16 changes: 9 additions & 7 deletions agent/src/rpc/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ use log::{debug, error, info};
use parking_lot::RwLock;
use tonic::transport::{Channel, Endpoint};

use crate::common::{DEFAULT_CONTROLLER_PORT, DEFAULT_CONTROLLER_TLS_PORT};
use crate::exception::ExceptionHandler;
use crate::utils::stats::{self, AtomicTimeStats, StatsOption};
use crate::{
common::{DEFAULT_CONTROLLER_PORT, DEFAULT_CONTROLLER_TLS_PORT},
exception::ExceptionHandler,
trident::AgentId,
utils::stats::{self, AtomicTimeStats, StatsOption},
};
use public::proto::trident::{self, Exception, Status};
use public::{
counter::{Countable, Counter, CounterType, CounterValue, RefCountable},
Expand Down Expand Up @@ -443,13 +446,12 @@ impl Session {
&self,
name: &str,
plugin_type: PluginType,
ctrl_ip: &str,
ctrl_mac: &str,
agent_id: &AgentId,
) -> Result<Vec<u8>> {
let s = self
.plugin(trident::PluginRequest {
ctrl_ip: Some(ctrl_ip.into()),
ctrl_mac: Some(ctrl_mac.into()),
ctrl_ip: Some(agent_id.ip.to_string()),
ctrl_mac: Some(agent_id.mac.to_string()),
plugin_type: Some(plugin_type as i32),
plugin_name: Some(name.into()),
})
Expand Down
8 changes: 2 additions & 6 deletions agent/src/trident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,12 +704,8 @@ impl Trident {
api_watcher.stop();
}

config_handler.load_plugin(
&runtime,
&session,
ctrl_ip.to_string().as_str(),
ctrl_mac.to_string().as_str(),
);
let agent_id = synchronizer.agent_id.read().clone();
config_handler.load_plugin(&runtime, &session, &agent_id);

let mut comp = Components::new(
&version_info,
Expand Down

0 comments on commit aab7b98

Please sign in to comment.