Add helper methods to support kafka output in beatreceivers#49768
Add helper methods to support kafka output in beatreceivers#49768khushijain21 wants to merge 13 commits intoelastic:mainfrom
Conversation
🤖 GitHub commentsJust comment with:
|
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe PR exports previously internal symbols and refactors token parsing. parseEventPath was renamed to ParseEventPath. makeLexer was renamed to MakeLexer and gained a bounds check and corrected two-byte operator slicing. Parsing was refactored into a generic parseFormatTokens loop with a new parseVariableToken helper. A new exported type VariableToken and function ParseRawTokens were added. Tests and a fuzz test for ParseRawTokens were included. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libbeat/common/fmtstr/formatstring.go`:
- Around line 340-365: ParseRawTokens can return early and leave the lexer
producer goroutine blocked; ensure we always drain lex.Tokens() on any early
exit by adding a deferred drain. At the top of ParseRawTokens, add a defer that
iterates over lex.Tokens() and discards remaining tokens (for range lex.Tokens()
{ }) unless the function completes normally; mark normal completion (e.g., a
local done flag set to true just before the final return) so the deferred drain
only runs on error/early returns. This ensures any early returns from cases like
tokErr or parseVariableToken failures do not leak the goroutine started by
MakeLexer while keeping normal behavior for the existing token handling
(tokString, tokOpen, tokClose, tokOperator) and existing use of
parseVariableToken and VariableToken.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6a04693a-87bf-405a-8074-0a210fd48f5c
📒 Files selected for processing (3)
libbeat/common/fmtstr/formatevents.golibbeat/common/fmtstr/formatstring.golibbeat/common/fmtstr/formatstring_test.go
belimawr
left a comment
There was a problem hiding this comment.
Overall LGMT, but I agree with Mauri, a more exhaustive test for ParseRawTokens would be great.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
libbeat/common/fmtstr/formatstring.go (1)
351-361:⚠️ Potential issue | 🟠 MajorGoroutine leak:
ParseRawTokensmust drain lexer on early exit.
MakeLexerspawns a goroutine. If parsing fails mid-stream (e.g.,errNestedVarat line 378), this function returns without draininglex.Tokens(), blocking the producer indefinitely.Proposed fix
func ParseRawTokens(lex lexer) ([]any, error) { + defer lex.Finish() return parseFormatTokens(lex, func(elems *[]any, s string) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libbeat/common/fmtstr/formatstring.go` around lines 351 - 361, ParseRawTokens can return early while MakeLexer’s producer goroutine is still sending tokens, causing a goroutine leak; ensure the lexer channel is drained on any early return. Change ParseRawTokens so after calling parseFormatTokens it checks for a non-nil error and if present iterates over lex.Tokens() to exhaust the channel (e.g., for range lex.Tokens() {} ) before returning the error; reference functions: ParseRawTokens, parseFormatTokens and the lex.Tokens() method, and preserve existing return values (including wrapping/returning the original error).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@libbeat/common/fmtstr/formatstring.go`:
- Around line 351-361: ParseRawTokens can return early while MakeLexer’s
producer goroutine is still sending tokens, causing a goroutine leak; ensure the
lexer channel is drained on any early return. Change ParseRawTokens so after
calling parseFormatTokens it checks for a non-nil error and if present iterates
over lex.Tokens() to exhaust the channel (e.g., for range lex.Tokens() {} )
before returning the error; reference functions: ParseRawTokens,
parseFormatTokens and the lex.Tokens() method, and preserve existing return
values (including wrapping/returning the original error).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 23c8ab50-cf3a-4536-b190-bc8c098334cd
📒 Files selected for processing (2)
libbeat/common/fmtstr/formatstring.golibbeat/common/fmtstr/formatstring_test.go
✅ Files skipped from review due to trivial changes (1)
- libbeat/common/fmtstr/formatstring_test.go
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
libbeat/common/fmtstr/formatstring.go (1)
351-361:⚠️ Potential issue | 🔴 CriticalDrain lexer on
ParseRawTokenserror paths to prevent goroutine leaks.At Line 351,
ParseRawTokenscan return early (malformed input) without draininglex.Tokens(). BecauseMakeLexeruses a producer goroutine, this can leak blocked goroutines.Proposed fix
func ParseRawTokens(lex lexer) ([]any, error) { + defer lex.Finish() return parseFormatTokens(lex, func(elems *[]any, s string) { *elems = append(*elems, s) }, func(lex lexer) (any, error) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libbeat/common/fmtstr/formatstring.go` around lines 351 - 361, ParseRawTokens can return early leaving the lexer producer goroutine blocked; when parseFormatTokens returns an error you must start a background goroutine to fully drain lex.Tokens() before returning to avoid leaking the producer. Modify ParseRawTokens so after calling parseFormatTokens you check the returned error and if non-nil spawn a goroutine that ranges over lex.Tokens() (for range lex.Tokens() { }) to consume remaining tokens, then return the error; reference the ParseRawTokens function, the lex parameter (type lexer) and lex.Tokens() channel and ensure this drain happens on all error return paths from ParseRawTokens.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@libbeat/common/fmtstr/formatstring.go`:
- Around line 351-361: ParseRawTokens can return early leaving the lexer
producer goroutine blocked; when parseFormatTokens returns an error you must
start a background goroutine to fully drain lex.Tokens() before returning to
avoid leaking the producer. Modify ParseRawTokens so after calling
parseFormatTokens you check the returned error and if non-nil spawn a goroutine
that ranges over lex.Tokens() (for range lex.Tokens() { }) to consume remaining
tokens, then return the error; reference the ParseRawTokens function, the lex
parameter (type lexer) and lex.Tokens() channel and ensure this drain happens on
all error return paths from ParseRawTokens.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2d66f647-ac32-4cd9-bce7-d96960240585
📒 Files selected for processing (2)
libbeat/common/fmtstr/formatstring.golibbeat/common/fmtstr/formatstring_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- libbeat/common/fmtstr/formatstring_test.go
Co-authored-by: Orestis Floros <orestisflo@gmail.com>
Co-authored-by: Orestis Floros <orestisflo@gmail.com>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
TL;DRBuildkite failed because Remediation
Investigation detailsRoot Cause
The failure is enforced by:
Evidence
Verification
Follow-upIf the file still changes after Note 🔒 Integrity filtering filtered 1 itemIntegrity filtering activated and filtered the following item during workflow execution.
What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
Proposed commit message
This PR adds helper methods on
fmtstrpackage to help parse dynamic fields. This is required to support kafka output on beatreceiversChecklist
stresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.Disruptive User Impact
None
Related issues