Skip to content

Commit 23e6634

Browse files
ArthurKamalovarthur
andauthored
Small copy-truncate fixes and release info update (#754)
* update the changelog * update VERSION file. * Add dateext and extension options handling. Co-authored-by: arthur <[email protected]>
1 parent 082a3e6 commit 23e6634

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Scalyr Agent 2 Changes By Release
22
=================================
33

4-
## 2.1.21 "TBD" - April 30, 2021
4+
## 2.1.21 "Ultramarine" - Jun 1, 2021
55

66
<!---
7-
Packaged by Arthur Kamalov <[email protected]> on Apr 30, 2021 21:00 -0800
7+
Packaged by Arthur Kamalov <[email protected]> on Jun 1, 2021 21:00 -0800
88
--->
99

1010
Improvements:
@@ -15,6 +15,7 @@ Bug fixes:
1515
* Fix an issue where LogFileIterator during the copy-truncate process picks wrong pending file with a similar name causing loss of the log and showing negative bytes in agent status.
1616

1717
Other:
18+
* The discovery logic of the log files, which have been rotated with copy truncate method, now can handle only default rogrotate configurations.
1819
* Agent now emits a warning if running under Python 2.6 which we will stop supporting in the next release.
1920

2021
## 2.1.20 "Tabeisshi" - April 19, 2021

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.20
1+
2.1.21

scalyr_agent/log_processing.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ def __find_copy_truncate_file(self):
12371237
r"{0}\.\d+".format(re.escape(file_name)), os.path.basename(f)
12381238
)
12391239
or
1240-
# the same but the number is located before the extension ("extension" option in logrotate)
1240+
# the same but the number or date is located before the extension ("extension" option in logrotate)
12411241
# (e.g. foo.1.log)
12421242
re.match(
12431243
r"{0}\.\d+{1}".format(
@@ -1246,9 +1246,19 @@ def __find_copy_truncate_file(self):
12461246
os.path.basename(f),
12471247
)
12481248
or
1249+
# (e.g.foo-20210527.log)
1250+
re.match(
1251+
r"{0}-\d{{8}}{1}".format(
1252+
re.escape(file_prefix), re.escape(file_ext)
1253+
),
1254+
os.path.basename(f),
1255+
)
1256+
or
12491257
# if rotated file name ends with the date without additional extension (e.g. foo.log-20210527),
12501258
# then the only thing that we can check is that the extension starts with original file's extension.
1251-
re.match(r"{0}.+".format(re.escape(file_name)), os.path.basename(f))
1259+
re.match(
1260+
r"{0}-\d{{8}}".format(re.escape(file_name)), os.path.basename(f)
1261+
)
12521262
),
12531263
self.__file_system.list_files(dir_path),
12541264
)

tests/unit/log_processing_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,18 @@ def test_find_copy_truncate_with_ext_option_filename(self):
563563
)
564564
self.assertEqual(copied_file, located_copy_truncate_file)
565565

566+
def test_find_copy_truncate_with_ext_dateext_option_filename(self):
567+
# Test find_copy_truncate_file with date and extension rotation scheme
568+
filename = os.path.join(self.__tempdir, "app.log")
569+
self.write_file(filename, b"")
570+
copied_file = os.path.join(self.__tempdir, "app-20210101.log")
571+
self.write_file(copied_file, b"")
572+
app_log_file = self._create_iterator({"path": filename})
573+
located_copy_truncate_file = (
574+
app_log_file._LogFileIterator__find_copy_truncate_file()
575+
)
576+
self.assertEqual(copied_file, located_copy_truncate_file)
577+
566578
def test_find_copy_truncate_with_ext_and_dateext_option_filename(self):
567579
# Test find_copy_truncate_file with date rotation scheme
568580
filename = os.path.join(self.__tempdir, "app.log")

0 commit comments

Comments
 (0)