You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/31 19:42:11 UTC

[GitHub] [airflow] jedcunningham commented on a change in pull request #22588: Print configuration on scheduler startup.

jedcunningham commented on a change in pull request #22588:
URL: https://github.com/apache/airflow/pull/22588#discussion_r839949884



##########
File path: tests/cli/commands/test_scheduler_command.py
##########
@@ -87,3 +91,18 @@ def test_graceful_shutdown(self, executor, mock_process, mock_scheduler_job):
                 scheduler_command.scheduler(args)
             finally:
                 mock_process().terminate.assert_called()
+
+    @mock.patch.dict(os.environ, {'AIRFLOW__CORE__PARALLELISM': '35'}, clear=True)
+    @mock.patch("airflow.cli.commands.scheduler_command.SchedulerJob")
+    @mock.patch("airflow.cli.commands.scheduler_command.Process")
+    def test_scheduler_print_config(self, mock_process, mock_scheduler_job):
+        args = self.parser.parse_args(['scheduler'])
+        with conf_vars({("core", "sql_alchemy_conn_cmd"): 'echo hello'}):
+            with contextlib.redirect_stdout(io.StringIO()) as temp_stdout:
+                scheduler_command.scheduler(args)
+                output = temp_stdout.getvalue()
+
+                assert "sql_alchemy_conn = < hidden > [cmd]" in output
+                assert "max_active_tasks_per_dag = 16 [airflow.cfg]" in output
+                assert "parallelism = < hidden > [env var]" in output

Review comment:
       Hmm, why is parallelism hidden 🤔

##########
File path: airflow/utils/cli.py
##########
@@ -328,3 +344,32 @@ def _wrapper(*args, **kwargs):
                     logging.disable(logging.NOTSET)
 
     return cast(T, _wrapper)
+
+
+def get_config_with_source(include_default=False):
+    """
+    Return configuration along with source for each option.
+    """
+    config_dict = conf.as_dict(display_source=True)
+
+    with io.StringIO() as buf, redirect_stdout(buf):
+        for section, options in config_dict.items():
+            if not include_default:
+                options = {
+                    key: (value, source) for key, (value, source) in options.items() if source != "default"
+                }
+
+            # Print the section only when there are options after filtering
+            if options:
+                print(f"[{section}]")
+                for key, (value, source) in options.items():
+                    if not include_default and source == "default":
+                        continue

Review comment:
       ```suggestion
   ```
   
   We've already filtered these out, no?

##########
File path: airflow/utils/cli.py
##########
@@ -328,3 +344,32 @@ def _wrapper(*args, **kwargs):
                     logging.disable(logging.NOTSET)
 
     return cast(T, _wrapper)
+
+
+def get_config_with_source(include_default=False):

Review comment:
       ```suggestion
   def get_config_with_source(include_default: bool = False) -> str:
   ```
   
   nit: let's add typehints




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org