Skip to content

feat(packetparser): use ring buffer back-pressure#2208

Open
holly-agyei wants to merge 1 commit intomicrosoft:mainfrom
holly-agyei:feat-1967-adaptive-sampling
Open

feat(packetparser): use ring buffer back-pressure#2208
holly-agyei wants to merge 1 commit intomicrosoft:mainfrom
holly-agyei:feat-1967-adaptive-sampling

Conversation

@holly-agyei
Copy link
Copy Markdown

Description

This updates packetparser so ring buffer mode uses ring buffer back-pressure instead of the static dataSamplingRate.

When packetParserRingBuffer=enabled, Retina now:

  • skips DATA_SAMPLING_RATE in the generated header
  • emits events with bpf_ringbuf_reserve() and bpf_ringbuf_submit()
  • drops events only when the ring buffer is full
  • keeps the current sampling behavior for perf event arrays

This also adds tests for both paths and updates the docs to explain how dataSamplingRate and packetParserRingBufferSize behave in each mode.

Related Issue

Related to #1966
Related to #655

Checklist

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary.
  • I have added tests, if applicable.

Screenshots (if applicable) or Testing Completed

  • go generate ./pkg/plugin/...
  • go generate ./...
  • golangci-lint with GOOS=linux GOARCH=amd64
  • golangci-lint with GOOS=linux GOARCH=arm64
  • go build ./... with GOOS=linux GOARCH=amd64
  • go build ./... with GOOS=linux GOARCH=arm64
  • go test -c ./pkg/plugin/packetparser with GOOS=linux GOARCH=amd64
  • go test -c ./pkg/plugin/packetparser with GOOS=linux GOARCH=arm64
  • go test -tags=ebpf -c ./pkg/plugin/packetparser with GOOS=linux GOARCH=amd64
  • go test -tags=ebpf -c ./pkg/plugin/packetparser with GOOS=linux GOARCH=arm64
  • markdownlint-cli2 on the updated docs

Additional Notes

  • dataSamplingRate still applies to the perf event array path.
  • packetParserRingBufferSize controls burst capacity in ring buffer mode.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the packetparser plugin so that when packetParserRingBuffer=enabled, event dropping is governed by ring buffer back-pressure (reserve/submit) rather than the static dataSamplingRate, while keeping existing sampling behavior for the perf event array path.

Changes:

  • Skip generating DATA_SAMPLING_RATE in dynamic.h when ring buffer mode is enabled; keep it for perf event arrays.
  • Switch ring buffer emission to bpf_ringbuf_reserve() / bpf_ringbuf_submit() and disable sampling logic under ring buffer mode in the eBPF program.
  • Add/adjust tests and documentation to cover and explain the different behaviors in perf vs ring buffer mode.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/plugin/packetparser/packetparser_linux.go Omits DATA_SAMPLING_RATE define in ring buffer mode; logs that sampling is ignored for ring buffer.
pkg/plugin/packetparser/packetparser_linux_test.go Adds a header-generation test ensuring ring buffer mode ignores dataSamplingRate.
pkg/plugin/packetparser/packetparser_ebpf_test.go Updates variant compilation to omit DATA_SAMPLING_RATE under ring buffer; adds tests for perf sampling vs ring buffer behavior.
pkg/plugin/packetparser/_cprog/packetparser.c Introduces a unified emit helper and switches ring buffer path to reserve/submit; disables sampling when USE_RING_BUFFER is set.
docs/06-Troubleshooting/performance.md Documents ring buffer back-pressure as a performance option; clarifies sampling behavior by mode.
docs/03-Metrics/plugins/Linux/packetparser.md Updates performance considerations to recommend ring buffers; clarifies that sampling is ignored in ring buffer mode.
docs/02-Installation/03-Config.md Clarifies dataSamplingRate applies only when ring buffers are disabled; documents ring buffer behavior.
docs/01-Introduction/01-intro.md Updates guidance for high-core/high-throughput nodes to prefer ring buffers.
deploy/standard/manifests/controller/helm/retina/values.yaml Adds comments clarifying dataSamplingRate is ignored in ring buffer mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +868 to +874
func TestHighAggregationSamplingSuppressesPerfBufferEvents(t *testing.T) {
objs, reader := compileAndLoadVariant(t, compileOpts{
bypassFilter: 1,
enableConntrack: false,
aggregationLevel: 1, // HIGH
samplingRate: 2147483647, // effectively never sampled
})
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestHighAggregationSamplingSuppressesPerfBufferEvents relies on bpf_get_prandom_u32() for sampling and then asserts the ACK event is not emitted. Even with a very large samplingRate, there is still a non-zero chance the ACK is sampled and emitted, which can make this test flaky over enough CI runs. Consider making the assertion deterministic by avoiding a single random trial (e.g., send many ACK packets and assert fewer than N events were emitted, or add a test-only compile flag/hook to force sampling on/off).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@holly-agyei
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/plugin/packetparser/packetparser_ebpf_test.go Outdated
@holly-agyei holly-agyei force-pushed the feat-1967-adaptive-sampling branch from 9fda7df to 652930b Compare April 18, 2026 23:03
Signed-off-by: Agyei Holy <agyeiholy978@gmail.com>
@holly-agyei holly-agyei force-pushed the feat-1967-adaptive-sampling branch from 652930b to 0cff9d0 Compare April 18, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants