Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit 956cc44

Browse files
Apply limit time filter.
Signed-off-by: Shriya Deshmukh <[email protected]>
1 parent b52d023 commit 956cc44

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

src/rgw/support/rgw_support_bundle

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ from cortx.utils.conf_store.conf_store import Conf, MappedConf
3232
from cortx.utils.support_framework.log_filters import FilterLog
3333
from cortx.rgw.const import (
3434
CONFIG_PATH_KEY, LOG_PATH_KEY, COMPONENT_NAME, RGW_CONF_FILE,
35-
SVC_FILE_PERCENTAGE)
35+
SVC_FILE_PERCENTAGE, LOG_DATE_REGEX, LOG_TIME_REGEX,
36+
DATETIME_DATE_REGEX, DATETIME_TIME_REGEX)
3637

3738

3839
class SupportBundleError(BaseError):
@@ -98,34 +99,22 @@ class RGWSupportBundle:
9899
# files in delim_T use timestamp syntax as
99100
# 2022-07-10T05:28:35.570+0000
100101
from cortx.utils.support_framework.log_filters import FilterLog
101-
from cortx.rgw.const import (RGW_STARTUP_LOG, RGW_SETUP_LOG,
102-
RGW_SUPPORT_BUNDLE_LOG, RADOSGW_ADMIN_LOG, RGW_1_LOG,
103-
LOG_DATE_REGEX, LOG_TIME_REGEX, DATETIME_DATE_REGEX,
104-
DATETIME_TIME_REGEX)
105-
106-
# log files with timestamp syntax "YYYY-mm-DD H:M:S"
107-
delim_space = [RGW_STARTUP_LOG, RGW_SETUP_LOG, RGW_SUPPORT_BUNDLE_LOG]
108-
# log files with timestamp syntax "YYYY-mm-DDTH:M:S"
109-
delim_T = [RADOSGW_ADMIN_LOG, RGW_1_LOG]
102+
temp_path_src = os.path.join('/tmp', 'rgw_src')
103+
os.makedirs(temp_path_src, exist_ok=True)
104+
# Move text logs and rotated log files to temp dir.
110105
for file in os.listdir(RGWSupportBundle._tmp_src):
111-
if file in delim_space:
112-
delim = ' '
113-
elif file in delim_T:
114-
delim = 'T'
115-
else:
106+
if file.endswith('.conf') or file == "installed-cortx-rpms.txt":
116107
continue
117-
log_timestamp_regex = LOG_DATE_REGEX + delim + LOG_TIME_REGEX
118-
datetime_format = DATETIME_DATE_REGEX + delim + DATETIME_TIME_REGEX
119-
# apply log filter to individual file by passing exact filename
120-
# to file_name_reg_ex
121-
FilterLog.limit_time(
122-
src_dir=RGWSupportBundle._tmp_src,
123-
dest_dir=RGWSupportBundle._tmp_src,
124-
duration=duration,
125-
file_name_reg_ex=file,
126-
log_timestamp_regex=log_timestamp_regex,
127-
datetime_format=datetime_format)
128-
108+
shutil.move(os.path.join(RGWSupportBundle._tmp_src, file),
109+
os.path.join(temp_path_src, file))
110+
temp_path = os.path.join('/tmp', 'rgw_time_based_log')
111+
RGWSupportBundle._apply_limit_time(temp_path_src, temp_path, 'rgw-*', duration)
112+
RGWSupportBundle._apply_limit_time(temp_path_src, temp_path, 'rgw_*', duration)
113+
RGWSupportBundle._apply_limit_time(temp_path_src, temp_path, 'radosgw*', duration)
114+
# delete temp paths.
115+
shutil.rmtree(temp_path)
116+
shutil.rmtree(temp_path_src)
117+
Log.info('Collected log files based on time duration.')
129118
else:
130119
Log.error("RGW log file does not exists hence skipping log file collection.")
131120

@@ -233,6 +222,31 @@ class RGWSupportBundle:
233222
RGWSupportBundle._generate_tar(bundle_id, target_path)
234223
RGWSupportBundle._cleanup()
235224

225+
@staticmethod
226+
def _apply_limit_time(temp_path_src: str, path: str, reg_ex: str, duration: str):
227+
"""Apply limit_time filter."""
228+
if os.path.exists(path):
229+
shutil.rmtree(path)
230+
os.makedirs(path, exist_ok=True)
231+
for file in os.listdir(temp_path_src):
232+
regex = re.compile(f'({reg_ex})')
233+
if regex.match(file) and file.startswith(reg_ex[:-1]):
234+
shutil.move(os.path.join(temp_path_src, file),
235+
os.path.join(path, file))
236+
if reg_ex == 'rgw-*' or reg_ex == 'radosgw*':
237+
delim = 'T'
238+
else:
239+
delim = ' '
240+
log_timestamp_regex = LOG_DATE_REGEX + delim + LOG_TIME_REGEX
241+
datetime_format = DATETIME_DATE_REGEX + delim + DATETIME_TIME_REGEX
242+
Log.info(f'apply limit-time filter on {reg_ex} files.')
243+
# apply limit_time log filter to file names started by reg_ex
244+
FilterLog.limit_time(src_dir=path, dest_dir=RGWSupportBundle._tmp_src,
245+
duration=duration, file_name_reg_ex=reg_ex[:-1],
246+
log_timestamp_regex=log_timestamp_regex,
247+
datetime_format=datetime_format)
248+
249+
236250
@staticmethod
237251
def _get_dir_size(dir_path: str):
238252
"""Calculate total directory size."""
@@ -285,7 +299,7 @@ class RGWSupportBundle:
285299
if size_limit:
286300
remaining_size_limit = RGWSupportBundle._get_remaining_folder_size(
287301
RGWSupportBundle._tmp_src, size_limit)
288-
if (os.path.getsize(addb_dir) > int(remaining_size_limit[:-1])):
302+
if (RGWSupportBundle._get_dir_size(addb_dir) > int(remaining_size_limit[:-1])):
289303
Log.warn('Exhausted support bundle size limit while '
290304
'collecting addb files.')
291305
break

0 commit comments

Comments
 (0)