diff --git a/core/Cargo.lock b/core/Cargo.lock index 4ff5da19..38ac516f 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] @@ -122,11 +122,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "aya-build" +version = "0.1.2" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" +dependencies = [ + "anyhow", + "cargo_metadata", +] + [[package]] name = "aya-ebpf" version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" dependencies = [ + "aya-build", "aya-ebpf-bindings", "aya-ebpf-cty", "aya-ebpf-macros", @@ -136,20 +146,24 @@ dependencies = [ [[package]] name = "aya-ebpf-bindings" version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" dependencies = [ + "aya-build", "aya-ebpf-cty", ] [[package]] name = "aya-ebpf-cty" version = "0.2.2" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" +dependencies = [ + "aya-build", +] [[package]] name = "aya-ebpf-macros" version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" dependencies = [ "proc-macro2", "proc-macro2-diagnostics", @@ -183,7 +197,7 @@ dependencies = [ [[package]] name = "aya-log-common" version = "0.1.15" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" dependencies = [ "num_enum", ] @@ -191,7 +205,7 @@ dependencies = [ [[package]] name = "aya-log-ebpf" version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" dependencies = [ "aya-ebpf", "aya-log-common 0.1.15 (git+https://github.com/aya-rs/aya)", @@ -201,7 +215,7 @@ dependencies = [ [[package]] name = "aya-log-ebpf-macros" version = "0.1.0" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" dependencies = [ "aya-log-common 0.1.15 (git+https://github.com/aya-rs/aya)", "aya-log-parser", @@ -213,7 +227,7 @@ dependencies = [ [[package]] name = "aya-log-parser" version = "0.1.13" -source = "git+https://github.com/aya-rs/aya#fc5387c80626957017ceeb988322bc288f438059" +source = "git+https://github.com/aya-rs/aya#948b8553ee72ab72d91c9a16e7e937a75eb0e155" dependencies = [ "aya-log-common 0.1.15 (git+https://github.com/aya-rs/aya)", ] @@ -240,9 +254,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" -version = "2.9.4" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "block-buffer" @@ -285,11 +299,43 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "camino" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "276a59bf2b2c967788139340c9f0c5b12d7fd6630315c15c217e559de85d2609" +dependencies = [ + "serde_core", +] + +[[package]] +name = "cargo-platform" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122ec45a44b270afd1402f351b782c676b173e3c3fb28d86ff7ebfb4d86a4ee4" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "981a6f317983eec002839b90fae7411a85621410ae591a9cab2ecf5cb5744873" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror 2.0.17", +] + [[package]] name = "cc" -version = "1.2.41" +version = "1.2.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" +checksum = "37521ac7aabe3d13122dc382493e20c9416f299d2ccd5b3a5340a2570cdeb0f3" dependencies = [ "find-msvc-tools", "shlex", @@ -297,9 +343,9 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cfg_aliases" @@ -355,6 +401,15 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cortexbrain-common" +version = "0.1.0" +dependencies = [ + "anyhow", + "tracing", + "tracing-subscriber", +] + [[package]] name = "cortexflow_agent_api" version = "0.1.1-beta.2" @@ -364,6 +419,7 @@ dependencies = [ "bytemuck", "bytemuck_derive", "chrono", + "cortexbrain-common", "cortexflow_identity", "prost", "tokio", @@ -387,6 +443,7 @@ dependencies = [ "bytemuck", "bytemuck_derive", "bytes", + "cortexbrain-common", "k8s-openapi", "kube", "libc", @@ -605,19 +662,19 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", - "wasi 0.11.1+wasi-snapshot-preview1", + "wasi", ] [[package]] name = "getrandom" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.7+wasi-0.2.4", + "wasip2", ] [[package]] @@ -818,9 +875,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.4" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" +checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" dependencies = [ "equivalent", "hashbrown 0.16.0", @@ -843,9 +900,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "js-sys" -version = "0.3.81" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" +checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" dependencies = [ "once_cell", "wasm-bindgen", @@ -1012,6 +1069,7 @@ dependencies = [ "aya-log", "bytemuck", "bytes", + "cortexbrain-common", "libc", "nix", "tokio", @@ -1037,13 +1095,13 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "mio" -version = "1.0.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" +checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873" dependencies = [ "libc", - "wasi 0.11.1+wasi-snapshot-preview1", - "windows-sys 0.59.0", + "wasi", + "windows-sys 0.61.2", ] [[package]] @@ -1085,9 +1143,9 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" +checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" dependencies = [ "num_enum_derive", "rustversion", @@ -1095,9 +1153,9 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" dependencies = [ "proc-macro2", "quote", @@ -1273,9 +1331,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.101" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] @@ -1392,9 +1450,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.12.1" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a52d8d02cacdb176ef4678de6c052efb4b3da14b78e4db683a4252762be5433" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ "aho-corasick", "memchr", @@ -1404,9 +1462,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "722166aa0d7438abbaa4d5cc2c649dac844e8c56d82fb3d33e9c34b5cd268fc6" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -1415,9 +1473,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3160422bbd54dd5ecfdca71e5fd59b7b8fe2b1697ab2baf64f6d05dcc66d298" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "ring" @@ -1552,6 +1610,16 @@ dependencies = [ "libc", ] +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" +dependencies = [ + "serde", + "serde_core", +] + [[package]] name = "serde" version = "1.0.228" @@ -1683,9 +1751,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.106" +version = "2.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" dependencies = [ "proc-macro2", "quote", @@ -1705,7 +1773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" dependencies = [ "fastrand", - "getrandom 0.3.3", + "getrandom 0.3.4", "once_cell", "rustix", "windows-sys 0.61.2", @@ -1811,9 +1879,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.16" +version = "0.7.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5" +checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594" dependencies = [ "bytes", "futures-core", @@ -2041,9 +2109,9 @@ checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" [[package]] name = "unicode-ident" -version = "1.0.19" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "unsafe-libyaml" @@ -2084,15 +2152,6 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" -[[package]] -name = "wasi" -version = "0.14.7+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" -dependencies = [ - "wasip2", -] - [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" @@ -2104,9 +2163,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" +checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" dependencies = [ "cfg-if", "once_cell", @@ -2115,25 +2174,11 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - [[package]] name = "wasm-bindgen-macro" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" +checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2141,22 +2186,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" +checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" dependencies = [ + "bumpalo", "proc-macro2", "quote", "syn", - "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" +checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" dependencies = [ "unicode-ident", ] @@ -2241,15 +2286,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-sys" version = "0.60.2" diff --git a/core/Cargo.toml b/core/Cargo.toml index f1b50db3..dd324455 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,7 @@ [workspace] resolver = "3" members = [ + "common", "api", "src/components/conntracker", "src/components/identity", diff --git a/core/api/Cargo.toml b/core/api/Cargo.toml index 4bc6d801..6d40115e 100644 --- a/core/api/Cargo.toml +++ b/core/api/Cargo.toml @@ -23,6 +23,7 @@ tonic = "0.14.0" tonic-prost = "0.14.0" tracing = "0.1.41" aya = "0.13.1" +cortexbrain-common = { path = "../common" } tonic-reflection = "0.14.0" tonic-build = "0.14.0" tracing-subscriber = "0.3.19" diff --git a/core/api/Dockerfile b/core/api/Dockerfile index 468bf97f..3946f3f6 100644 --- a/core/api/Dockerfile +++ b/core/api/Dockerfile @@ -21,6 +21,7 @@ WORKDIR /usr/src/app/agent # Copy Cargo manifest and sources COPY . . +COPY common ../common # Fetch dependencies and build release RUN cargo fetch diff --git a/core/api/src/main.rs b/core/api/src/main.rs index 2c76b431..4410458e 100644 --- a/core/api/src/main.rs +++ b/core/api/src/main.rs @@ -1,6 +1,6 @@ // module imports use tonic::transport::{Error, Server}; -use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter}; +use cortexbrain_common::logger; mod agent; mod api; @@ -20,16 +20,7 @@ use tracing::{error, info}; #[main] async fn main() -> Result<(), Error> { //init tracing subscriber - tracing_subscriber::fmt() - .with_max_level(tracing::Level::INFO) - .with_target(false) - .with_level(true) - .with_span_events(FmtSpan::NONE) - .with_file(false) - .pretty() - .with_env_filter(EnvFilter::new("info")) - .with_line_number(false) - .init(); + logger::init_default_logger(); info!("Starting agent server..."); info!("fetching data"); diff --git a/core/common/Cargo.toml b/core/common/Cargo.toml new file mode 100644 index 00000000..6c8e04a8 --- /dev/null +++ b/core/common/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "cortexbrain-common" +version = "0.1.0" +edition = "2021" + +[dependencies] +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] } +anyhow = "1.0" diff --git a/core/common/src/constants.rs b/core/common/src/constants.rs new file mode 100644 index 00000000..4cc38355 --- /dev/null +++ b/core/common/src/constants.rs @@ -0,0 +1,7 @@ +/// Environment variable name for the BPF program file path. +/// Used by all components to load their eBPF programs. +pub const BPF_PATH: &str = "BPF_PATH"; + +/// Environment variable name for the BPF map pinning path. +/// Used for sharing maps between eBPF programs. +pub const PIN_MAP_PATH: &str = "PIN_MAP_PATH"; diff --git a/core/common/src/lib.rs b/core/common/src/lib.rs new file mode 100644 index 00000000..c5d43735 --- /dev/null +++ b/core/common/src/lib.rs @@ -0,0 +1,2 @@ +pub mod constants; +pub mod logger; diff --git a/core/common/src/logger.rs b/core/common/src/logger.rs new file mode 100644 index 00000000..5a1b8906 --- /dev/null +++ b/core/common/src/logger.rs @@ -0,0 +1,37 @@ +use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter}; + +/// Initialize the default logger configuration used across CortexBrain components. +/// +/// This configures tracing with: +/// - INFO level logging +/// - Pretty formatting +/// - No target, file, or line number information +/// - Environment-based filtering +pub fn init_default_logger() { + tracing_subscriber::fmt() + .with_max_level(tracing::Level::INFO) + .with_target(false) + .with_level(true) + .with_span_events(FmtSpan::NONE) + .with_file(false) + .pretty() + .with_env_filter(EnvFilter::new("info")) + .with_line_number(false) + .init(); +} + +/// Initialize logger without timestamp information. +/// Used by components that don't need timestamp logging. +pub fn init_logger_without_time() { + tracing_subscriber::fmt() + .with_max_level(tracing::Level::INFO) + .with_target(false) + .with_level(true) + .with_span_events(FmtSpan::NONE) + .with_file(false) + .without_time() + .pretty() + .with_env_filter(EnvFilter::new("info")) + .with_line_number(false) + .init(); +} diff --git a/core/src/components/identity/Cargo.toml b/core/src/components/identity/Cargo.toml index dd0f4011..e53dcdc2 100644 --- a/core/src/components/identity/Cargo.toml +++ b/core/src/components/identity/Cargo.toml @@ -27,6 +27,7 @@ tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } libc = "0.2.172" bytemuck = {version ="1.23.0",features = ["derive"]} bytemuck_derive = "1.10.1" +cortexbrain-common = { path = "../../../common" } nix = { version = "0.30.1", features = ["net"] } kube = {version = "2.0.1",features = ["client"]} k8s-openapi = {version ="0.26.0", features = ["v1_34"]} diff --git a/core/src/components/identity/Dockerfile b/core/src/components/identity/Dockerfile index 197b5cba..30feb4ef 100644 --- a/core/src/components/identity/Dockerfile +++ b/core/src/components/identity/Dockerfile @@ -7,6 +7,7 @@ WORKDIR /usr/src/app/identity-service # Copy Cargo manifest and sources COPY Cargo.toml . COPY src ./src +COPY common ../../../common # Fetch dependencies and build release RUN cargo fetch && cargo build --release diff --git a/core/src/components/identity/build-identity.sh b/core/src/components/identity/build-identity.sh index bcee85d8..133aa0ad 100755 --- a/core/src/components/identity/build-identity.sh +++ b/core/src/components/identity/build-identity.sh @@ -8,6 +8,7 @@ popd echo "Copying connection tracker binaries" cp -r ../../../target/bpfel-unknown-none/release/conntracker conntracker +cp -r ../../../common common # Run docker build docker build -t identity:0.0.1 . @@ -15,3 +16,4 @@ docker build -t identity:0.0.1 . # Cleanup echo "Cleaning building files" rm -rf conntracker +rm -rf common diff --git a/core/src/components/identity/src/helpers.rs b/core/src/components/identity/src/helpers.rs index 34911f76..3a0be5b4 100644 --- a/core/src/components/identity/src/helpers.rs +++ b/core/src/components/identity/src/helpers.rs @@ -21,11 +21,7 @@ use std::{ }, }; use tracing::{error, info, warn}; - -/* - * decleare bpf path env variable - */ -const BPF_PATH: &str = "BPF_PATH"; +use cortexbrain_common::constants; /* * TryFrom Trait implementation for IpProtocols enum diff --git a/core/src/components/identity/src/main.rs b/core/src/components/identity/src/main.rs index 2e6813c6..9804256c 100644 --- a/core/src/components/identity/src/main.rs +++ b/core/src/components/identity/src/main.rs @@ -31,27 +31,14 @@ use std::{ convert::TryInto, path::Path, sync::{ Arc, Mutex, atomic::{ AtomicBoo use anyhow::{ Context, Ok }; use tokio::{ fs, signal }; use tracing::{ error, info }; -use tracing_subscriber::{ EnvFilter, fmt::format::FmtSpan }; - -const BPF_PATH: &str = "BPF_PATH"; //BPF env path -const PIN_MAP_PATH: &str = "PIN_MAP_PATH"; +use cortexbrain_common::{constants, logger}; use std::collections::HashMap; #[tokio::main] async fn main() -> Result<(), anyhow::Error> { //init tracing subscriber - tracing_subscriber - ::fmt() - .with_max_level(tracing::Level::INFO) - .with_target(false) - .with_level(true) - .with_span_events(FmtSpan::NONE) - .with_file(false) - .pretty() - .with_env_filter(EnvFilter::new("info")) - .with_line_number(false) - .init(); + logger::init_default_logger(); info!("Starting identity service..."); info!("fetching data"); @@ -60,13 +47,13 @@ async fn main() -> Result<(), anyhow::Error> { let link_ids = Arc::new(Mutex::new(HashMap::::new())); //init conntracker data path - let bpf_path = std::env::var(BPF_PATH).context("BPF_PATH environment variable required")?; + let bpf_path = std::env::var(constants::BPF_PATH).context("BPF_PATH environment variable required")?; let data = fs::read(Path::new(&bpf_path)).await.context("failed to load file from path")?; //init bpf data let bpf = Arc::new(Mutex::new(Bpf::load(&data)?)); let bpf_map_save_path = std::env - ::var(PIN_MAP_PATH) + ::var(constants::PIN_MAP_PATH) .context("PIN_MAP_PATH environment variable required")?; match init_bpf_maps(bpf.clone()) { diff --git a/core/src/components/metrics/Cargo.toml b/core/src/components/metrics/Cargo.toml index b2b4fb8c..112872e8 100644 --- a/core/src/components/metrics/Cargo.toml +++ b/core/src/components/metrics/Cargo.toml @@ -13,4 +13,5 @@ tracing = "0.1.41" tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } libc = "0.2.172" bytemuck = "1.23.0" +cortexbrain-common = { path = "../../../common" } nix ={version="0.30.1",features=["net"]} diff --git a/core/src/components/metrics/Dockerfile b/core/src/components/metrics/Dockerfile index b5674bf8..8b22aaeb 100644 --- a/core/src/components/metrics/Dockerfile +++ b/core/src/components/metrics/Dockerfile @@ -7,6 +7,7 @@ WORKDIR /usr/src/app/metrics # Copy Cargo manifest and sources COPY Cargo.toml . COPY src ./src +COPY common ../../../common # Fetch dependencies and build release RUN cargo fetch && cargo build --release diff --git a/core/src/components/metrics/build-metrics.sh b/core/src/components/metrics/build-metrics.sh index 874ae1ed..fe6a9f64 100755 --- a/core/src/components/metrics/build-metrics.sh +++ b/core/src/components/metrics/build-metrics.sh @@ -8,6 +8,7 @@ popd echo "Copying metrics_tracer binaries" cp -r ../../../target/bpfel-unknown-none/release/metrics_tracer metrics_tracer +cp -r ../../../common common # Run docker build docker build -t metrics:0.0.1 . @@ -15,3 +16,4 @@ docker build -t metrics:0.0.1 . # Cleanup echo "Cleaning building files" rm -rf metrics_tracer +rm -rf common diff --git a/core/src/components/metrics/src/main.rs b/core/src/components/metrics/src/main.rs index 134c8dd7..2b0f2e91 100644 --- a/core/src/components/metrics/src/main.rs +++ b/core/src/components/metrics/src/main.rs @@ -12,10 +12,7 @@ use std::{ use anyhow::{Context, Ok}; use tracing::{error, info}; -use tracing_subscriber::{EnvFilter, fmt::format::FmtSpan}; - -const BPF_PATH: &str = "BPF_PATH"; //BPF env path -const PIN_MAP_PATH: &str = "PIN_MAP_PATH"; +use cortexbrain_common::{constants, logger}; mod helpers; use crate::{helpers::event_listener, maps_handlers::map_pinner, program_handlers::load_and_attach_tcp_programs}; @@ -31,21 +28,12 @@ mod structs; #[tokio::main] async fn main() -> Result<(), anyhow::Error> { //init tracing subscriber - tracing_subscriber::fmt() - .with_max_level(tracing::Level::INFO) - .with_target(false) - .with_level(true) - .with_span_events(FmtSpan::NONE) - .with_file(false) - .pretty() - .with_env_filter(EnvFilter::new("info")) - .with_line_number(false) - .init(); + logger::init_default_logger(); info!("Starting metrics service..."); info!("fetching data"); - let bpf_path = env::var(BPF_PATH).context("BPF_PATH environment variable required")?; + let bpf_path = env::var(constants::BPF_PATH).context("BPF_PATH environment variable required")?; let data = fs::read(Path::new(&bpf_path)).context("Failed to load file from path")?; let bpf = Arc::new(Mutex::new(Ebpf::load(&data)?)); let tcp_bpf = bpf.clone(); @@ -54,7 +42,7 @@ async fn main() -> Result<(), anyhow::Error> { info!("Running Ebpf logger"); info!("loading programs"); let bpf_map_save_path = - std::env::var(PIN_MAP_PATH).context("PIN_MAP_PATH environment variable required")?; + std::env::var(constants::PIN_MAP_PATH).context("PIN_MAP_PATH environment variable required")?; match init_ebpf_maps(bpf.clone()) { std::result::Result::Ok(maps) => {