Skip to content

Enable Filebeat's Journald input in some docker image variants #7995

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

Merged
merged 37 commits into from
Jun 12, 2025

Conversation

belimawr
Copy link
Contributor

@belimawr belimawr commented Apr 25, 2025

What does this PR do?

Filebeat's Journald input requires journalctl, so the systemd package is added to all docker image variants.

Changes in image size

Images built from main (f108618):

docker.elastic.co/elastic-agent/elastic-agent-complete         9.1.0-SNAPSHOT         123d3a5d0a22   2 hours ago   3.57GB
docker.elastic.co/elastic-agent/elastic-otel-collector         9.1.0-SNAPSHOT         a5182ef34ae0   2 hours ago   1.2GB
docker.elastic.co/elastic-agent/elastic-agent                  9.1.0-SNAPSHOT         cf9309afdc3f   2 hours ago   1.89GB

Images built from this PR:

docker.elastic.co/elastic-agent/elastic-agent-complete         9.1.0-SNAPSHOT         18845462f221   16 minutes ago   3.58GB
docker.elastic.co/elastic-agent/elastic-otel-collector         9.1.0-SNAPSHOT         2f29d6c0f17a   18 minutes ago   1.25GB
docker.elastic.co/elastic-agent/elastic-agent                  9.1.0-SNAPSHOT         d5b99148748a   18 minutes ago   1.94GB

Increase in size

  • docker.elastic.co/elastic-agent/elastic-agent-complete: 10MB
  • docker.elastic.co/elastic-agent/elastic-otel-collector: 50MB
  • docker.elastic.co/elastic-agent/elastic-agent: 40MB

Why is it important?

Currently it is only possible to use integrations that requires the journald input with the complete docker image variant, this PR allows it to be used with any docker image variant. The complete docker image is the largest with more than 3Gb, while the standard Elastic-Agent image is less than 2Gb.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • 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/fragments using the changelog tool
  • I have added an integration test or an E2E test

## Disruptive User Impact

Author's Checklist

  • Add integration test for each docker image: mount the journal into the container and ensure the Journald input can read it.

