[8.19](backport #50324) filebeat: add read_until_eof to filestream#51206
Conversation
|
Cherry-pick of 14ddacb has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
🤖 GitHub commentsJust comment with:
|
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
|
Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services) |
TL;DRThe Buildkite failure is caused by unresolved Git merge-conflict markers committed into this backport branch, so Remediation
Investigation detailsRoot CauseThis is a configuration/backport conflict-resolution issue (not a runtime code regression): the PR branch contains raw merge conflict markers. Confirmed by CI log output from
Evidence
Verification
Follow-upAfter conflict resolution, ensure the backported docs/file deletions referenced by Mergify’s conflict summary are reconciled consistently with What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
|
This pull request has not been merged yet. Could you please review and merge it @AndersonQ? 🙏 |
1 similar comment
|
This pull request has not been merged yet. Could you please review and merge it @AndersonQ? 🙏 |
There was a problem hiding this comment.
The docs changes need to be ported to the asciidoc file: filebeat/docs/inputs/input-filestream.asciidoc.
|
This pull request has not been merged yet. Could you please review and merge it @AndersonQ? 🙏 |
a6ae908 to
435bcd8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
01b81c4 to
7c45a8e
Compare
This comment has been minimized.
This comment has been minimized.
4641373 to
8144c33
Compare
This comment has been minimized.
This comment has been minimized.
8144c33 to
e31a74c
Compare
Add a new `read_until_eof` option that defers a filestream input's shutdown until the file currently being harvested reaches EOF (or a configurable timeout fires). When the input is cancelled — for example by a Kubernetes autodiscover provider removing the input on pod termination — the harvester previously exited immediately and any unread bytes were lost. With `read_until_eof.enabled: true`, the harvester finishes draining the file before exiting. Approach: * `logFile` gets a one-shot `startReadUntilEOF` method that stops the file-monitoring goroutines (close.on_state_change.* / close.reader.after_interval), swaps the reader's cancellation context for one scoped to `read_until_eof.timeout`, and sets `closeOnEOF=true`. `sync.Once` makes the swap idempotent and guarantees that, by the time it returns, the monitoring goroutines cannot race with the swapped-in context. * `readFromSource` now has a normal read loop and, when the feature is enabled, a `read_until_eof` continuation. When the normal loop exits because `ctx.Cancelation` was cancelled, `handleReadError` recognises the resulting `ErrClosed` and falls through to the continuation: `startReadUntilEOF` is invoked with a fresh read-until-EOF-scoped context and the loop resumes until EOF or timeout. * The harvester's publisher canceler is `nil` while the feature is enabled, so a `Publish` that returns after backpressure releases does not surface `context.Canceled` and short-circuit the continuation. * The harvester task-group's stop deadline is extended by `read_until_eof.timeout + 100ms` so the drain is not killed prematurely. Assisted-By: Claude (cherry picked from commit 14ddacb) # Conflicts: # docs/reference/filebeat/filebeat-input-filestream.md # filebeat/input/filestream/config.go # filebeat/input/filestream/config_test.go # filebeat/input/filestream/filestream_test.go # filebeat/input/filestream/input.go # filebeat/input/filestream/internal/input-logfile/input.go # filebeat/input/filestream/internal/input-logfile/manager.go # filebeat/testing/integration/log_generator.go
e31a74c to
71ff5fd
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
TL;DR
Remediation
Investigation detailsRoot CauseThis backport has progressed past the earlier typecheck and broad lint failures, but conflict-resolution cleanup is still incomplete. The current Evidence
Validation
Follow-up
What is this? | From workflow: PR Actions Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
|
Tick the box to add this pull request to the merge queue (same as
|
Proposed commit message
Checklist
stresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.Disruptive User Impact
None, last lines on a file will not be missed and the input might take a bit longer to close.
The new option is enabled by default.
When the option is set, the only observable behaviour change is the input taking up to
read_until_eof.timeoutlonger to exit on cancellation. Output / pipeline shutdown semantics are unchanged.How to test this PR locally
The realistic scenario the feature targets is reproduced by
TestFilestreamReadUntilEOFOnInputStopinfilebeat/tests/integration/filestream_read_until_eof_test.go. To run it:The faster in-process integration suite covers the timeout fallback, the no-close-on-EOF (tail) path, gzip files, file-deletion-during-drain, and a pure happy path:
The unit suite locks down
startReadUntilEOFsemantics,handleReadError'sErrClosedbridge, and the config:Manual end-to-end exercise (autodiscover-style):
filebeat.config.inputs: { path: inputs.d/*.yml, reload.enabled: true }and an output that can be made to apply backpressure.inputs.d/with a large file,read_until_eof.enabled: true,read_until_eof.timeout: 1m.mock-eswithpercentTooMany=100).mv inputs.d/x.yml inputs.d/x.yml.disabled) so the reload removes the input.Related issues
Use cases
Kubernetes autodiscover with short-lived pods. A pod terminates while filebeat is still reading its log file. Without
read_until_eof, the input is removed mid-read and the tail of the file is lost. Withread_until_eof.enabled: true(the default), the harvester finishes the file before the input exits, and the Kubernetes-bound metadata is still attached because the input itself has not yet been torn down.Reload-driven input removal in any deployment. Any time the input set is reduced (config reload, autodiscover, central management), the removed inputs now have a bounded grace window to finish their current file rather than dropping bytes.
## ScreenshotsLogs
The drain emits three messages, with
read_until_eof:This is an automatic backport of pull request #50324 done by [Mergify](https://mergify.com).