[#119] Add cortexbrain-common crate to eliminate code duplication#154
Conversation
…cation This commit introduces a new shared crate `cortexbrain-common` to address issue ( part of )CortexFlow#119 regarding code optimization and reduction of repeated code fragments. ## Changes Made ### New Shared Crate - Created `core/common/` crate with: - `logger.rs`: Centralized logger initialization functions - `constants.rs`: Shared constants (BPF_PATH, PIN_MAP_PATH) ### Refactored Components - **api**: Migrated to use shared logger initialization - **identity**: Migrated to use shared logger and constants - **metrics**: Migrated to use shared logger and constants ### Code Reduction - Eliminated ~46 lines of duplicated code - Logger initialization: 5 duplicates (10 lines each) → 1 shared function - Constants: 6 duplicate declarations → 1 shared module ## Benefits - Single source of truth for logger configuration - Consistent initialization across all components - Easier maintenance and future modifications - Foundation for further refactoring (BPF utilities, error types) ## Testing All modified components compile successfully: - cortexbrain-common ✓ - api ✓ - identity ✓ - metrics ✓
Resolved conflicts by integrating cortexbrain-common crate with upstream changes: - Maintained cortexbrain-common dependency in all modified components - Adapted to renamed packages (cortexflow_agent_api, cortexflow_identity) - Integrated with new features and dependencies from upstream - Fixed PIN_MAP_PATH reference in metrics component All modified components compile successfully.
|
Buonasera @AndreaBozzo , i'll check your PR in a couple of hours |
|
@AndreaBozzo, checked the PR and it seems great. I'll go ahead with a runtime test today, as it's currently unchecked in the test plan. Sorry for being late, but I've had busy days |
No problem bro, as this pr implements a common usage crate that can be expanded further, also @siddh34 should take a look i think |
|
Will try to test it in few hours @AndreaBozzo Edit: Made some exceptions for copying common into docker context
Things seems to be working so far! Thanks mate @AndreaBozzo for contribution 🚀🚀 |
|
Thanks man, looking forward to cooperate further |
|
@AndreaBozzo just tested by my side, and the code is working. I'm creating the new tags. Thanks for your PR! |
93f50a4
into
CortexFlow:feature/ebpf-core
|
@AndreaBozzo @siddh34 , i've added a commit to update the dockerfiles and the building scripts and everything seems to work now. New tags: cortexflow-identity: identity:0.1.1-beta.3 cortexflow-agent: agent:0.1.1-beta.3 cortexflow-metrics: metrics:0.1.0 |
|
Awesome, if you guys have any optimization you want to suggest/try just go ahead and tell or i'll propose some work on bpf utilities next. Also, @LorenzoTettamanti i can't straight up access the Docker links you provided becouse i lack right, but i still can see them on your public docker profiles so It should be fine. Catch up soon |
Sure @AndreaBozzo, I'll let you know, next week! |



I'm sending this PR as lorenzo said he might already be working on few refactors, low-code but modifies few files. Works towards completing #119
Summary
Implements some code optimization for issue #119 by creating a shared
cortexbrain-commoncrate to eliminate repeated code fragments across components.Status: Solved my upstream problem ( xd )
Changes Made
New Shared Crate:
core/common/with centralized utilities:logger.rs: Shared logger initialization functions (init_default_logger(),init_logger_without_time())constants.rs: Shared constants (BPF_PATH,PIN_MAP_PATH)Refactored Components:
Impact
Code Reduction:
Benefits:
Files Changed
core/Cargo.toml- Added common to workspacecore/common/- New shared crate (4 files)core/api/- Refactored to use commoncore/src/components/identity/- Refactored to use commoncore/src/components/metrics/- Refactored to use commonTest Plan
cortexbrain-commoncrate successfullycortexflow_agent_apicomponentcortexflow_identitycomponentmetricscomponentIntegration Notes
Areas worth checking out next (imo)