mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 11:02:54 +00:00
refactor: Make eBPF dependencies optional and add conditional compilation support to packet-gateway
- Add ebpf feature flag to Cargo.toml with default disabled - Make aya and aya-log dependencies optional and tied to ebpf feature - Add #[cfg(feature = "ebpf")] conditional compilation directives for EbpfManager imports and usage - Add feature-gated readiness check logic (ebpf_ok only checked when feature enabled) - Add feature-gated metrics_handler implementations (full version with eBPF, stub version without) - Change
This commit is contained in:
@@ -6,9 +6,13 @@ edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[features]
|
||||
default = []
|
||||
ebpf = []
|
||||
|
||||
[dependencies]
|
||||
aya = { workspace = true }
|
||||
aya-log = { workspace = true }
|
||||
aya = { version = "0.13.1", features = ["async_tokio"], optional = true }
|
||||
aya-log = { version = "0.2.1", optional = true }
|
||||
tokio = { workspace = true }
|
||||
redis = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
|
||||
@@ -78,7 +78,7 @@ impl ChargingEngineClient {
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to send usage to charging engine: {}", e);
|
||||
Err(e.context("Failed to send usage to charging engine"))
|
||||
Err(anyhow::anyhow!("Failed to send usage to charging engine: {}", e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ use redis::AsyncCommands;
|
||||
use serde::Serialize;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "ebpf")]
|
||||
use crate::ebpf::EbpfManager;
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -57,7 +59,7 @@ pub async fn readiness_handler(
|
||||
|
||||
let redis_ok = match redis_client.get_multiplexed_async_connection().await {
|
||||
Ok(mut conn) => {
|
||||
match redis::cmd("PING").query_async::<_, String>(&mut conn).await {
|
||||
match redis::AsyncCommands::ping::<String>(&mut conn).await {
|
||||
Ok(_) => {
|
||||
checks.insert("redis".to_string(), serde_json::Value::String("ok".to_string()));
|
||||
true
|
||||
@@ -77,7 +79,12 @@ pub async fn readiness_handler(
|
||||
let ebpf_ok = ebpf_attached.load(std::sync::atomic::Ordering::Relaxed);
|
||||
checks.insert("ebpf".to_string(), serde_json::Value::String(if ebpf_ok { "ok".to_string() } else { "not attached".to_string() }));
|
||||
|
||||
if redis_ok && ebpf_ok {
|
||||
#[cfg(feature = "ebpf")]
|
||||
let ready = redis_ok && ebpf_ok;
|
||||
#[cfg(not(feature = "ebpf"))]
|
||||
let ready = redis_ok;
|
||||
|
||||
if ready {
|
||||
Ok(Json(ReadinessResponse {
|
||||
status: "ready".to_string(),
|
||||
service: "packet-gateway".to_string(),
|
||||
@@ -89,6 +96,7 @@ pub async fn readiness_handler(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ebpf")]
|
||||
pub async fn metrics_handler(
|
||||
State(ebpf_manager): State<Arc<EbpfManager>>,
|
||||
) -> Json<MetricsResponse> {
|
||||
@@ -113,3 +121,15 @@ pub async fn metrics_handler(
|
||||
low_credit_users,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ebpf"))]
|
||||
pub async fn metrics_handler() -> Json<MetricsResponse> {
|
||||
Json(MetricsResponse {
|
||||
status: "ok".to_string(),
|
||||
service: "packet-gateway".to_string(),
|
||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||
tracked_ips: 0,
|
||||
total_bytes_processed: 0,
|
||||
low_credit_users: 0,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user