Skip to content

Commit 4ca8495

Browse files
[#182]: added VethEvent protobuf message. Added log to see the veth event in the agent api
1 parent 78aa079 commit 4ca8495

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

core/api/protos/agent.proto

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ message VethResponse{
7676
int32 tot_monitored_veth = 3;
7777
}
7878
message VethEvent{
79-
string event_id = 1;
80-
string name = 2; // Virtual Ethernet Interface Name
81-
uint64 state = 3; // Veth State
82-
string dev_addr = 4; // Veth device Address
83-
uint32 event_type = 5; // Event type
84-
uint32 netns = 6; // Network Namespace
85-
uint32 pid = 7; // Process ID
79+
string name = 1; // Virtual Ethernet Interface Name
80+
uint64 state = 2; // Veth State
81+
string dev_addr = 3; // Veth device Address
82+
uint32 event_type = 4; // Event type
83+
uint32 netns = 5; // Network Namespace
84+
uint32 pid = 6; // Process ID
8685
}
8786

8887
//declare agent api

core/api/src/agent.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,23 @@ pub struct VethResponse {
132132
}
133133
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
134134
pub struct VethEvent {
135-
#[prost(string, tag = "1")]
136-
pub event_id: ::prost::alloc::string::String,
137135
/// Virtual Ethernet Interface Name
138-
#[prost(string, tag = "2")]
136+
#[prost(string, tag = "1")]
139137
pub name: ::prost::alloc::string::String,
140138
/// Veth State
141-
#[prost(uint64, tag = "3")]
139+
#[prost(uint64, tag = "2")]
142140
pub state: u64,
143141
/// Veth device Address
144-
#[prost(string, tag = "4")]
142+
#[prost(string, tag = "3")]
145143
pub dev_addr: ::prost::alloc::string::String,
146144
/// Event type
147-
#[prost(uint32, tag = "5")]
145+
#[prost(uint32, tag = "4")]
148146
pub event_type: u32,
149147
/// Network Namespace
150-
#[prost(uint32, tag = "6")]
148+
#[prost(uint32, tag = "5")]
151149
pub netns: u32,
152150
/// Process ID
153-
#[prost(uint32, tag = "7")]
151+
#[prost(uint32, tag = "6")]
154152
pub pid: u32,
155153
}
156154
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]

core/api/src/api.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
#![allow(warnings)]
21
use anyhow::Context;
32
use chrono::Local;
43
use cortexbrain_common::formatters::{format_ipv4, format_ipv6};
54
use cortexbrain_common::map_handlers::load_perf_event_array_from_mapdata;
65
use prost::bytes::BytesMut;
6+
use std::str::FromStr;
77
use std::sync::Mutex;
8-
use std::{str::FromStr, sync::Arc};
98
use tonic::{Request, Response, Status};
109
use tracing::info;
1110

12-
use aya::{
13-
maps::{MapData, PerfEventArray},
14-
util::online_cpus,
15-
};
11+
use aya::{maps::MapData, util::online_cpus};
1612
use std::result::Result::Ok;
1713
use tonic::async_trait;
1814

@@ -39,7 +35,6 @@ use crate::constants::PIN_BLOCKLIST_MAP_PATH;
3935
use crate::helpers::comm_to_string;
4036
use aya::maps::Map;
4137
use cortexbrain_common::buffer_type::IpProtocols;
42-
use cortexbrain_common::constants::BPF_PATH;
4338
use std::net::Ipv4Addr;
4439
use tracing::warn;
4540

@@ -104,7 +99,6 @@ pub trait EventSender: Send + Sync + 'static {
10499
let event = Ok(map);
105100
let _ = tx.send(event).await;
106101
}
107-
108102
}
109103

110104
// send event function. takes an HashMap and send that using mpsc event_tx
@@ -155,7 +149,7 @@ impl Default for AgentApi {
155149
let (conn_tx, conn_rx) = mpsc::channel(1024);
156150
let (lat_tx, lat_rx) = mpsc::channel(2048);
157151
let (drop_tx, drop_rx) = mpsc::channel(2048);
158-
let (tracked_veth_tx, tracked_veth_rx) = mpsc::channel(1024);
152+
let (veth_tx, tracked_veth_rx) = mpsc::channel(1024);
159153

160154
let api = AgentApi {
161155
active_connection_event_rx: conn_rx.into(),
@@ -165,7 +159,7 @@ impl Default for AgentApi {
165159
dropped_packet_metrics_rx: Mutex::new(drop_rx),
166160
dropped_packet_metrics_tx: drop_tx.clone(),
167161
tracked_veth_rx: Mutex::new(tracked_veth_rx),
168-
tracked_veth_tx: tracked_veth_tx.clone(),
162+
tracked_veth_tx: veth_tx.clone(),
169163
};
170164

171165
// For network metrics
@@ -441,12 +435,12 @@ impl Default for AgentApi {
441435
//read the events, this function is similar to the one used in identity/helpers.rs/display_events
442436
if events.read > 0 {
443437
for i in 0..events.read {
438+
info!("Found veth events {}", events.read);
444439
let data = &buffers[i];
445440
if data.len() >= std::mem::size_of::<VethLog>() {
446441
let veth: VethLog =
447442
unsafe { std::ptr::read(data.as_ptr() as *const _) };
448443
let veth_event = VethEvent {
449-
event_id: todo!(),
450444
name: String::from_utf8_lossy(unsafe {
451445
std::slice::from_raw_parts(
452446
veth.name.as_ptr() as *const u8,
@@ -469,9 +463,18 @@ impl Default for AgentApi {
469463
netns: veth.netns,
470464
pid: veth.pid,
471465
};
466+
info!(
467+
"Veth Event - name: {}, state: {}, dev_addr: {}, event_type: {}, netns: {}, pid: {}",
468+
veth_event.name,
469+
veth_event.state,
470+
veth_event.dev_addr,
471+
veth_event.event_type,
472+
veth_event.netns,
473+
veth_event.pid
474+
);
472475
let mut evt = Vec::new();
473476
evt.push(veth_event.clone());
474-
let _ = tracked_veth_tx.send(Ok(evt)).await;
477+
let _ = veth_tx.send(Ok(evt)).await;
475478
} else {
476479
warn!(
477480
"Received time stamp metrics data too small: {} bytes",

0 commit comments

Comments
 (0)