Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

belimawr
Copy link
Contributor

@belimawr belimawr commented Oct 15, 2024

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

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

## Disruptive User Impact

Author's Checklist

  • Ensure TestInputParsers from filebeat/input/journald/input_parsers_test.go is not flaky
  • Add tests to ensure messages from all boots are read

How to test this PR locally

1. Run the tests

cd filebeat/input/journald
go test -run=TestInputCanReadAllBoots

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:

journalctl --file filebeat/input/journald/testdata/multiple-boots.export

3. Fully manual test

  1. Run the journald input on a machine (or a journal file) that has got messages from more than one boot
  2. Ensure all messages in the journal are correctly ingested.

Related issues

## Use cases
## Screenshots
## Logs

@belimawr belimawr added bug skip-ci Skip the build in the CI but linting Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team labels Oct 15, 2024
@belimawr belimawr self-assigned this Oct 15, 2024
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Oct 15, 2024
Copy link
Contributor

mergify bot commented Oct 15, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b 41083-journald-input-all-boots upstream/41083-journald-input-all-boots
git merge upstream/main
git push upstream 41083-journald-input-all-boots

Copy link
Contributor

mergify bot commented Oct 15, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @belimawr? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Oct 15, 2024

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Oct 15, 2024
@belimawr belimawr force-pushed the 41083-journald-input-all-boots branch from c6cee3e to 2c39ac0 Compare October 15, 2024 19:15
@belimawr belimawr removed the skip-ci Skip the build in the CI but linting label Oct 15, 2024
@belimawr belimawr force-pushed the 41083-journald-input-all-boots branch from 21360eb to 30c8299 Compare October 18, 2024 20:53
Copy link
Contributor

mergify bot commented Oct 18, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b 41083-journald-input-all-boots upstream/41083-journald-input-all-boots
git merge upstream/main
git push upstream 41083-journald-input-all-boots

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.
@belimawr belimawr force-pushed the 41083-journald-input-all-boots branch from 6012cb8 to 1a91677 Compare October 18, 2024 21:20
@belimawr belimawr marked this pull request as ready for review October 18, 2024 21:21
@belimawr belimawr requested a review from a team as a code owner October 18, 2024 21:21
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@pierrehilbert pierrehilbert requested review from mauri870 and removed request for khushijain21 October 20, 2024 16:24
Comment on lines +62 to +70
// 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)
}
Copy link
Member

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

Copy link
Member

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?

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Journald input only ingests events from the current boot
3 participants