Lee-W commented on code in PR #67104:
URL: https://github.com/apache/airflow/pull/67104#discussion_r3528288208


##########
airflow-core/src/airflow/logging_config.py:
##########
@@ -120,6 +120,39 @@ def load_logging_config() -> tuple[dict[str, Any], str]:
     ) or DEFAULT_LOGGING_CONFIG_PATH
 
 
+def _warn_if_missing_remote_task_log(logging_class_path: str) -> None:
+    """
+    Warn if ``[logging] remote_logging`` is on but the user module exposes no 
remote IO.
+
+    Runs *after* ``dictConfig`` has constructed handlers, so deprecated
+    self-registration in provider task handlers (Elasticsearch, OpenSearch) has
+    already had its chance to populate 
``_ActiveLoggingConfig.remote_task_log``.
+    Only fires for user-defined ``logging_config_class`` values; the stock
+    fallback is exempt.
+
+    :param logging_class_path: the resolved ``[logging] logging_config_class``
+        dotted path (already defaulted to :data:`DEFAULT_LOGGING_CONFIG_PATH`).
+    """
+    user_defined = bool(logging_class_path) and logging_class_path != 
DEFAULT_LOGGING_CONFIG_PATH

Review Comment:
   ```suggestion
       user_defined = logging_class_path != DEFAULT_LOGGING_CONFIG_PATH
   ```



##########
airflow-core/tests/unit/logging/test_logging_config.py:
##########
@@ -200,3 +201,42 @@ def test_skips_reload_when_already_loaded(self):
             mocked_conf.get.return_value = None
             assert get_default_remote_conn_id() == "cached_conn"
         mock_load.assert_not_called()
+
+
+class TestWarnIfMissingRemoteTaskLog:
+    @pytest.fixture(autouse=True)
+    def _reset_active_logging_config(self, monkeypatch):
+        monkeypatch.setattr(_ActiveLoggingConfig, "remote_task_log", None, 
raising=False)
+        monkeypatch.setattr(_ActiveLoggingConfig, "logging_config_loaded", 
True, raising=False)
+
+    def 
test_warns_when_user_module_missing_remote_task_log_and_remote_logging_enabled(self,
 monkeypatch):
+        monkeypatch.setenv("AIRFLOW__LOGGING__REMOTE_LOGGING", "True")
+        with mock.patch("airflow.logging_config.log") as mock_log:
+            
_warn_if_missing_remote_task_log("my_pkg.custom_settings.LOGGING_CONFIG")
+        mock_log.warning.assert_called_once()
+        assert "my_pkg.custom_settings" in mock_log.warning.call_args.args
+
+    def test_no_warning_when_using_fallback_path(self, monkeypatch):
+        monkeypatch.setenv("AIRFLOW__LOGGING__REMOTE_LOGGING", "True")
+        with mock.patch("airflow.logging_config.log") as mock_log:
+            _warn_if_missing_remote_task_log(DEFAULT_LOGGING_CONFIG_PATH)
+        mock_log.warning.assert_not_called()
+
+    def test_no_warning_when_remote_logging_disabled(self, monkeypatch):
+        monkeypatch.setenv("AIRFLOW__LOGGING__REMOTE_LOGGING", "False")
+        with mock.patch("airflow.logging_config.log") as mock_log:
+            
_warn_if_missing_remote_task_log("my_pkg.custom_settings.LOGGING_CONFIG")
+        mock_log.warning.assert_not_called()
+
+    def test_no_warning_when_remote_task_log_is_set(self, monkeypatch):
+        monkeypatch.setenv("AIRFLOW__LOGGING__REMOTE_LOGGING", "True")
+        monkeypatch.setattr(_ActiveLoggingConfig, "remote_task_log", object(), 
raising=False)
+        with mock.patch("airflow.logging_config.log") as mock_log:
+            
_warn_if_missing_remote_task_log("my_pkg.custom_settings.LOGGING_CONFIG")
+        mock_log.warning.assert_not_called()
+
+    def test_no_warning_when_empty_logging_class_path(self, monkeypatch):
+        monkeypatch.setenv("AIRFLOW__LOGGING__REMOTE_LOGGING", "True")
+        with mock.patch("airflow.logging_config.log") as mock_log:
+            _warn_if_missing_remote_task_log("")
+        mock_log.warning.assert_not_called()

Review Comment:
   these could be parametreize



##########
airflow-core/tests/unit/logging/test_logging_config.py:
##########
@@ -200,3 +201,42 @@ def test_skips_reload_when_already_loaded(self):
             mocked_conf.get.return_value = None
             assert get_default_remote_conn_id() == "cached_conn"
         mock_load.assert_not_called()
+
+
+class TestWarnIfMissingRemoteTaskLog:
+    @pytest.fixture(autouse=True)
+    def _reset_active_logging_config(self, monkeypatch):
+        monkeypatch.setattr(_ActiveLoggingConfig, "remote_task_log", None, 
raising=False)
+        monkeypatch.setattr(_ActiveLoggingConfig, "logging_config_loaded", 
True, raising=False)
+
+    def 
test_warns_when_user_module_missing_remote_task_log_and_remote_logging_enabled(self,
 monkeypatch):
+        monkeypatch.setenv("AIRFLOW__LOGGING__REMOTE_LOGGING", "True")

Review Comment:
   ```suggestion
       @mock.patch.dict(os.environ, {"AIRFLOW__LOGGING__REMOTE_LOGGING": 
"True"})
       def 
test_warns_when_user_module_missing_remote_task_log_and_remote_logging_enabled(self,
 monkeypatch):
   ```
   
   what about something like this? makes it super easy to read



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to