Skip to content

Commit

Permalink
Allow sampling configs to be applied for PCA
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Jun 28, 2024
1 parent e84e169 commit e318d16
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bpf/pca.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ static inline bool validate_pca_filter(struct __sk_buff *skb, direction dir) {
}

static inline int export_packet_payload(struct __sk_buff *skb, direction dir) {
// If sampling is defined, will only parse 1 out of "sampling" flows
if (sampling > 1 && (bpf_get_prandom_u32() % sampling) != 0) {
return 0;
}

void *data_end = (void *)(long)skb->data_end;
void *data = (void *)(long)skb->data;

Expand Down
1 change: 1 addition & 0 deletions pkg/agent/packets_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func PacketsAgent(cfg *Config) (*Packets, error) {
EnableIngress: ingress,
EnableEgress: egress,
Debug: debug,
Sampling: cfg.Sampling,
CacheMaxSize: cfg.CacheMaxFlows,
EnablePCA: cfg.EnablePCA,
FilterConfig: &ebpf.FilterConfig{
Expand Down
Binary file modified pkg/ebpf/bpf_arm64_bpfel.o
Binary file not shown.
Binary file modified pkg/ebpf/bpf_powerpc_bpfel.o
Binary file not shown.
Binary file modified pkg/ebpf/bpf_s390_bpfeb.o
Binary file not shown.
Binary file modified pkg/ebpf/bpf_x86_bpfel.o
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/ebpf/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ func NewPacketFetcher(cfg *FlowFetcherConfig) (*PacketFetcher, error) {
}

if err := spec.RewriteConstants(map[string]interface{}{
constSampling: uint32(cfg.Sampling),
constPcaEnable: uint8(pcaEnable),
}); err != nil {
return nil, fmt.Errorf("rewriting BPF constants definition: %w", err)
Expand Down

0 comments on commit e318d16

Please sign in to comment.