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

[Journald] Add tests to ensure no data duplication on restart #42596

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions filebeat/tests/integration/journald_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,58 @@ func TestJournaldInputRunsAndRecoversFromJournalctlFailures(t *testing.T) {
t.Fatalf("expecting 8 published events, got %d instead'", eventsPublished)
}
}

func TestJournaldInputDoesNotDuplicateData(t *testing.T) {
filebeat := integration.NewBeat(
t,
"filebeat",
"../../filebeat.test",
)

// render configuration
syslogID := fmt.Sprintf("%s-%s", t.Name(), uuid.Must(uuid.NewV4()).String())
yamlCfg := fmt.Sprintf(journaldInputCfg, syslogID, filebeat.TempDir())

defer func() {
if t.Failed() {
t.Logf("Syslog ID: %q", syslogID)
}
}()
go generateJournaldLogs(t, context.Background(), syslogID, 3)

filebeat.WriteConfigFile(yamlCfg)
filebeat.Start()
// On a normal execution we run journalclt twice, the first time to read all messages from the
// previous boot until 'now' and the second one with the --follow flag that should keep on running.
filebeat.WaitForLogs("journalctl started with PID", 10*time.Second, "journalctl did not start")
filebeat.WaitForLogs("journalctl started with PID", 10*time.Second, "journalctl did not start")

pidLine := filebeat.GetLastLogLine("journalctl started with PID")
logEntry := struct{ Message string }{}
if err := json.Unmarshal([]byte(pidLine), &logEntry); err != nil {
t.Errorf("could not parse PID log entry as JSON: %s", err)
}

filebeat.WaitForLogs("Count: 003", 5*time.Second, "did not find the third event in published events")

// Stop Filebeat
filebeat.Stop()

// Generate more logs
go generateJournaldLogs(t, context.Background(), syslogID, 5)

// Restart Filebeat
filebeat.Start()

// Wait for journalctl to start
filebeat.WaitForLogs("journalctl started with PID", 10*time.Second, "journalctl did not start")

// Wait for last even in the debug logs
filebeat.WaitForLogs("Count: 005", time.Second, "expected log message not found in published events SECOND")

eventsPublished := filebeat.CountFileLines(filepath.Join(filebeat.TempDir(), "output-*.ndjson"))

if eventsPublished != 8 {
t.Fatalf("expecting 8 published events, got %d instead'", eventsPublished)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ output:
file:
path: ${path.home}
filename: "output"
rotate_on_startup: false

logging:
level: debug
Expand Down
Loading