@@ -4,7 +4,7 @@ use crate::events::CoreEvent;
4
4
5
5
use advisory_lock:: { AdvisoryFileLock , FileLockMode } ;
6
6
use libcrio:: Cli ;
7
- use log:: { debug, error, info} ;
7
+ use log:: { debug, error, info, warn } ;
8
8
use serde_json:: json;
9
9
use serde_json:: Value ;
10
10
use std:: env;
@@ -297,6 +297,9 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
297
297
break ;
298
298
}
299
299
} ;
300
+
301
+ let container_id = container[ "id" ] . as_str ( ) . unwrap_or_default ( ) ;
302
+ debug ! ( "Getting logs for container id {}" , container_id) ;
300
303
let log =
301
304
match cli. tail_logs ( container[ "id" ] . as_str ( ) . unwrap_or_default ( ) , cc. log_length ) {
302
305
Ok ( v) => v,
@@ -357,10 +360,77 @@ fn handle(mut cc: config::CoreConfig) -> Result<(), anyhow::Error> {
357
360
process:: exit ( 1 ) ;
358
361
}
359
362
} ;
360
- debug ! (
361
- "Getting logs for container id {}" ,
362
- container[ "id" ] . as_str( ) . unwrap_or_default( )
363
- ) ;
363
+
364
+ if cc. include_proc_info {
365
+ debug ! ( "Getting pid info for container id {}" , container_id) ;
366
+
367
+ let inspect = match cli. inspect_container ( container_id) {
368
+ Ok ( v) => v,
369
+ Err ( e) => {
370
+ error ! ( "Error inspecting container \n {}" , e) ;
371
+ // We continue here since we do not want to interrupt the whole gathering
372
+ // flow because we could not inspect a container
373
+ continue ;
374
+ }
375
+ } ;
376
+
377
+ let pid = match inspect[ "info" ] [ "pid" ] . as_u64 ( ) {
378
+ Some ( p) => p,
379
+ None => {
380
+ // We continue here since we do not want to interrupt the whole gathering
381
+ // flow because we could not extract pid from the container inspection
382
+ warn ! ( "Failed to parse pid from inspect container, skipping" ) ;
383
+ continue ;
384
+ }
385
+ } ;
386
+
387
+ debug ! ( "Got pid {} for container" , pid) ;
388
+
389
+ debug ! ( "Add proc files to the zip" ) ;
390
+
391
+ // Gathering proc files means reading from the /proc/$pid folder to capture files
392
+ // needed fore core2md to do its conversion. If for some reason a file is missing,
393
+ // then that means that the container was evicted and has no longer a pid folder.
394
+ // When this happens we do not want to abort the rest of data gathering as it can
395
+ // contain useful information regardless of that containers process data.
396
+ // So if any files failed to open, then log the error and continue on to the next container(s)
397
+ let proc_folder_full_path = cc. get_proc_folder_full_path ( counter) ;
398
+ for filename in cc. get_proc_files_to_gather ( ) {
399
+ let mut file = match File :: open ( format ! (
400
+ "{}/{}/{}" ,
401
+ cc. system_proc_folder_path, pid, filename
402
+ ) ) {
403
+ Ok ( f) => f,
404
+ Err ( e) => {
405
+ warn ! (
406
+ "Failed to open {}. Has the pod been ejected?\n {}" ,
407
+ filename, e
408
+ ) ;
409
+ break ;
410
+ }
411
+ } ;
412
+
413
+ let mut buffer = Vec :: new ( ) ;
414
+ if let Err ( e) = file. read_to_end ( & mut buffer) {
415
+ warn ! ( "Failed read contents of the {} file \n {}" , filename, e) ;
416
+ break ;
417
+ }
418
+
419
+ if let Err ( e) =
420
+ zip. start_file ( format ! ( "{}/{}" , proc_folder_full_path, filename) , options)
421
+ {
422
+ warn ! ( "Error starting {} file in zip \n {}" , filename, e) ;
423
+ break ;
424
+ }
425
+
426
+ if let Err ( e) = zip. write_all ( buffer. as_slice ( ) ) {
427
+ warn ! ( "Error writing {} file in zip \n {}" , filename, e) ;
428
+ break ;
429
+ }
430
+ }
431
+
432
+ debug ! ( "Finished adding proc files to the zip" ) ;
433
+ }
364
434
}
365
435
} ;
366
436
0 commit comments