-
Notifications
You must be signed in to change notification settings - Fork 197
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
belimawr
merged 37 commits into
elastic:main
from
belimawr:44040-journalctl-on-docker-iamges
Jun 12, 2025
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
7e6caf2
Enable Filebeat's Journald input in all docker image variants
belimawr 80f1fd8
Merge branch 'main' into 44040-journalctl-on-docker-iamges
belimawr f406282
Add changelog
belimawr 423fd25
Merge branch '44040-journalctl-on-docker-iamges' of github.com:belima…
belimawr be5dce0
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr c81ba47
Systemd installed only in complete and otel docker Images
belimawr d8a8ac1
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr d0c0d4c
Fix condition to add systemd/journalctl
belimawr eee9aab
update changelog
belimawr 6b8003b
Fix changelog
belimawr 17c38c3
fix changelog one more time
belimawr c4f8c50
Update changelog/fragments/1745609163-journalctl-on-all-docker-varian…
belimawr a57d788
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr 7f11fd5
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr d4bffe4
Add test to ensure docker images contain journalctl
belimawr a888305
Fix namespace on test
belimawr 89e92ba
Add more docker images and improve docs
belimawr 4d13e5e
Merge branch '44040-journalctl-on-docker-iamges' of github.com:belima…
belimawr 3ccead5
Add integration build tag
belimawr 7b1112e
Add otelcollector tests
belimawr a3d7535
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr fca29ac
update notice files
belimawr f80ebea
Reduce verbosity
belimawr 551b664
Fix notice files
belimawr fe8f78e
Fix parsing of ES host and add integration:kubernetesSingle
belimawr 5861ff3
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr d4957c6
Refactor tests
belimawr 9634981
Consolidate package installation
belimawr c22981e
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr 4c321fb
Update dev-tools/packaging/templates/docker/Dockerfile.elastic-agent.…
belimawr 48d8cfa
Use k8s namespace as data_stream.namespace
belimawr c8c7907
Merge branch '44040-journalctl-on-docker-iamges' of github.com:belima…
belimawr 176ab26
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr 9b64e84
Update changelog
belimawr 72e3a0e
Update Elastic-Agent test to use username + password
belimawr 5b15246
Merge branch 'main' of github.com:elastic/elastic-agent into 44040-jo…
belimawr b10a886
Update function call
belimawr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
changelog/fragments/1745609163-journalctl-on-all-docker-variants.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Kind can be one of: | ||
# - breaking-change: a change to previously-documented behavior | ||
# - deprecation: functionality that is being removed in a later release | ||
# - bug-fix: fixes a problem in a previous version | ||
# - enhancement: extends functionality but does not break or fix existing behavior | ||
# - feature: new functionality | ||
# - known-issue: problems that we are aware of in a given version | ||
# - security: impacts on the security of a product or a user’s deployment. | ||
# - upgrade: important information for someone upgrading from a prior version | ||
# - other: does not fit into any of the other categories | ||
kind: bug-fix | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: | | ||
Ship journalctl in the elastic-agent, elastic-agent-complete, and | ||
elastic-otel-collector Docker images to enable reading journald | ||
logs. Journalctl is not present on *-slim and all Wolfi images. | ||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
#description: | ||
|
||
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
component: elastic-agent | ||
|
||
# PR URL; optional; the PR number that added the changeset. | ||
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
# Please provide it if you are adding a fragment for a different PR. | ||
pr: https://github.com/elastic/elastic-agent/pull/7995 | ||
|
||
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
# If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
issue: https://github.com/elastic/beats/issues/44040 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/e2e-framework/klient/k8s" | ||
|
||
"github.com/elastic/elastic-agent-libs/testing/estools" | ||
"github.com/elastic/elastic-agent/pkg/testing/define" | ||
"github.com/elastic/go-elasticsearch/v8" | ||
) | ||
|
||
func TestKubernetesJournaldInput(t *testing.T) { | ||
info := define.Require(t, define.Requirements{ | ||
Stack: &define.Stack{}, | ||
Local: false, | ||
Sudo: false, | ||
OS: []define.OS{ | ||
{Type: define.Kubernetes, DockerVariant: "basic"}, | ||
{Type: define.Kubernetes, DockerVariant: "complete"}, | ||
}, | ||
Group: define.Kubernetes, | ||
}) | ||
|
||
agentConfigYAML, err := os.ReadFile(filepath.Join("testdata", "journald-input.yml")) | ||
require.NoError(t, err, "failed to read journald input template") | ||
|
||
ctx := context.Background() | ||
kCtx := k8sGetContext(t, info) | ||
|
||
schedulableNodeCount, err := k8sSchedulableNodeCount(ctx, kCtx) | ||
require.NoError(t, err, "error at getting schedulable node count") | ||
require.NotZero(t, schedulableNodeCount, "no schedulable Kubernetes nodes found") | ||
|
||
namespace := kCtx.getNamespace(t) | ||
hostPathType := corev1.HostPathDirectory | ||
|
||
steps := []k8sTestStep{ | ||
k8sStepCreateNamespace(), | ||
k8sStepDeployKustomize( | ||
agentK8SKustomize, | ||
"elastic-agent-standalone", | ||
k8sKustomizeOverrides{ | ||
agentContainerExtraEnv: []corev1.EnvVar{ | ||
{ | ||
Name: "ELASTICSEARCH_USERNAME", | ||
Value: os.Getenv("ELASTICSEARCH_USERNAME"), | ||
}, | ||
{ | ||
Name: "ELASTICSEARCH_PASSWORD", | ||
Value: os.Getenv("ELASTICSEARCH_PASSWORD"), | ||
}, | ||
{ | ||
Name: "EA_POLICY_NAMESPACE", | ||
Value: namespace, | ||
}, | ||
}, | ||
agentContainerVolumeMounts: []corev1.VolumeMount{ | ||
{ | ||
Name: "journald-mount", | ||
MountPath: "/opt/journald", | ||
ReadOnly: true, | ||
}, | ||
}, | ||
agentPodVolumes: []corev1.Volume{ | ||
{ | ||
Name: "journald-mount", | ||
VolumeSource: corev1.VolumeSource{ | ||
HostPath: &corev1.HostPathVolumeSource{ | ||
Path: "/run/log/journal", | ||
Type: &hostPathType, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
func(obj k8s.Object) { | ||
// update the configmap to use the journald input | ||
switch objWithType := obj.(type) { | ||
case *corev1.ConfigMap: | ||
_, ok := objWithType.Data["agent.yml"] | ||
if ok { | ||
objWithType.Data["agent.yml"] = string(agentConfigYAML) | ||
} | ||
} | ||
|
||
}), | ||
k8sStepCheckAgentStatus( | ||
"app=elastic-agent-standalone", | ||
schedulableNodeCount, | ||
"elastic-agent-standalone", | ||
map[string]bool{ | ||
"journald": true, | ||
}), | ||
} | ||
|
||
journaldTest( | ||
t, | ||
info.ESClient, | ||
kCtx, | ||
steps, | ||
fmt.Sprintf("logs-generic-%s", namespace), | ||
"input.type", | ||
"journald") | ||
} | ||
|
||
func TestKubernetesJournaldInputOtel(t *testing.T) { | ||
info := define.Require(t, define.Requirements{ | ||
Stack: &define.Stack{}, | ||
Local: false, | ||
Sudo: false, | ||
OS: []define.OS{ | ||
{Type: define.Kubernetes, DockerVariant: "elastic-otel-collector"}, | ||
}, | ||
Group: define.Kubernetes, | ||
}) | ||
|
||
otelConfigYAML, err := os.ReadFile(filepath.Join("testdata", "journald-otel.yml")) | ||
require.NoError(t, err, "failed to read journald input template") | ||
|
||
kCtx := k8sGetContext(t, info) | ||
namespace := kCtx.getNamespace(t) | ||
hostPathType := corev1.HostPathDirectory | ||
|
||
steps := []k8sTestStep{ | ||
k8sStepCreateNamespace(), | ||
k8sStepDeployKustomize( | ||
agentK8SKustomize, | ||
"elastic-agent-standalone", | ||
k8sKustomizeOverrides{ | ||
agentContainerArgs: []string{"--config", "/etc/elastic-agent/agent.yml"}, | ||
agentContainerExtraEnv: []corev1.EnvVar{ | ||
{ | ||
Name: "EA_POLICY_NAMESPACE", | ||
Value: namespace, | ||
}, | ||
{ | ||
Name: "ES_API_KEY_ENCODED", | ||
Value: kCtx.esEncodedAPIKey, | ||
}, | ||
}, | ||
agentContainerVolumeMounts: []corev1.VolumeMount{ | ||
{ | ||
Name: "journald-mount", | ||
MountPath: "/opt/journal", | ||
ReadOnly: true, | ||
}, | ||
}, | ||
agentPodVolumes: []corev1.Volume{ | ||
{ | ||
Name: "journald-mount", | ||
VolumeSource: corev1.VolumeSource{ | ||
HostPath: &corev1.HostPathVolumeSource{ | ||
Path: "/run/log/journal", | ||
Type: &hostPathType, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
func(obj k8s.Object) { | ||
// update the configmap to use the journald input | ||
switch objWithType := obj.(type) { | ||
case *corev1.ConfigMap: | ||
_, ok := objWithType.Data["agent.yml"] | ||
if ok { | ||
objWithType.Data["agent.yml"] = string(otelConfigYAML) | ||
} | ||
} | ||
}), | ||
} | ||
|
||
journaldTest( | ||
t, | ||
info.ESClient, | ||
kCtx, | ||
steps, | ||
fmt.Sprintf("logs-generic.otel-%s", namespace), | ||
"body.structured.input.type", | ||
"journald") | ||
} | ||
|
||
func journaldTest( | ||
t *testing.T, | ||
esClient *elasticsearch.Client, | ||
kCtx k8sContext, | ||
steps []k8sTestStep, | ||
index, field, value string) { | ||
t.Helper() | ||
|
||
ctx := context.Background() | ||
testNamespace := kCtx.getNamespace(t) | ||
|
||
for _, step := range steps { | ||
step(t, ctx, kCtx, testNamespace) | ||
} | ||
|
||
// Check if the context was cancelled or timed out | ||
if ctx.Err() != nil { | ||
t.Errorf("context error: %v", ctx.Err()) | ||
} | ||
|
||
// Query the index and filter by the input type | ||
docs := findESDocs(t, func() (estools.Documents, error) { | ||
return estools.GetLogsForIndexWithContext( | ||
ctx, | ||
esClient, | ||
index, | ||
map[string]any{ | ||
field: value, | ||
}, | ||
) | ||
}) | ||
require.NotEmpty(t, docs, "expected logs to be found in Elasticsearch") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.