-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read journal entries from all boots #41244
base: main
Are you sure you want to change the base?
Conversation
This pull request is now in conflicts. Could you fix it? 🙏
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
c6cee3e
to
2c39ac0
Compare
21360eb
to
30c8299
Compare
This pull request is now in conflicts. Could you fix it? 🙏
|
Some versions of journalctl will only return messages from the current boot when --follow is passed, it will even ignore the cursor or date arguments. This commit reads messages from all boots by first calling journalctl without the --follow flag, reading all entries and once it successfully exits, then we restart journalctl with the cursor and the --follow flag.
This commit updates the parse test to use ndjson parser instead of multiline because the multiline parser can have issues when journald input is reading from files. There is a corner case where the journalctl exits successfully and the reader goroutine gets an error, this makes Next to return early, making the multiline to also return early. So far I have only seen this happening when reading from file and at the very end of the file, hence it does not seem to be a critical bug.
6012cb8
to
1a91677
Compare
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
// The JSON in the test journal is: '{"foo": "bar", "answer":42}' | ||
expectedFoo := "bar" | ||
expectedAnswer := int64(42) | ||
if foo != expectedFoo { | ||
t.Errorf("expecting foo to be '%s' got '%s' instead", expectedFoo, foo) | ||
} | ||
if answer != expectedAnswer { | ||
t.Errorf("expecting foo to be '%d' got '%d' instead", expectedAnswer, answer) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: You might be able to simplify this by using assert.JSONEq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 megabytes is quite huge to put under version control, is that standard behavior for test files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the alternative is to only run the test on journald-enabled systems and compare with the live output.
Proposed commit message
Some versions of journalctl will only return messages from the current boot when --follow is passed, it will even ignore the cursor or date arguments.
This commit reads messages from all boots by first calling journalctl without the --follow flag, reading all entries and once it successfully exits, then we restart journalctl with the cursor and the --follow flag.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.## Disruptive User ImpactAuthor's Checklist
TestInputParsers
fromfilebeat/input/journald/input_parsers_test.go
is not flakyHow to test this PR locally
1. Run the tests
2. Run Filebeat reading
filebeat/input/journald/testdata/multiple-boots.journal
There must be 6 entries, you can see the plaintext entries by looking at
filebeat/input/journald/testdata/multiple-boots.export
or by running:3. Fully manual test
Related issues
## Use cases## Screenshots## Logs