@@ -84,36 +84,17 @@ class RGWSupportBundle:
8484
8585 # copy rgw client log files
8686 log_dir = os .path .join (log_base , f'rgw/{ machine_id } ' )
87- if os .path .exists (log_dir ):
88- regex = re .compile ('(rgw*)|(radosgw*)' )
89- for file in os .listdir (log_dir ):
90- if regex .match (file ):
91- infile = os .path .join (log_dir , file )
92- outfile = os .path .join (RGWSupportBundle ._tmp_src , file )
93- if os .path .isfile (infile ):
94- shutil .copyfile (infile , outfile )
9587
9688 if duration :
9789 # files in delim_space use timestamp syntax as
9890 # [2022-07-10 05:26:57,579] & 2022-07-10 05:26:34
9991 # files in delim_T use timestamp syntax as
10092 # 2022-07-10T05:28:35.570+0000
10193 from cortx .utils .support_framework .log_filters import FilterLog
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.
105- for file in os .listdir (RGWSupportBundle ._tmp_src ):
106- if file .endswith ('.conf' ) or file == "installed-cortx-rpms.txt" :
107- continue
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 )
94+ RGWSupportBundle ._apply_limit_time (log_dir , 'rgw-*' , duration )
95+ RGWSupportBundle ._apply_limit_time (log_dir , 'rgw_*' , duration )
96+ RGWSupportBundle ._apply_limit_time (log_dir , 'radosgw*' , duration )
97+
11798 Log .info ('Collected log files based on time duration.' )
11899 else :
119100 Log .error ("RGW log file does not exists hence skipping log file collection." )
@@ -126,8 +107,6 @@ class RGWSupportBundle:
126107 # rgw service logs(rgw-*) and then add other files in SB if it fits
127108 # withing the size_limit.
128109 if size_limit :
129- from cortx .utils .support_framework .log_filters import FilterLog
130- # Move all files to temp dir and apply size filter on it.
131110 tmp_client_log_dir = os .path .join ('/tmp' , 'rgw_log' )
132111 os .makedirs (tmp_client_log_dir , exist_ok = True )
133112 for file in os .listdir (RGWSupportBundle ._tmp_src ):
@@ -161,13 +140,13 @@ class RGWSupportBundle:
161140 RGWSupportBundle ._apply_size_filter (
162141 tmp_svc_files_dir , allocated_size , 'rgw-*' ,
163142 check_remaining_size = False )
143+ shutil .rmtree (tmp_svc_files_dir )
164144 RGWSupportBundle ._copy_compressed_files (
165145 tmp_client_log_dir , allocated_size )
166146 RGWSupportBundle ._apply_size_filter (
167147 tmp_client_log_dir , size_limit , 'rgw_*' )
168148 RGWSupportBundle ._apply_size_filter (
169149 tmp_client_log_dir , size_limit , 'radosgw*' )
170- shutil .rmtree (tmp_svc_files_dir )
171150 shutil .rmtree (tmp_client_log_dir )
172151
173152 RGWSupportBundle ._collect_motr_trace_files (size_limit , log_dir )
@@ -223,16 +202,8 @@ class RGWSupportBundle:
223202 RGWSupportBundle ._cleanup ()
224203
225204 @staticmethod
226- def _apply_limit_time (temp_path_src : str , path : str , reg_ex : str , duration : str ):
205+ def _apply_limit_time (log_path : str , reg_ex : str , duration : str ):
227206 """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 ))
236207 if reg_ex == 'rgw-*' or reg_ex == 'radosgw*' :
237208 delim = 'T'
238209 else :
@@ -241,7 +212,7 @@ class RGWSupportBundle:
241212 datetime_format = DATETIME_DATE_REGEX + delim + DATETIME_TIME_REGEX
242213 Log .info (f'apply limit-time filter on { reg_ex } files.' )
243214 # apply limit_time log filter to file names started by reg_ex
244- FilterLog .limit_time (src_dir = path , dest_dir = RGWSupportBundle ._tmp_src ,
215+ FilterLog .limit_time (src_dir = log_path , dest_dir = RGWSupportBundle ._tmp_src ,
245216 duration = duration , file_name_reg_ex = reg_ex [:- 1 ],
246217 log_timestamp_regex = log_timestamp_regex ,
247218 datetime_format = datetime_format )
0 commit comments