Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
301be35
[#158]: moved map_handlers module from identity crate to common crate
LorenzoTettamanti Jan 16, 2026
1385bcf
[#158]: simplified identity logic. removed duplicated code and functions
LorenzoTettamanti Jan 16, 2026
b9edd1d
[#158]: added program handlers function in the common crate. Remove d…
LorenzoTettamanti Jan 22, 2026
d3a5342
[#168]: added load from program-handlers in identity user space imple…
LorenzoTettamanti Jan 22, 2026
b8449a3
[#158]: fixed typos in the map names
LorenzoTettamanti Jan 23, 2026
52cab4c
[#158]: fixed bpf error: Error: the program is already loaded.Improve…
LorenzoTettamanti Jan 23, 2026
2bd44b6
[#174]: added open telemetry (otel) logger for logs. Added otel daemo…
LorenzoTettamanti Jan 25, 2026
cd4687f
[#158]: improved docs for the conntracker data structures. removed us…
LorenzoTettamanti Jan 25, 2026
b21a58a
[#174]: Added otel libraries and features in the common crate. .updat…
LorenzoTettamanti Jan 25, 2026
69863bb
[#158]: imroved documentation in the user space for the identity (Vet…
LorenzoTettamanti Jan 25, 2026
af85614
[#158]: restored blocklist map initialization
LorenzoTettamanti Jan 26, 2026
1cbd9f5
[#158]: added better docs. Updated while true pattern with "loop" pat…
LorenzoTettamanti Jan 27, 2026
440d44d
[#174]: added prettify to logger
LorenzoTettamanti Jan 27, 2026
84c4efa
[fix]: solved merge conflicts
LorenzoTettamanti Jan 27, 2026
c0afdf4
[#181]: added command to repair blocklist configmaps
LorenzoTettamanti Jan 27, 2026
c3e47b1
[#182]: added GetTrackedVeth grpc endpoint definition
LorenzoTettamanti Jan 30, 2026
8d6541b
[#158]: added load_perf_event_array_from_mapdata function in map_hand…
LorenzoTettamanti Jan 31, 2026
1804aab
[#182]: added total monitored veth_events (tot_monitored_veth)
LorenzoTettamanti Jan 31, 2026
8bfa366
[#182]: added "cfcli monitoring veth" command frontend. added send_tr…
LorenzoTettamanti Jan 31, 2026
074cd72
[refactoring]: separate experimental service discovery from the helpe…
LorenzoTettamanti Feb 1, 2026
370ca78
[refactoring]: created BufferType enum to centralize the event reader…
LorenzoTettamanti Feb 1, 2026
57cb4bb
updated common cargo.toml
LorenzoTettamanti Feb 1, 2026
43fef8d
[#158]: moved IpProtocols and network structures from the identity cr…
LorenzoTettamanti Feb 3, 2026
062b626
[update]: cli packages update
LorenzoTettamanti Feb 3, 2026
8e49cc8
[update]: IpProtocols update . Btter code formatting
LorenzoTettamanti Feb 3, 2026
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
610 changes: 547 additions & 63 deletions cli/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tonic = "0.14.2"
tonic-reflection = "0.14.2"
prost-types = "0.14.3"
prost = "0.14.3"
cortexflow_agent_api = {version = "0.1.1",features = ["client"]}
cortexflow_agent_api = {path = "../core/api",features = ["client"]}
kube = "2.0.1"
k8s-openapi = {version = "0.26.0", features = ["v1_34"]}

Expand Down
84 changes: 83 additions & 1 deletion cli/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use crate::errors::CliError;
use crate::essential::{BASE_COMMAND, connect_to_client, create_config_file, create_configs};
use clap::{Args, Subcommand};
use colored::Colorize;
use kube::Error;
use k8s_openapi::api::core::v1::ConfigMap;
use kube::core::ErrorResponse;
use kube::{Api, Client, Error};
use std::thread::sleep;
use std::{process::Command, thread, time::Duration};

// docs:
Expand Down Expand Up @@ -38,6 +40,8 @@ pub enum InstallCommands {
about = "Deploys a simple example contained in deploy-test-pod.yaml"
)]
TestPods,
#[command(name = "blocklist", about = "Install or Repair blocklist configmap")]
Blocklist,
}

//install args
Expand Down Expand Up @@ -206,6 +210,84 @@ async fn install_simple_example_component() -> Result<(), CliError> {
}
}

// docs:
pub async fn install_blocklist_configmap() -> Result<(), CliError> {
match connect_to_client().await {
Ok(client) => {
println!(
"{} {}",
"=====>".blue().bold(),
"Checking if the Blocklist configmap exists"
);
sleep(Duration::from_secs(1));
let blocklist_exists = check_if_blocklist_exists(client).await?;
if !blocklist_exists {
println!(
"{} {}",
"=====>".blue().bold(),
"Blocklist configmap does not exist".red().bold()
);
sleep(Duration::from_secs(1));
println!("{} {}", "=====>".bold().blue(), "Creating configmap");
let metdata_configs = create_configs();
sleep(Duration::from_secs(1));
match create_config_file(metdata_configs).await {
Ok(_) => {
println!(
"{} {}",
"=====>".bold().blue(),
"Configmap created/repaired successfully".bold().green()
)
}
Err(e) => {
return Err(CliError::InstallerError {
reason: e.to_string(),
});
}
}
return Ok(());
} else {
println!()
}

Ok(())
}
Err(e) => {
return Err(CliError::ClientError(Error::Api(ErrorResponse {
status: "failed".to_string(),
message: "Failed to connect to kubernetes client".to_string(),
reason: e.to_string(),
code: 404,
})));
}
}
}

// docs:
async fn check_if_blocklist_exists(client: Client) -> Result<bool, CliError> {
let namespace = "cortexflow";
let name = "cortexbrain-client-config";
let api: Api<ConfigMap> = Api::namespaced(client, namespace);
match api.get(name).await {
Ok(_) => {
println!(
"{} {}",
"=====>".bold().blue(),
"Blocklist configmap exists".green().bold()
);
Ok(true)
}
Err(_) => {
println!(
"{} {}",
"=====>".bold().blue(),
"Blocklist configmap doesn not exists".red().bold(),
);
Ok(false)
}
}
}

//docs:
//
// This is an auxiliary function to help manage the cortexflow components during the installation
Expand Down
11 changes: 9 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::install::{InstallArgs, InstallCommands, install_cortexflow, install_s
use crate::logs::{LogsArgs, logs_command};
use crate::monitoring::{
MonitorArgs, MonitorCommands, list_features, monitor_dropped_packets, monitor_identity_events,
monitor_latency_metrics,
monitor_latency_metrics, monitor_tracked_veth,
};
use crate::policies::{
PoliciesArgs, PoliciesCommands, check_blocklist, create_blocklist, remove_ip,
Expand Down Expand Up @@ -68,7 +68,7 @@ enum Commands {
struct SetArgs {
val: String,
}

//TODO: add command for monitoring veth interfaces
async fn args_parser() -> Result<(), CliError> {
let args = Cli::parse();
debug!("Arguments {:?}", args.cmd);
Expand All @@ -80,6 +80,10 @@ async fn args_parser() -> Result<(), CliError> {
InstallCommands::TestPods => {
install_simple_example().await?;
}
InstallCommands::Blocklist => {
//install or repair blocklist configmap
let _ = install::install_blocklist_configmap().await?;
}
},
Some(Commands::Uninstall) => {
uninstall().await?;
Expand Down Expand Up @@ -120,6 +124,9 @@ async fn args_parser() -> Result<(), CliError> {
MonitorCommands::Droppedpackets => {
let _ = monitor_dropped_packets().await?;
}
MonitorCommands::Veth => {
let _ = monitor_tracked_veth().await?;
}
},
Some(Commands::Policies(policies_args)) => {
match policies_args.policy_cmd {
Expand Down
60 changes: 55 additions & 5 deletions cli/src/monitoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use std::result::Result::Ok;
use tonic_reflection::pb::v1::server_reflection_response::MessageResponse;

use agent_api::client::{connect_to_client, connect_to_server_reflection};
use agent_api::requests::{get_all_features, send_active_connection_request};
use agent_api::requests::{
get_all_features, send_active_connection_request, send_dropped_packets_request,
send_latency_metrics_request, send_tracked_veth_request,
};

use crate::errors::CliError;
use clap::{Args, Subcommand};
Expand All @@ -33,15 +36,18 @@ pub enum MonitorCommands {
about = "Monitor the dropped packets metrics detected by the metrics service"
)]
Droppedpackets,
#[command(
name = "veth",
about = "Monitor tracked veth interfaces from the identity service"
)]
Veth,
}

// cfcli monitor <args>
#[derive(Args, Debug, Clone)]
pub struct MonitorArgs {
#[command(subcommand)]
pub monitor_cmd: MonitorCommands,
//#[arg(long, short)]
//pub flags: Option<String>,
}

pub async fn list_features() -> Result<(), CliError> {
Expand Down Expand Up @@ -168,7 +174,7 @@ pub async fn monitor_latency_metrics() -> Result<(), CliError> {
"Connected to CortexFlow Client".green()
);
//send request to get latency metrics
match agent_api::requests::send_latency_metrics_request(client).await {
match send_latency_metrics_request(client).await {
Ok(response) => {
let resp = response.into_inner();
if resp.metrics.is_empty() {
Expand Down Expand Up @@ -237,7 +243,7 @@ pub async fn monitor_dropped_packets() -> Result<(), CliError> {
"Connected to CortexFlow Client".green()
);
//send request to get dropped packets metrics
match agent_api::requests::send_dropped_packets_request(client).await {
match send_dropped_packets_request(client).await {
Ok(response) => {
let resp = response.into_inner();
if resp.metrics.is_empty() {
Expand Down Expand Up @@ -291,6 +297,50 @@ pub async fn monitor_dropped_packets() -> Result<(), CliError> {
Ok(())
}

pub async fn monitor_tracked_veth() -> Result<(), CliError> {
println!(
"{} {}",
"=====>".blue().bold(),
"Connecting to cortexflow Client".white()
);
match connect_to_client().await {
Ok(client) => match send_tracked_veth_request(client).await {
Ok(response) => {
let veth_response = response.into_inner();
if veth_response.tot_monitored_veth == 0 {
println!("{} {} ", "=====>".blue().bold(), "No tracked veth found");
Ok(())
} else {
println!(
"{} {} {} {} ",
"=====>".blue().bold(),
"Found:",
&veth_response.tot_monitored_veth,
"tracked veth"
);
for veth in veth_response.veth_names.iter() {
println!("{} {}", "=====>".blue().bold(), &veth);
}
Ok(())
}
}
Err(e) => {
return Err(CliError::AgentError(
tonic_reflection::server::Error::InvalidFileDescriptorSet(e.to_string()),
));
}
},
Err(e) => {
return Err(CliError::ClientError(kube::Error::Api(ErrorResponse {
status: "failed".to_string(),
message: "Failed to connect to kubernetes client".to_string(),
reason: e.to_string(),
code: 404,
})));
}
}
}

fn convert_timestamp_to_date(timestamp: u64) -> String {
DateTime::from_timestamp_micros(timestamp as i64)
.map(|dt| dt.to_string())
Expand Down
Loading