Skip to content

Commit

Permalink
Detect if the configured and the migrated registry paths are the same (
Browse files Browse the repository at this point in the history
…elastic#10982) (elastic#11085)

Cherry-pick of PR elastic#10982 to 6.7 branch. Original message: 

The E2E test of starting Journalbeat with an existing registry broke when I have added support and tests for `include_matches`. Thus, when I added the migration of the registry file, the issue was not detected.
Now both the code and the test are fixed.
  • Loading branch information
kvch authored Mar 8, 2019
1 parent 0ab7af1 commit 6b678be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions journalbeat/checkpoint/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ func (c *Checkpoint) findRegistryFile() error {
return fmt.Errorf("error accessing previous registry file: %+v", err)
}

// if two files are the same, do not do anything
migratedFs, err := os.Stat(migratedPath)
if err == nil {
if os.SameFile(fs, migratedFs) {
return nil
}
}

f, err := os.Open(c.file)
if err != nil {
return err
Expand Down
21 changes: 18 additions & 3 deletions journalbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import unittest
import time
import yaml


class Test(BaseTest):
Expand Down Expand Up @@ -114,10 +115,14 @@ def test_read_events_with_existing_registry(self):
Journalbeat is able to follow reading a from a journal with an existing registry file.
"""

registry_path = self.beat_path + "/tests/system/input/test.registry"
input_path = self.beat_path + "/tests/system/input/test.journal"
self._prepare_registry_file(registry_path, input_path)

self.render_config_template(
journal_path=self.beat_path + "/tests/system/input/test.journal",
journal_path=input_path,
seek_method="cursor",
registry_file=self.beat_path + "/tests/system/input/test.registry",
registry_file=registry_path,
path=os.path.abspath(self.working_dir) + "/log/*",
)
journalbeat_proc = self.start_beat()
Expand All @@ -140,7 +145,7 @@ def test_read_events_with_existing_registry(self):
assert exit_code == 0

@unittest.skipUnless(sys.platform.startswith("linux"), "Journald only on Linux")
def test_read_events_with_existing_registry(self):
def test_read_events_with_include_matches(self):
"""
Journalbeat is able to pass matchers to the journal reader and read filtered messages.
"""
Expand Down Expand Up @@ -172,6 +177,16 @@ def test_read_events_with_existing_registry(self):
exit_code = journalbeat_proc.kill_and_wait()
assert exit_code == 0

def _prepare_registry_file(self, registry_path, journal_path):
lines = []
with open(registry_path, "r") as registry_file:
lines = registry_file.readlines()
lines[2] = "- path: " + journal_path + "\n"

with open(registry_path, "w") as registry_file:
for line in lines:
registry_file.write(line)


if __name__ == '__main__':
unittest.main()

0 comments on commit 6b678be

Please sign in to comment.