-
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
Only start Journald input with supported systemd versions #39605
Only start Journald input with supported systemd versions #39605
Conversation
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) |
This pull request is now in conflicts. Could you fix it? 🙏
|
7a1460c
to
32d12e3
Compare
I converted this PR to draft because we still need to decide how if we want to move forward with D-Bus and the best way to test it. |
The Systemd D-Bus documentation clearly states the version property should not be parsed because its scheme may change and it is not part of the API.
However, it seems to be stable enough among the versions I manually tested:
So I believe it is safe to move forward using it. It does add the D-Bus dependency to the Journald input, which I believe is not a problem to run the input, but we will need to make some changes in CI to run the tests. |
c959999
to
d5e4f5d
Compare
5f1e184
to
c9e178c
Compare
I'm putting this PR back in draft because I started testing the behaviour when running under Elastic-Agent I found out the D-Bus package we're using in Beats requires I'm investigating if |
This commit adds a flag to ignore the Systemd version check for the Journald input. The mage targets are updated so the Journald input unit tests always run. The tests disable the Systemd version check so we can run the tests in our current hosts.
9159c8d
to
1b77913
Compare
Using |
This pull request is now in conflicts. Could you fix it? 🙏
|
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.
the blocker is just the typo
apart from that, there is a question for you to answer
// getSystemdVersionViaDBus gets the Systemd version from sd-bus | ||
// | ||
// The Systemd D-Bus documentation states: | ||
// | ||
// Version encodes the version string of the running systemd | ||
// instance. Note that the version string is purely informational, | ||
// it should not be parsed, one may not assume the version to be | ||
// formatted in any particular way. We take the liberty to change | ||
// the versioning scheme at any time and it is not part of the API. | ||
// Source: https://www.freedesktop.org/wiki/Software/systemd/dbus/ |
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.
[Question]
Then why to use dbus to get the version? Is it the most generic way of doing that across all linux distros?
func systemdVersion() (int, error) { | ||
versionStr, err := getSystemdVersionViaDBus() | ||
if err != nil { | ||
return 0, fmt.Errorf("caanot get Systemd version: %w", err) |
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.
Typo
return 0, fmt.Errorf("caanot get Systemd version: %w", err) | |
return 0, fmt.Errorf("cannot get Systemd version: %w", err) |
// TestJournald executes the Journald input tests | ||
// Use TEST_COVERAGE=true to enable code coverage profiling. | ||
// Use RACE_DETECTOR=true to enable the race detector. | ||
func TestJournaldInput(ctx context.Context) error { | ||
utArgs := devtools.DefaultGoTestUnitArgs() | ||
utArgs.Packages = []string{"../../filebeat/input/journald"} | ||
if devtools.Platform.GOOS == "linux" { | ||
utArgs.ExtraFlags = append(utArgs.ExtraFlags, "-tags=withjournald") | ||
} | ||
|
||
return devtools.GoTest(ctx, utArgs) | ||
} |
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.
Isn't a way to avoid duplicating that?
// The function will parse and return the 3 digit major version, minor version | ||
// and patch are ignored. | ||
func parseSystemdVersion(ver string) (int, error) { | ||
re := regexp.MustCompile(`(v)?(?P<version>\d\d\d)(\.)?`) |
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.
the 3 digits makes me a little nervous, if systemd goes to 4 this all breaks.
^(?P<version>\d{3,})
works with the examples provided. thoughts?
@AndersonQ, @leehinman thank you so much for the reviews! I was discussing with Craig and due to other issues and inconsistencies in versions and behaviour/crashes we face when calling libsystemd n the Systemd version across the supported Linux distribution, we decided to call OpenTelemetry calls So I'll close this PR in favour of #39820 that will be a real fix for #34077 instead of just a mitigation. |
Proposed commit message
Systemd/Journald has a bug that will cause Filebeat to be killed by a SIGBUS when reading from rotated logs. This bug is fixed in Systemd v255.
This commit checks the Systemd version when a Journald input is instantiated, if it is not supported, then then the input creation fails. A warning was added to the documentation stating the minimal version of Systemd.
It is possible to disable the Systemd version check by passing the
--ignore-journald-version
CLI flag.A Ubuntu 2204 Vagrant Box is added for testing.
Checklist
I have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Disruptive User Impact
Filebeat will refuse to start if a Journald input is configured and the host is running an unsupported version of Journald.
There should be no disruptions for the current users because the Journald input is still in technical preview.
When running Elastic-Agent and using the "Custom Journald logs" integration, there is no way to disable the current Systemd version check.
Author's Checklist
fork
system call?How to test this PR locally
Start two VMs: Ubuntu 2204 and Archlinux
SSH into the Archlinux VM and update the system to get the fixed version of Systemd and install other dependencies
Run the tests
Build Filebeat with Journald support (you can do this from within the VM):
Run Filebeat in each VM:
./filebeat -e -v
using the followingfilebeat.yml
filebeat.yml
Assert that:
Related issues
## Use casesScreenshots
When running under Elastic-Agent on hosts with Systemd < v255, the Journald input will not start and will correctly report the error/reason.
Screenshots from various Linux distributions
Logs
Filebeat will fail to start with: