Skip to content

Commit 868c328

Browse files
Documentation Update (#203)
* [#52]: Updated contact section * [#52]: added developer guide index * [#52]: updated requirements.txt * Revert "[#52]: updated requirements.txt" This reverts commit 1b2b203. * [#52]: updated gitignore * [#51]: Updated getting-started page * [#199]: added gpu-metrics preview snippet * [#199]: added metrics overview in developer-guide section * [#199]: added discussion section in developer-guide * [#199]: added mcp server overview and documentation * [#199]: removed deprecated tests * [#199]: added glossary in developer guide * [#199]: added development workflow guide * [#119]: added architecture overview * [#119]: added troubleshooting section * [#199]: added agent api overview * [#119]: added linux kernel docs in developer guide * [#199]: updated documentation structure * [#199]: fixed link typos * [#199]: updated documentation index page * [#199]: updated documentation index * [#52]: updated README
1 parent 4044522 commit 868c328

28 files changed

Lines changed: 912 additions & 1390 deletions

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,5 @@ config.json
165165
# Claude AI assistant working files
166166
CLAUDE.md
167167

168-
bindings.rs
168+
bindings.rs
169+
site/
263 KB
Loading
1.44 MB
Loading

‎Doc/docs/assets/cortexflow-mcp.png‎

27.7 KB
Loading

‎Doc/docs/cfcli/Agent-API-Overview.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Agent API Overview
1+
# Agent API Commands Overview
22

33
This page documents the CortexFlow Agent gRPC API for versions >= 0.1.3.
44

‎Doc/docs/contacts/contact.md‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
- **Tettamanti Lorenzo** [📧 lorenzotettamanti5@gmail.com](mailto:lorenzotettamanti5@gmail.com)
22
- **Lorenzo Bradanini** [📧 lorenzolollobrada@gmail.com](mailto:lorenzolollobrada@gmail.com)
3-
Right now we're looking for contributors and collaborators. If you have knowledge in DevOps/Kubernetes or Networks please write an email to lorenzotettamanti5@gmail.com
4-
5-
| **Role** | **Skills** | **Tasks** | **Related Issues and Milestones** |
6-
|-----------------------------------|-----------------------------------------------------|------------------------------------------------------------------------------------------|----------------------------------|
7-
| **CortexBrain Core Developer** | - Kubernetes <br> - Networks <br> - Rust | - Work alongside us to build and optimize the core functionalities (Client, DNS, Proxy, Telemetry, etc.) | - [Rust](https://github.com/CortexFlow/CortexBrain/labels/rust) <br> - [Core](https://github.com/CortexFlow/CortexBrain/milestone/1) |
8-
| **CortexBrain Dashboard Developer** | - React <br> - Frontend Development <br> - JavaScript/TypeScript | - Work alongside us to design and improve the dashboard | - [JavaScript](https://github.com/CortexFlow/CortexBrain/labels/javascript) |
9-
| **General Maintainers** | - GitHub <br> - Practical organization <br> - Documentation | - Keep the repository organized and clean <br> - Write/Update documentation <br> - Spot typos in the repository | - [Documentation](https://github.com/CortexFlow/CortexBrain/labels/documentation) <br> - [Question](https://github.com/CortexFlow/CortexBrain/labels/question) |
10-
| **Code Reviewers/Testers** | - Rust <br> - JavaScript/TypeScript <br> - Kubernetes <br> - Docker | - Review code and suggest changes/optimizations <br> - Write tests for CI/CD | - [Code refactoring](https://github.com/CortexFlow/CortexBrain/labels/code%20refactoring) |
3+
We're looking for contributors and collaborators. If you have knowledge in DevOps/Kubernetes, Monitoring, GPUs or Networking and Security please write an email to lorenzotettamanti5@gmail.com
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Agent API Architecture Overview
2+
3+
The CortexBrain **Agent** is the user-space gRPC server that exposes the data collected by the eBPF kernel programs to clients such as [`cfcli`](../cfcli/overview.md). This page gives an overview of the service surface and the data flow behind it. The full message schema lives in [`core/api/protos/agent.proto`](https://github.com/CortexFlow/CortexBrain/blob/main/core/api/protos/agent.proto) in the repository.
4+
5+
## What the Agent is
6+
7+
The Agent is the `cortexflow_agent_api` crate (`core/api/` in the workspace). It is a [tonic](https://docs.rs/tonic/) gRPC server that:
8+
9+
- Listens on `0.0.0.0:9090` (`core/api/src/main.rs`).
10+
- Registers the `agent.Agent` service together with a tonic **server reflection** service, so clients can enumerate the available RPCs at runtime - this is what `cfcli monitoring list` uses.
11+
- On startup, opens a set of **pinned BPF maps** from `/sys/fs/bpf/...` and spawns background reader tasks that drain the perf buffers into mpsc channels.
12+
- Serves the RPC methods (listed below) that drain those channels and return the data to the caller.
13+
14+
The Agent is deployed as the `cortexflow-agent` Kubernetes service (ClusterIP, port 9090). The CLI reaches it via `kubectl port-forward svc/cortexflow-agent 9090:9090 -n cortexflow`.
15+
16+
## Data flow
17+
18+
The Agent is a **consumer and aggregator** of data produced by metrics service which load the eBPF programs and pin the maps
19+
20+
### The BPF maps the Agent reads
21+
22+
| Map (kernel name) | Pinned path | Producer | Userspace struct | Feeds RPC |
23+
|-------------------|-------------|----------|------------------|-----------|
24+
| `EventsMap` | `/sys/fs/bpf/maps/events_map` | Identity (`identity/src/map_handlers.rs`) | `PacketLog` | `ActiveConnections` |
25+
| `net_metrics` | `/sys/fs/bpf/trace_maps/net_metrics` | Metrics (`metrics/src/maps_handlers.rs`) | `NetworkMetrics` | `GetDroppedPacketsMetrics` |
26+
| `time_stamp_events` | `/sys/fs/bpf/trace_maps/time_stamp_events` | Metrics (`metrics/src/maps_handlers.rs`) | `TimeStampMetrics` | `GetLatencyMetrics` |
27+
| `Blocklist` | `/sys/fs/bpf/maps/blocklist_map` | Identity (seeded from the `cortexbrain-client-config` ConfigMap) | `[u8;4] ->[u8;4]` | `AddIpToBlocklist` / `CheckBlocklist` / `RmIpFromBlocklist` |
28+
29+
!!! warning
30+
The Agent hardcodes the paths `/sys/fs/bpf/maps/...` and `/sys/fs/bpf/trace_maps/...` (`core/api/src/api.rs`), while the Identity and Metrics services pin under `${PIN_MAP_PATH}` which defaults to `/sys/fs/bpf/cortexbrain-identity-service/...`. This implies a deployment-time mount/symlink convention that is not captured in code. If you change the pin paths, update both sides.
31+
32+
## The `agent.Agent` service
33+
34+
The gRPC service is defined in `core/api/protos/agent.proto` (package `agent`, service name `Agent`). It exposes unary RPC methods. All methods are discoverable via server reflection.
35+
36+
| RPC method | Request | Response | Description |
37+
|------------|---------|----------|-------------|
38+
| `ActiveConnections` | `RequestActiveConnections { optional string pod_ip }` | `ActiveConnectionResponse { string status; repeated ConnectionEvent events }` | Returns the connection events drained from `events_map`. Each `ConnectionEvent` carries `event_id` (the PID), `src_ip_port`, and `dst_ip_port`. |
39+
| `AddIpToBlocklist` | `AddIpToBlocklistRequest { optional string ip }` | `BlocklistResponse { string status; map<string,string> events }` | Inserts an IPv4 into the `Blocklist` BPF map. If `ip` is omitted, just returns the current blocklist. |
40+
| `CheckBlocklist` | `google.protobuf.Empty` | `BlocklistResponse` | Reads the entire `Blocklist` BPF map and returns it as a `map<ip, ip>`. |
41+
| `RmIpFromBlocklist` | `RmIpFromBlocklistRequest { string ip }` | `RmIpFromBlocklistResponse { string status; map<string,string> events }` | Removes an IPv4 from the `Blocklist` BPF map and returns the remaining entries. |
42+
| `GetLatencyMetrics` | `google.protobuf.Empty` | `LatencyMetricsResponse { string status; repeated LatencyMetric metrics; uint32 total_count; double average_latency_us; double min_latency_us; double max_latency_us }` | Returns TCP connection latency metrics (`delta_us` per event, plus aggregate stats) drained from `time_stamp_events`. |
43+
| `GetDroppedPacketsMetrics` | `google.protobuf.Empty` | `DroppedPacketsResponse { string status; repeated DroppedPacketMetric metrics; uint32 total_drops }` | Returns socket-level drop/error metrics (only entries where `sk_drops > 0`) drained from `net_metrics`. |
44+
| `GetTrackedVeth` | `google.protobuf.Empty` | `VethResponse { string status; repeated string veth_names; int32 tot_monitored_veth }` | Returns tracked veth names from recent events. |
45+
| `GetTrackedVethFromHashMap` | `google.protobuf.Empty` | `VethHashMapResponse { string status; map<string,string> veths }` | Returns tracked veth entries from the pinned eBPF hash map. |
46+
47+
!!! note "Full message schema"
48+
The detailed field-by-field schema for every message (`ConnectionEvent`, `LatencyMetric`, `DroppedPacketMetric`, ...) lives in [`core/api/protos/agent.proto`](https://github.com/CortexFlow/CortexBrain/blob/main/core/api/protos/agent.proto). The [Integrated Metrics](metrics.md) page also describes the metric fields in tabular form. The [CLI Agent API page](../cfcli/Agent-API-Overview.md) has grpcurl examples.
49+
50+
## How `cfcli` calls the Agent
51+
52+
The CLI (`cli/`) is a tonic gRPC client. The mapping between `cfcli` commands and the Agent RPCs:
53+
54+
| `cfcli` command | Agent RPC |
55+
|-----------------|-----------|
56+
| `cfcli monitoring list` | (server reflection - lists all `Agent` methods) |
57+
| `cfcli monitoring connections` | `ActiveConnections` |
58+
| `cfcli monitoring latencymetrics` | `GetLatencyMetrics` |
59+
| `cfcli monitoring droppedpackets` | `GetDroppedPacketsMetrics` |
60+
| `cfcli policy create-blocklist --flags <IP>` | `AddIpToBlocklist` |
61+
| `cfcli policy check-blocklist` | `CheckBlocklist` |
62+
| `cfcli policy remove-ip --flags <IP>` | `RmIpFromBlocklist` |
63+
64+
## Relationship to the Identity service
65+
66+
The **Identity** service (`core/src/components/identity/`) is the **producer** of the connection events and the blocklist. It:
67+
68+
1. Loads the `conntracker` eBPF object.
69+
2. Extracts and pins `EventsMap` (->`events_map`), `Blocklist` (->`blocklist_map`), and other maps.
70+
3. Seeds the `Blocklist` map from the `cortexbrain-client-config` Kubernetes ConfigMap on startup.
71+
4. Attaches the TC classifier and kprobes that fill the perf buffers.
72+
73+
The **Agent** never calls Identity directly - they communicate solely through the pinned BPF maps in `/sys/fs/bpf/`. The Agent is also a **mutator** of the `Blocklist` map that Identity owns: `AddIpToBlocklist` and `RmIpFromBlocklist` write to it at runtime, on top of the initial ConfigMap seeding.
74+
75+
## Security notes
76+
77+
The gRPC channel is currently **plaintext** HTTP/2:
78+
79+
- The server binds to `0.0.0.0:9090` (`core/api/src/main.rs`, flagged with a `FIXME`).
80+
- The client connects to `http://127.0.0.1:9090` (`core/api/src/client.rs`, also flagged with a `FIXME`).
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Architecture Overview
2+
3+
This page describes the CortexBrain architecture with a focus on how data flows from the Linux kernel, through eBPF programs and pinned BPF maps, to the user-space gRPC agent, and finally to the `cfcli` and the Grafana Dashboard.
4+
5+
The conceptual diagram on the [home page](../index.md#architecture) gives the high-level picture; in this page you will find the full detailed pipeline.
6+
7+
## Architecture Resume
8+
9+
CortexBrain is built around a four-stage pipeline. Each stage has a clear responsibility and a well-defined boundary with the next.
10+
11+
| Stage | Components | Role | Output |
12+
|-------|------------|------|--------|
13+
| **1. Kernel instrumentation** | `conntracker`, `metrics_tracer` (eBPF) | Observe at kernel level via TC classifiers and kprobes | PerfEventArray fills |
14+
| **2. Map pinning** | `identity`, `metrics` (user-space loaders) | Load + attach the eBPF programs, pin the maps to `/sys/fs/bpf/`, seed policy | Pinned maps in bpffs |
15+
| **3. Aggregation & serving** | `agent` (`core/api`) - gRPC on `:9090` and opentelemetry collector on `:4317` | Open pinned maps, drain perf buffers into mpsc channels, serve the RPC and aggregate the data for visualization | gRPC responses |
16+
| **4. Consumption** | `cfcli` (live), `prometheus` ,`dashboard` (grafana) | Forwards the data to the UI components |
17+
18+
!!! tip "Reading order"
19+
If you want the detail behind each stage, after this page read the [Agent API Overview](agent-api.md) for the gRPC surface and the [Integrated Metrics](metrics.md) page for the metric field schemas.
20+
21+
## Full Pipeline
22+
!!! warn
23+
The **0.1.5** version adds OpenTelemetry instruments across socket/network, CPU, memory, scheduler, and SSL tracing (experimental) see the [Integrated Metrics](metrics.md#opentelemetry-metrics-incoming-metrics-patch) page for the full instrument list.
24+
25+
![cf-architecture-v.0.1.5](../assets/cf-architecture-0.1.5.png)
26+
27+
### Kernel hooks
28+
29+
CortexBrain attaches eBPF programs to the following kernel hook points. The diagram below shows where these hooks sit in the Linux network stack.
30+
31+
![Linux network stack and eBPF hooks](../assets/linux-net-stack.svg "Linux network stack with eBPF hook points")
32+
33+
| Program | Attach type | Target function | BPF map written | Data produced |
34+
|---------|-------------|-----------------|------------------|---------------|
35+
| `identity_classifier` | TC classifier (ingress) | veth interfaces | `EventsMap` | `PacketLog` (per-packet metadata) |
36+
| `veth_creation_trace` | kprobe | `register_netdevice` | `veth_identity_map` | `VethLog` (event_type=1) |
37+
| `veth_deletion_trace` | kprobe | `unregister_netdevice_queue` | `veth_identity_map` | `VethLog` (event_type=2) |
38+
| `tcp_message_tracer` | kprobe | `tcp_v4_rcv`, `tcp_v4_connect` | `TcpPacketRegistry` | `TcpPacketRegistry` (TCP flow metadata) |
39+
| `metrics_tracer` | kprobe | `tcp_identify_packet_loss` | `net_metrics` | `NetworkMetrics` (socket stats + drops) |
40+
| `tcp_connect` | kprobe | `tcp_v4_connect`, `tcp_v6_connect` | `time_stamp_start` | start timestamp keyed by socket pointer |
41+
| `tcp_rcv_state_process` | kprobe | `tcp_rcv_state_process` | `time_stamp_events` | `TimeStampEvent` (latency `delta_us`) |
42+
43+
**Source files**:
44+
- `core/src/components/conntracker/src/main.rs` and sub-modules (`tc.rs`, `veth_tracer.rs`, `tcp_analyzer.rs`, `data_structures.rs`)
45+
- `core/src/components/metrics_tracer/src/main.rs` and `data_structures.rs`
46+
47+
### Deployment topology
48+
49+
All CortexBrain components run in the `cortexflow` namespace. The core deployments use `hostPID: true`, `hostNetwork: true`, and `privileged: true` with the `BPF`, `SYS_ADMIN`, `NET_ADMIN`, `SYS_PTRACE`, and `SYS_RESOURCE` capabilities, and mount the host `/sys/fs/bpf` (bidirectional), `/proc`, and `/lib/modules`.
50+
51+
| Pod (Deployment) | Container & binary | Image | Network exposure | BPF maps (producer / consumer) |
52+
|------------------|--------------------|-------|------------------|--------------------------------|
53+
| `cortexflow-agent` | `agent` -> `/usr/local/bin/agent-api` | `lorenzotettamanti/cortexflow-agent:latest` | Service `cortexflow-agent` ClusterIP TCP 9090 (grpc); reached by `cfcli` via `kubectl port-forward` | **Consumer only** - reads `events_map`, `net_metrics`, `time_stamp_events`, `blocklist_map` |
54+
| `cortexflow-identity` | initContainer `bpf-map-permissions` (mounts bpffs); `identity` -> `/usr/local/bin/cortexflow-identity-service`; sidecar `bpftool-control-manager` | `lorenzotettamanti/cortexflow-identity:latest` | None (no Service) | **Producer** - pins `events_map`, `veth_map`, `blocklist_map`, `tcp_packet_registry`; seeds `blocklist_map` from the `cortexbrain-client-config` ConfigMap |
55+
| `cortexflow-metrics` | `metrics` -> `/usr/local/bin/cortexflow-metrics`; sidecar `bpftool-control-manager` | `lorenzotettamanti/cortexflow-metrics:latest` | None (no Service) | **Producer** - pins `net_metrics`, `time_stamp_events` |
56+
57+
**Manifests**: `core/src/testing/agent.yaml`, `core/src/testing/identity.yaml`, `core/src/testing/metrics.yaml`
58+
## Where to go next
59+
60+
- **[Agent API Overview](../developer-guide/agent-api.md)** - the gRPC RPCs and the BPF maps behind them, in detail.
61+
- **[Integrated Metrics](../developer-guide/metrics.md)** - the field schemas for `ConnectionEvent`, `LatencyMetric`, `DroppedPacketMetric`, and the incoming OpenTelemetry instruments.
62+
- **[Development Workflow](../developer-guide/development-workflow.md)** - how to build the components locally and submit changes.
63+
- **[Development Goals & Discussions](../developer-guide/discussions.md)** - milestones, roadmap, and how to propose new features.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Development Workflow
2+
3+
This page groups all the best practices to help newcomers create their first pull request.
4+
5+
## Branch conventions
6+
7+
We review every type of PR that points to the **current development branch**.
8+
The latest public version is contained in the **0.1.5** branch. The current development version is contained in the **0.1.6** branch.
9+
10+
|Branch | Content|
11+
|-----|------|
12+
|**main**| current production version linked to the latest version |
13+
|**0.1.5**| latest version |
14+
|**0.1.6**| current development version (send your PR here)|
15+
16+
17+
## Commit message conventions
18+
19+
- Reference the issue number: `#<n>: <description>` (e.g. _[#199]: updated documentation. Added development-workflow_)
20+
21+
## Contribution flow
22+
23+
Before opening a pull request, you **must** open an issue or a GitHub Discussion for any non-trivial change - pull requests without a related issue or discussion are not accepted (see `CONTRIBUTING.md`). This rule ensures that every update is pre-approved by the maintainers and is aligned with the latest project goals.
24+
25+
- ### "Step 1 - Fork & clone"
26+
27+
```bash
28+
git clone https://github.com/<your-username>/CortexBrain.git
29+
cd CortexBrain
30+
git remote add upstream https://github.com/CortexFlow/CortexBrain.git
31+
```
32+
33+
- ### "Step 2 - Open an issue or discussion"
34+
35+
New features and significant changes require a prior [GitHub Discussion](https://github.com/CortexFlow/CortexBrain/discussions). Bug fixes and small improvements can start directly from a [GitHub Issue](https://github.com/CortexFlow/CortexBrain/issues/new/choose). Reference the issue/discussion number in every commit and in the PR description.
36+
37+
- ### "Step 3 - Create a dedicated branch"
38+
39+
```bash
40+
git checkout -b feature/<short-description>
41+
```
42+
43+
Pull requests without a dedicated branch are not accepted. Use a descriptive branch name prefixed by the type of change (`feature/`, `fix/`, `docs/`).
44+
45+
- ### "Step 4 - Commit with a clear message"
46+
47+
Tag the related issue in every commit using the `#issue: message` convention:
48+
49+
```bash
50+
git commit -m "#78: added TCP connection tracing in conntracker"
51+
```
52+
53+
Keep commits focused. Avoid pull requests larger than ~1500 lines of code unless explicitly justified. (e.g. Grafana example dashboard update)
54+
55+
- ### "Step 5 - Open a Pull Request"
56+
57+
Open the PR against `CortexFlow/CortexBrain:<current development branch>`. See the **Branch Conventions** to correctly link the PR to the development branch. The PR template asks for:
58+
59+
- A description of the change
60+
- The type of change (bug fix, new feature, documentation, refactoring, other)
61+
- A checklist (tested locally, docs updated, new tests added, builds successfully)
62+
- Related issues tagged using `#`
63+
64+
The PR is auto-assigned to a maintainer (`@LorenzoTettamanti`) and an auto-reviewer assignment workflow runs.
65+
66+
67+
## Local build
68+
69+
To build the core components locally, see the [Getting Started for developers](../getting-started/installation.md#getting-started-for-developers) section. The short version:
70+
71+
```bash
72+
# From the repo root
73+
cargo +nightly build --release -p <component-name>
74+
```
75+
76+
Each component also has its own build script under `core/` and `core/src/components/<name>/`.
77+
78+
```bash
79+
# From the repo root CortexBrain/core
80+
cargo +nightly build --release -p <component-name>
81+
```
82+
83+
84+
## Containarization
85+
86+
Every component can be containerized using a prebuilt scripts located in the `CortexBrain/core`.
87+
|Script name| content|
88+
|-----|------|
89+
|agent-api-build.sh| Build the cortexflow-agent container|
90+
|identity-build.sh| Build the identity service container|
91+
|metrics-build.sh| Build the metrics service container|

0 commit comments

Comments
 (0)