feat: flowstats protocol-specific maps #375
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
This PR introduces a significant refactor of the eBPF memory architecture and performance tracking logic to improve scalability and data accuracy.
1. Protocol-Specific Map Architecture (Split-Maps)
To reduce kernel memory footprint, the monolithic
FlowStatsstruct was split into a base struct and two optional extension maps:FLOW_STATS(Base): Reduced from 176 bytes to 120 bytes. Contains Ethernet/IP layer data common to all flows.TCP_STATS(Extension): 56-byte map allocated only for TCP flows. Stores handshake timings, state, and transaction performance metrics.ICMP_STATS(Extension): 4-byte map allocated only for ICMP flows. Stores type and code metadata.Impact: Saves ~37% of kernel memory for typical traffic mixes (40% TCP, 50% UDP, 10% ICMP).
2. Direction-Agnostic Latency Logic
Upgraded TCP transaction timing to track timestamps for both directions independently. This allows for accurate latency and jitter calculation regardless of which side (client or server) initiates a data transaction, and correctly handles "Late Start" scenarios where monitoring begins mid-flow.
3. Userspace "Join" Logic & Multi-Map Cleanup
record_flowto perform conditional lookups (Joins) of protocol extensions based on the base protocol.EbpfFlowGuard,timeout_and_remove_flow, andorphan_scanner_taskwith a macro-based approach to ensure keys are wiped from all eBPF tables simultaneously, preventing kernel memory leaks.flow.ip.ttlvsflow.reverse.ip.ttl).Fixes ENG-372
Type of change
Testing
mermin-commontests to verify the new 120-byte, 56-byte, and 4-byte memory layouts.std::mem::forgeton leaked Arcs.kubectl debugwithping -4to confirm Echo Request/Reply (8/0) mapping.Proof it works
TCP Span with Split-Map Join & Performance Metrics
ICMPv6 Span showing successful Join of ICMP_STATS
Checklist
cargo fmtandcargo clippy)