Repository: Parsl/parsl

Issue:
Make logging in monitoring wrapper parameterisable
The logging is set to DEBUG level in current state. We should make it parameterisable in the future.


Discussion:
Mentioned in #1082 

Resolving patch:
diff --git a/parsl/dataflow/dflow.py b/parsl/dataflow/dflow.py
--- a/parsl/dataflow/dflow.py
+++ b/parsl/dataflow/dflow.py
@@ -432,9 +432,11 @@ def launch_task(self, task_id, executable, *args, **kwargs):
             raise ValueError("Task {} requested invalid executor {}".format(task_id, executor_label))
 
         if self.monitoring is not None and self.monitoring.resource_monitoring_enabled:
+            wrapper_logging_level = logging.DEBUG if self.monitoring.monitoring_debug else logging.INFO
             executable = self.monitoring.monitor_wrapper(executable, task_id,
                                                          self.monitoring.monitoring_hub_url,
                                                          self.run_id,
+                                                         wrapper_logging_level,
                                                          self.monitoring.resource_monitoring_interval)
 
         with self.submitter_lock:
diff --git a/parsl/monitoring/monitoring.py b/parsl/monitoring/monitoring.py
--- a/parsl/monitoring/monitoring.py
+++ b/parsl/monitoring/monitoring.py
@@ -135,7 +135,7 @@ def __init__(self,
                  workflow_version=None,
                  logging_endpoint='sqlite:///monitoring.db',
                  logdir=None,
-                 logging_level=logging.INFO,
+                 monitoring_debug=False,
                  resource_monitoring_enabled=True,
                  resource_monitoring_interval=30):  # in seconds
         """
@@ -163,8 +163,8 @@ def __init__(self,
              Default: 'sqlite:///monitoring.db'
         logdir : str
              Parsl log directory paths. Logs and temp files go here. Default: '.'
-        logging_level : int
-             Logging level as defined in the logging module. Default: logging.INFO (20)
+        monitoring_debug : Bool
+             Enable monitoring debug logging. Default: False
         resource_monitoring_enabled : boolean
              Set this field to True to enable logging the info of resource usage of each task. Default: True
         resource_monitoring_interval : int
@@ -185,7 +185,7 @@ def __init__(self,
 
         self.logging_endpoint = logging_endpoint
         self.logdir = logdir
-        self.logging_level = logging_level
+        self.monitoring_debug = monitoring_debug
 
         self.workflow_name = workflow_name
         self.workflow_version = workflow_version
@@ -203,7 +203,7 @@ def start(self, run_id):
         # Initialize the ZMQ pipe to the Parsl Client
         self.logger = start_file_logger("{}/monitoring_hub.log".format(self.logdir),
                                         name="monitoring_hub",
-                                        level=self.logging_level)
+                                        level=logging.DEBUG if self.monitoring_debug else logging.INFO)
         self.logger.info("Monitoring Hub initialized")
 
         self.logger.debug("Initializing ZMQ Pipes to client")
@@ -229,7 +229,7 @@ def start(self, run_id):
                                           "client_address": self.client_address,
                                           "client_port": self.dfk_port,
                                           "logdir": self.logdir,
-                                          "logging_level": self.logging_level,
+                                          "logging_level": logging.DEBUG if self.monitoring_debug else logging.INFO,
                                           "run_id": run_id
                                   },
                                   name="Monitoring-Queue-Process"
@@ -239,7 +239,7 @@ def start(self, run_id):
         self.dbm_proc = Process(target=dbm_starter,
                                 args=(self.priority_msgs, self.node_msgs, self.resource_msgs,),
                                 kwargs={"logdir": self.logdir,
-                                        "logging_level": self.logging_level,
+                                        "logging_level": logging.DEBUG if self.monitoring_debug else logging.INFO,
                                         "db_url": self.logging_endpoint,
                                   },
                                 name="Monitoring-DBM-Process"
@@ -276,12 +276,24 @@ def close(self):
             self.priority_msgs.put(("STOP", 0))
 
     @staticmethod
-    def monitor_wrapper(f, task_id, monitoring_hub_url, run_id, sleep_dur):
+    def monitor_wrapper(f,
+                        task_id,
+                        monitoring_hub_url,
+                        run_id,
+                        logging_level,
+                        sleep_dur):
         """ Internal
         Wrap the Parsl app with a function that will call the monitor function and point it at the correct pid when the task begins.
         """
         def wrapped(*args, **kwargs):
-            p = Process(target=monitor, args=(os.getpid(), task_id, monitoring_hub_url, run_id, sleep_dur), name="Monitor-Wrapper-{}".format(task_id))
+            p = Process(target=monitor,
+                        args=(os.getpid(),
+                              task_id,
+                              monitoring_hub_url,
+                              run_id,
+                              logging_level,
+                              sleep_dur),
+                        name="Monitor-Wrapper-{}".format(task_id))
             p.start()
             try:
                 return f(*args, **kwargs)
@@ -305,7 +317,7 @@ def __init__(self,
                  monitoring_hub_address="127.0.0.1",
                  logdir=".",
                  run_id=None,
-                 logging_level=logging.DEBUG,
+                 logging_level=logging.INFO,
                  atexit_timeout=3    # in seconds
                 ):
         """ Initializes a monitoring configuration class.
@@ -424,7 +436,12 @@ def hub_starter(comm_q, priority_msgs, node_msgs, resource_msgs, stop_q, *args,
     hub.start(priority_msgs, node_msgs, resource_msgs, stop_q)
 
 
-def monitor(pid, task_id, monitoring_hub_url, run_id, sleep_dur=10):
+def monitor(pid,
+            task_id,
+            monitoring_hub_url,
+            run_id,
+            logging_level=logging.INFO,
+            sleep_dur=10):
     """Internal
     Monitors the Parsl task's resources by pointing psutil to the task's pid and watching it and its children.
     """
@@ -436,7 +453,7 @@ def monitor(pid, task_id, monitoring_hub_url, run_id, sleep_dur=10):
 
     format_string = "%(asctime)s.%(msecs)03d %(name)s:%(lineno)d [%(levelname)s]  %(message)s"
     logging.basicConfig(filename='{logbase}/monitor.{task_id}.{pid}.log'.format(
-        logbase="/tmp", task_id=task_id, pid=pid), level=logging.DEBUG, format=format_string)
+        logbase="/tmp", task_id=task_id, pid=pid), level=logging_level, format=format_string)
     logging.debug("start of monitor")
 
     radio = UDPRadio(monitoring_hub_url,


Test patch:
diff --git a/parsl/tests/configs/local_threads_monitoring.py b/parsl/tests/configs/local_threads_monitoring.py
--- a/parsl/tests/configs/local_threads_monitoring.py
+++ b/parsl/tests/configs/local_threads_monitoring.py
@@ -1,5 +1,3 @@
-import logging
-
 from parsl import ThreadPoolExecutor
 from parsl.config import Config
 from parsl.monitoring import MonitoringHub
@@ -8,7 +6,6 @@
                 monitoring=MonitoringHub(
                     hub_address="localhost",
                     hub_port=55055,
-                    logging_level=logging.INFO,
                     resource_monitoring_interval=3,
                 )
          )