How to test this PR locally

  1. Package the Elastic-Agent:
    DEV=true SNAPSHOT=true EXTERNAL=true PACKAGES="docker" PLATFORMS=linux/amd64 mage -v package
    
  2. Check the version of journalctl on each docker image by running the following script/commands:
    #!/bin/bash
    
    echo "############################## Testing images with journalctl ##############################"
    
    set -o xtrace
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-agent-complete:9.1.0-SNAPSHOT  --version
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-agent-ubi:9.1.0-SNAPSHOT  --version
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-agent:9.1.0-SNAPSHOT  --version
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-otel-collector:9.1.0-SNAPSHOT  --version
    
    set +o xtrace
    echo "############################## Testing images without journalctl ##############################"
    
    set -o xtrace
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-agent-complete-wolfi:9.1.0-SNAPSHOT  --version
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-agent-slim-wolfi:9.1.0-SNAPSHOT  --version
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-agent-slim:9.1.0-SNAPSHOT  --version
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-agent-wolfi:9.1.0-SNAPSHOT  --version
    docker run --rm -it --entrypoint journalctl docker.elastic.co/elastic-agent/elastic-otel-collector-wolfi:9.1.0-SNAPSHOT  --version
    
  3. Alternatively, check the Dockerfile for each of the images:
    grep "systemd" build/package/elastic-*/*/docker-build/Dockerfile

Related issues

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

Filebeat's Journald input requires `journalctl`, so the systemd
package is added to all docker image variants.
Copy link
Contributor

mergify bot commented Apr 25, 2025

This pull request does not have a backport label. Could you fix it @belimawr? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@belimawr belimawr added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team backport-active-all Automated backport with mergify to all the active branches labels Apr 25, 2025
@belimawr belimawr marked this pull request as ready for review April 25, 2025 21:28
@belimawr belimawr requested a review from a team as a code owner April 25, 2025 21:28
@belimawr belimawr requested review from ycombinator and pchila April 25, 2025 21:28
@elasticmachine
Copy link
Collaborator

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

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Apr 27, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@rdner
Copy link
Member

rdner commented Apr 28, 2025

@belimawr please add the image size comparison to the description.

Copy link
Member

@cmacknz cmacknz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep this (size dependent), it definitely shouldn't be in the slim variant at least.

@pkoutsovasilis
Copy link
Contributor

pkoutsovasilis commented Apr 30, 2025

So I went ahead and found my notes from when we did the initial switch from ubuntu-based to ubi-based images, and I remembered the quirks with journalctl and systemd package. To this end, journalctl is only part of the systemd package and it's not something that we can install standalone.

I built all images with this PR and this is the comparison the images from main, in terms of size:

arm64:

docker.elastic.co/elastic-agent/elastic-agent-complete         with-systemd-PR-9.1.0-SNAPSHOT   693b6e89332b   2 hours ago     3.33GB
docker.elastic.co/elastic-agent/elastic-agent-complete         9.1.0-SNAPSHOT                   002667864129   12 hours ago    3.33GB
docker.elastic.co/beats-ci/elastic-agent-service               with-systemd-PR-9.1.0-SNAPSHOT   bf4763072e2f   2 hours ago     2.3GB
docker.elastic.co/beats-ci/elastic-agent-service               9.1.0-SNAPSHOT                   bf4763072e2f   2 hours ago     2.3GB
docker.elastic.co/beats-ci/elastic-agent-cloud                 with-systemd-PR-9.1.0-SNAPSHOT   134ef9b6eed6   2 hours ago     2.21GB
docker.elastic.co/beats-ci/elastic-agent-cloud                 9.1.0-SNAPSHOT                   134ef9b6eed6   2 hours ago     2.21GB
docker.elastic.co/elastic-agent/elastic-agent-ubi              with-systemd-PR-9.1.0-SNAPSHOT   f6f367b91ffc   2 hours ago     1.67GB   (~ 40MB increase)
docker.elastic.co/elastic-agent/elastic-agent-ubi              9.1.0-SNAPSHOT                   c39e45552f7c   12 hours ago    1.63GB
docker.elastic.co/elastic-agent/elastic-agent                  with-systemd-PR-9.1.0-SNAPSHOT   f6f367b91ffc   2 hours ago     1.67GB   (~ 40MB increase)
docker.elastic.co/elastic-agent/elastic-agent                  9.1.0-SNAPSHOT                   c39e45552f7c   12 hours ago    1.63GB
docker.elastic.co/elastic-agent/elastic-agent-slim             with-systemd-PR-9.1.0-SNAPSHOT   7311176930d6   2 hours ago     1.12GB   (~ 50MB increase)
docker.elastic.co/elastic-agent/elastic-agent-slim             9.1.0-SNAPSHOT                   fc65146d79d6   12 hours ago    1.07GB
docker.elastic.co/elastic-agent/elastic-otel-collector         with-systemd-PR-9.1.0-SNAPSHOT   5eb9b4234489   2 hours ago     1.03GB   (~ 50MB increase)
docker.elastic.co/elastic-agent/elastic-otel-collector         9.1.0-SNAPSHOT                   10f3e676c678   12 hours ago    983MB
docker.elastic.co/elastic-agent/elastic-agent-wolfi            with-systemd-PR-9.1.0-SNAPSHOT   4d3de9efd830   2 hours ago     1.75GB   (~ 170MB increase)
docker.elastic.co/elastic-agent/elastic-agent-wolfi            9.1.0-SNAPSHOT                   c85d302eb13d   12 hours ago    1.58GB
docker.elastic.co/elastic-agent/elastic-agent-slim-wolfi       with-systemd-PR-9.1.0-SNAPSHOT   ac34c798b016   2 hours ago     1.2GB    (~ 180MB increase)
docker.elastic.co/elastic-agent/elastic-agent-slim-wolfi       9.1.0-SNAPSHOT                   d5cd36078fdf   12 hours ago    1.02GB
docker.elastic.co/elastic-agent/elastic-agent-complete-wolfi   with-systemd-PR-9.1.0-SNAPSHOT   1ef4f0086615   2 hours ago     2.97GB   (~ 180MB increase)
docker.elastic.co/elastic-agent/elastic-agent-complete-wolfi   9.1.0-SNAPSHOT                   147828688b56   12 hours ago    2.81GB
docker.elastic.co/elastic-agent/elastic-otel-collector-wolfi   with-systemd-PR-9.1.0-SNAPSHOT   9a7f5b346b99   2 hours ago     1.11GB   (~ 180MB increase)
docker.elastic.co/elastic-agent/elastic-otel-collector-wolfi   9.1.0-SNAPSHOT                   d2a00044c610   12 hours ago    933MB

amd64:

(amd64)
docker.elastic.co/elastic-agent/elastic-agent-complete         with-systemd-PR-9.1.0-SNAPSHOT   6bb84a795044   13 minutes ago  3.37GB   
docker.elastic.co/elastic-agent/elastic-agent-complete         9.1.0-SNAPSHOT                   0000e9ed5f23   12 hours ago    3.37GB   
docker.elastic.co/beats-ci/elastic-agent-service               with-systemd-PR-9.1.0-SNAPSHOT   95e3bfe0941c   13 minutes ago  2.38GB   
docker.elastic.co/beats-ci/elastic-agent-service               9.1.0-SNAPSHOT                   95e3bfe0941c   13 minutes ago  2.38GB   
docker.elastic.co/beats-ci/elastic-agent-cloud                 with-systemd-PR-9.1.0-SNAPSHOT   b889bd89bee4   15 minutes ago  2.31GB   
docker.elastic.co/beats-ci/elastic-agent-cloud                 9.1.0-SNAPSHOT                   b889bd89bee4   15 minutes ago  2.31GB   
docker.elastic.co/elastic-agent/elastic-otel-collector         with-systemd-PR-9.1.0-SNAPSHOT   e77a5648b478   15 minutes ago  1.06GB   (~ 30MB increase)  
docker.elastic.co/elastic-agent/elastic-otel-collector         9.1.0-SNAPSHOT                   46aedf7de7e1   12 hours ago    1.03GB   
docker.elastic.co/elastic-agent/elastic-agent-ubi              with-systemd-PR-9.1.0-SNAPSHOT   fa6b2f661969   15 minutes ago  1.75GB   (~ 30MB increase)  
docker.elastic.co/elastic-agent/elastic-agent-ubi              9.1.0-SNAPSHOT                   b6e665ec531c   12 hours ago    1.72GB   
docker.elastic.co/elastic-agent/elastic-agent                  with-systemd-PR-9.1.0-SNAPSHOT   fa6b2f661969   15 minutes ago  1.75GB   (~ 30MB increase)  
docker.elastic.co/elastic-agent/elastic-agent                  9.1.0-SNAPSHOT                   b6e665ec531c   12 hours ago    1.72GB   
docker.elastic.co/elastic-agent/elastic-agent-slim             with-systemd-PR-9.1.0-SNAPSHOT   58d3dd1d12d1   15 minutes ago  1.16GB   (~ 30MB increase) 
docker.elastic.co/elastic-agent/elastic-agent-slim             9.1.0-SNAPSHOT                   a58865886ade   12 hours ago    1.13GB   
docker.elastic.co/elastic-agent/elastic-agent-wolfi            with-systemd-PR-9.1.0-SNAPSHOT   fdaf4fa8a0ac   15 minutes ago  1.82GB   (~ 160MB increase)
docker.elastic.co/elastic-agent/elastic-agent-wolfi            9.1.0-SNAPSHOT                   b8f9b0d336ad   12 hours ago    1.66GB   
docker.elastic.co/elastic-agent/elastic-agent-slim-wolfi       with-systemd-PR-9.1.0-SNAPSHOT   464367c5c29c   15 minutes ago  1.24GB   (~ 170MB increase)
docker.elastic.co/elastic-agent/elastic-agent-slim-wolfi       9.1.0-SNAPSHOT                   a4007ffd9dea   12 hours ago    1.07GB   
docker.elastic.co/elastic-agent/elastic-agent-complete-wolfi   with-systemd-PR-9.1.0-SNAPSHOT   4824ac942ad1   13 minutes ago  3GB      (~ 140MB increase)
docker.elastic.co/elastic-agent/elastic-agent-complete-wolfi   9.1.0-SNAPSHOT                   1dcefb2b9c7c   12 hours ago    2.86GB   
docker.elastic.co/elastic-agent/elastic-otel-collector-wolfi   with-systemd-PR-9.1.0-SNAPSHOT   366fc969e3df   15 minutes ago  1.14GB   (~ 170MB increase)
docker.elastic.co/elastic-agent/elastic-otel-collector-wolfi   9.1.0-SNAPSHOT                   2b85fbbb4e34   12 hours ago    973MB   

Just from the above comparisons, and the security-based reasons, I would say that wolfi-based images should not feature systemd. Now for the ubi-based ones, if the on average 50MB of an increase is prohibitive, we could try out having an intermediate step that installs systemd package and copies the bare minimum of journalctl dependencies to the final image

$ du -sh /usr/bin/journalctl
132K    /usr/bin/journalctl
$ du -sh /usr/lib/aarch64-linux-gnu/systemd/libsystemd-shared-255.so
3.8M    /usr/lib/aarch64-linux-gnu/systemd/libsystemd-shared-255.so
$ readelf -d /usr/bin/journalctl | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libsystemd-shared-255.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-aarch64.so.1]

I have to test the above out but AFAIK journalctl either connects to the /run/systemd/journal/socket, host path that needs to be mounted, and/or reads persistent journal files on disk /var/log/journal/*

PS: I would also propose introducing a k8s integration test that tests the journald input 🙂

@cmacknz
Copy link
Member

cmacknz commented May 2, 2025

IMO based on the above we keep systemd out of the slim, service, and wolfi variants.

We would add systemd/journald to the plain elastic-agent (and elastic-agent-ubi) and the elastic-otel-collector since the collector needs journald for the same reason. This removes the need to deploy the complete variant and preserve the main properties of slim (smallest size) and wolfi (minimal dependencies and CVEs) variants.

@cmacknz
Copy link
Member

cmacknz commented May 2, 2025

(service has no need for journald/systemd it's the agentless container).

Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @cmacknz assessment, adding systemd to all docker images is not what we want to do, please try to limit the addition to only some of the variants and not to the security/size focused ones.

@belimawr
Copy link
Contributor Author

belimawr commented May 9, 2025

Thanks for the input folks!

I believe we should add systemd/journalctl in the slim variant as well as the size increase is very small. How slim does the slim image need to be?

Based on @pkoutsovasilis numbers, adding systemd in the slim image is a 30Mb increase on a 1.13Gb, this means 2.65% increase in size, however if a user needs the journald input and migrates from the slim to the ubi variant, that means jumping from 1.13Gb to 1.75Gb, a 54.88% increase, that's a significant change.

If the user wants to monitor their Kubernetes cluster, I'd expect them to also want to collect the system logs, and if the logs are on journald, then they will need the journald input. So it looks to be this is a very important use case.

Do we have any numbers on this use case and which image was being used before we introduced the need for journalctl in the docker image?

In the mean time, I'll look into adding systemd based on the image variant.

@cmacknz
Copy link
Member

cmacknz commented May 20, 2025

I believe we should add systemd/journalctl in the slim variant as well as the size increase is very small. How slim does the slim image need to be?

It needs to be as small as possible while still being useful. That including systemd is a marginal increase is a hint that we need to remove other things not that we can include any arbitrary thing that is 10-50 MB in size because the image is too huge as a starting point.

Everyone with this use case is already using the plain elastic-agent image because -slim was only available in 9.0 so we aren't breaking anything.

We can put journald in later if people tell us it is critical requirement, but removing it later based on an assumption will be a breaking change if we do it too early.

cmacknz
cmacknz previously approved these changes Jun 10, 2025
@belimawr belimawr changed the title Enable Filebeat's Journald input in all docker image variants Enable Filebeat's Journald input in some docker image variants Jun 10, 2025
Copy link

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @belimawr

@belimawr belimawr requested review from cmacknz and pchila June 12, 2025 16:31
@belimawr belimawr added backport-8.18 Automated backport to the 8.18 branch backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches and removed backport-active-all Automated backport with mergify to all the active branches backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches labels Jun 12, 2025
@belimawr
Copy link
Contributor Author

@cmacknz, regarding backports, I'm thinking about only backporting to 8.18 as all the other active branches have journalctl at least in the complete image, which makes this PR more of a feature addition than bug fix.

Some context: #8445

What do you think?

@belimawr belimawr merged commit fd33d85 into elastic:main Jun 12, 2025
15 checks passed
mergify bot pushed a commit that referenced this pull request Jun 12, 2025
Filebeat's Journald input requires `journalctl`, so the systemd
package is added to elastic-agent, elastic-agent-complete, elastic-otel-collector variants.

---------

Co-authored-by: Craig MacKenzie <[email protected]>
(cherry picked from commit fd33d85)

# Conflicts:
#	dev-tools/packaging/settings.go
#	dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl
@cmacknz
Copy link
Member

cmacknz commented Jun 13, 2025

@cmacknz, regarding backports, I'm thinking about only backporting to 8.18 as all the other active branches have journalctl at least in the complete image, which makes this PR more of a feature addition than bug fix.

I think that makes sense, if users ask about fixing it in the other versions we can consider going back even further.

Though by the same logic, shouldn't 8.18 just have it in the complete image to match 9.0 and this change only lands in 9.1 and 8.19?

@belimawr belimawr added the backport-8.19 Automated backport to the 8.19 branch label Jun 13, 2025
@belimawr
Copy link
Contributor Author

Though by the same logic, shouldn't 8.18 just have it in the complete image to match 9.0 and this change only lands in 9.1 and 8.19?

That makes sense.

I'll change the backport to 8.18 to only include it in the complete image. And create one to 8.19 with all other images.

mergify bot pushed a commit that referenced this pull request Jun 13, 2025
Filebeat's Journald input requires `journalctl`, so the systemd
package is added to elastic-agent, elastic-agent-complete, elastic-otel-collector variants.

---------

Co-authored-by: Craig MacKenzie <[email protected]>
(cherry picked from commit fd33d85)

# Conflicts:
#	dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl
belimawr added a commit that referenced this pull request Jun 17, 2025
…er image variants (#8492)

Filebeat's Journald input requires `journalctl`, so the systemd
package is added to elastic-agent, elastic-agent-complete,variants.

---------

Co-authored-by: Craig MacKenzie <[email protected]>
(cherry picked from commit fd33d85)

# Conflicts:
#	dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl

---------

Co-authored-by: Tiago Queiroz <[email protected]>
pkoutsovasilis added a commit that referenced this pull request Jun 18, 2025
…r image variants (#8482)

* Enable Filebeat's Journald input in some docker image variants (#7995)

Filebeat's Journald input requires `journalctl`, so the systemd
package is added to elastic-agent, elastic-agent-complete, elastic-otel-collector variants.

---------

Co-authored-by: Craig MacKenzie <[email protected]>
(cherry picked from commit fd33d85)

# Conflicts:
#	dev-tools/packaging/settings.go
#	dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.tmpl

* Fix merge conflicts

Mostly re-doing the addition of systemd packages due to the different
base images

* Update env var usage

* Only install jounralctl in the complete variant

* remove basic variant from TestKubernetesJournaldInput

* remove TestKubernetesJournaldInputOtel as edot collector variant is not relevant to 8.18

* Update changelog/fragments/1745609163-journalctl-on-all-docker-variants.yaml

---------

Co-authored-by: Tiago Queiroz <[email protected]>
Co-authored-by: Panos Koutsovasilis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.18 Automated backport to the 8.18 branch backport-8.19 Automated backport to the 8.19 branch Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team 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 and integration) not working on some 8.x Docker images
7 participants