|
9 | 9 | import os |
10 | 10 | from pathlib import Path |
11 | 11 | import platform |
| 12 | +import socket |
12 | 13 | import subprocess |
13 | 14 | import tempfile |
14 | 15 | import time |
@@ -457,8 +458,21 @@ def _generate_launch_string( |
457 | 458 | return launch_string |
458 | 459 |
|
459 | 460 |
|
| 461 | +def _confirm_watchdog_start(start_watchdog, cleanup_on_exit, fluent_connection): |
| 462 | + """Confirm whether Fluent is running locally, and whether the Watchdog should be |
| 463 | + started.""" |
| 464 | + if start_watchdog is None and cleanup_on_exit: |
| 465 | + host = fluent_connection.connection_properties.cortex_host |
| 466 | + if host == socket.gethostname(): |
| 467 | + logger.debug( |
| 468 | + "Fluent running on the host machine and 'cleanup_on_exit' activated, will launch Watchdog." |
| 469 | + ) |
| 470 | + start_watchdog = True |
| 471 | + return start_watchdog |
| 472 | + |
| 473 | + |
460 | 474 | def scm_to_py(topy, journal_filepaths): |
461 | | - """Convert journal filenames to Python filename.""" |
| 475 | + """Convert journal file names to Python file name.""" |
462 | 476 | fluent_jou_arg = "".join([f'-i "{journal}" ' for journal in journal_filepaths]) |
463 | 477 | if isinstance(topy, str): |
464 | 478 | return f" {fluent_jou_arg} -topy={topy}" |
@@ -648,13 +662,6 @@ def launch_fluent( |
648 | 662 | "when starting a remote Fluent PyPIM client." |
649 | 663 | ) |
650 | 664 |
|
651 | | - if ( |
652 | | - start_watchdog is None |
653 | | - and cleanup_on_exit |
654 | | - and (fluent_launch_mode in (LaunchMode.CONTAINER, LaunchMode.STANDALONE)) |
655 | | - ): |
656 | | - start_watchdog = True |
657 | | - |
658 | 665 | if dry_run and fluent_launch_mode != LaunchMode.CONTAINER: |
659 | 666 | logger.warning( |
660 | 667 | "'dry_run' argument for 'launch_fluent' currently is only " |
@@ -757,6 +764,9 @@ def launch_fluent( |
757 | 764 | launcher_args=argvals, |
758 | 765 | inside_container=False, |
759 | 766 | ) |
| 767 | + start_watchdog = _confirm_watchdog_start( |
| 768 | + start_watchdog, cleanup_on_exit, session.fluent_connection |
| 769 | + ) |
760 | 770 | if start_watchdog: |
761 | 771 | logger.info("Launching Watchdog for local Fluent client...") |
762 | 772 | ip, port, password = _get_server_info(server_info_filepath) |
@@ -844,6 +854,8 @@ def launch_fluent( |
844 | 854 | ) |
845 | 855 | ) |
846 | 856 |
|
| 857 | + if start_watchdog is None and cleanup_on_exit: |
| 858 | + start_watchdog = True |
847 | 859 | if start_watchdog: |
848 | 860 | logger.debug("Launching Watchdog for Fluent container...") |
849 | 861 | watchdog.launch(os.getpid(), port, password) |
@@ -912,11 +924,12 @@ def connect_to_fluent( |
912 | 924 | ) |
913 | 925 | new_session = _get_running_session_mode(fluent_connection) |
914 | 926 |
|
915 | | - if start_watchdog is None and cleanup_on_exit: |
916 | | - start_watchdog = True |
| 927 | + start_watchdog = _confirm_watchdog_start( |
| 928 | + start_watchdog, cleanup_on_exit, fluent_connection |
| 929 | + ) |
917 | 930 |
|
918 | 931 | if start_watchdog: |
919 | | - logger.info("Launching Watchdog for existing Fluent connection...") |
| 932 | + logger.info("Launching Watchdog for existing Fluent session...") |
920 | 933 | ip, port, password = _get_server_info(server_info_filepath, ip, port, password) |
921 | 934 | watchdog.launch(os.getpid(), port, password, ip) |
922 | 935 |
|
|
0 commit comments