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 2020/05/06 13:17:08 UTC

[GitHub] [airflow] kaxil opened a new pull request #8732: Make loading plugins from entrypoint fault-tolerant

kaxil opened a new pull request #8732:
URL: https://github.com/apache/airflow/pull/8732


   Currently `entry_point.load()` enforces dependecies check so if there are version conflicts (or any other Exception) it would result in Airflow Webserver & Scheduler to error.
   
   We should catch errors loading plugins. That shouldn't take down/stop Airflow
   
   ---
   Make sure to mark the boxes below before creating PR: [x]
   
   - [x] Description above provides context of the change
   - [x] Unit tests coverage for changes (not needed for documentation changes)
   - [x] Target Github ISSUE in description if exists
   - [x] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [x] Relevant documentation is updated including usage instructions.
   - [x] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   


----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420956430



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,32 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.import_errors', return_value={})
+@mock.patch('airflow.plugins_manager.plugins', return_value=[])
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
+def test_entrypoint_plugin_errors_dont_raise_exceptions(
+    mock_ep_plugins, mock_plugins, mock_import_errors, caplog
+):
+    """
+    Test that Airflow does not raise an Error if there is any Exception because of the
+    Plugin.
+    """
+    from airflow.plugins_manager import load_entrypoint_plugins, import_errors
+
+    mock_entrypoint = mock.Mock()
+    mock_entrypoint.name = 'test-entrypoint'
+    mock_entrypoint.module_name = 'test.plugins.test_plugins_manager'
+    mock_entrypoint.load.side_effect = Exception('Version Conflict')
+    mock_ep_plugins.return_value = [mock_entrypoint]
+
+    # Clear Logs
+    caplog.clear()

Review comment:
       This causes some problems. Personally, I use `self.assertLogs`. 




----------------------------------------------------------------
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.

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



[GitHub] [airflow] ashb commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420783023



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -18,6 +18,8 @@
 
 import unittest
 
+import mock

Review comment:
       ```suggestion
   from unittest import mock
   ```




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420789097



##########
File path: airflow/plugins_manager.py
##########
@@ -141,13 +141,16 @@ def load_entrypoint_plugins():
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception as e:  # pylint: disable=broad-except
+            log.exception(e)

Review comment:
       Should we add it to import_errors - line 36? This will make this information available on the Web UI.




----------------------------------------------------------------
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r421095462



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,32 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.import_errors', return_value={})
+@mock.patch('airflow.plugins_manager.plugins', return_value=[])
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
+def test_entrypoint_plugin_errors_dont_raise_exceptions(
+    mock_ep_plugins, mock_plugins, mock_import_errors, caplog
+):
+    """
+    Test that Airflow does not raise an Error if there is any Exception because of the
+    Plugin.
+    """
+    from airflow.plugins_manager import load_entrypoint_plugins, import_errors
+
+    mock_entrypoint = mock.Mock()
+    mock_entrypoint.name = 'test-entrypoint'
+    mock_entrypoint.module_name = 'test.plugins.test_plugins_manager'
+    mock_entrypoint.load.side_effect = Exception('Version Conflict')
+    mock_ep_plugins.return_value = [mock_entrypoint]
+
+    # Clear Logs
+    caplog.clear()

Review comment:
       Created https://github.com/apache/airflow/pull/8746 to fix side effects from test_logging_config




----------------------------------------------------------------
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420987502



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,32 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.import_errors', return_value={})
+@mock.patch('airflow.plugins_manager.plugins', return_value=[])
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
+def test_entrypoint_plugin_errors_dont_raise_exceptions(
+    mock_ep_plugins, mock_plugins, mock_import_errors, caplog
+):
+    """
+    Test that Airflow does not raise an Error if there is any Exception because of the
+    Plugin.
+    """
+    from airflow.plugins_manager import load_entrypoint_plugins, import_errors
+
+    mock_entrypoint = mock.Mock()
+    mock_entrypoint.name = 'test-entrypoint'
+    mock_entrypoint.module_name = 'test.plugins.test_plugins_manager'
+    mock_entrypoint.load.side_effect = Exception('Version Conflict')
+    mock_ep_plugins.return_value = [mock_entrypoint]
+
+    # Clear Logs
+    caplog.clear()

Review comment:
       I wonder why though, it is passing locally with Breeze




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420956430



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,32 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.import_errors', return_value={})
+@mock.patch('airflow.plugins_manager.plugins', return_value=[])
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
+def test_entrypoint_plugin_errors_dont_raise_exceptions(
+    mock_ep_plugins, mock_plugins, mock_import_errors, caplog
+):
+    """
+    Test that Airflow does not raise an Error if there is any Exception because of the
+    Plugin.
+    """
+    from airflow.plugins_manager import load_entrypoint_plugins, import_errors
+
+    mock_entrypoint = mock.Mock()
+    mock_entrypoint.name = 'test-entrypoint'
+    mock_entrypoint.module_name = 'test.plugins.test_plugins_manager'
+    mock_entrypoint.load.side_effect = Exception('Version Conflict')
+    mock_ep_plugins.return_value = [mock_entrypoint]
+
+    # Clear Logs
+    caplog.clear()

Review comment:
       This causes some problems. Personally, I use `self.assertLogs`. However, we have a side effect in the global configuration of the logger and you must pass the logger as a parameter for it to work.




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420849958



##########
File path: airflow/plugins_manager.py
##########
@@ -135,19 +135,23 @@ def load_entrypoint_plugins():
     Load and register plugins AirflowPlugin subclasses from the entrypoints.
     The entry_point group should be 'airflow.plugins'.
     """
+    global import_errors  # pylint: disable=global-statement
     global plugins  # pylint: disable=global-statement
 
     entry_points = pkg_resources.iter_entry_points('airflow.plugins')
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception:  # pylint: disable=broad-except
+            log.exception("Failed to import plugin %s", entry_point.name)

Review comment:
       Should we add it to import_errors - line 36? This will make this information available on the Web UI. I see you added global, but you haven't used the variable still.




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420900346



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,28 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')

Review comment:
       ```suggestion
   @mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
   @mock.patch('airflow.plugins_manager.import_errors', {})
   @mock.patch('airflow.plugins_manager.plugins', [])
   ```
   It prevents side effects.




----------------------------------------------------------------
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r421005569



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,32 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.import_errors', return_value={})
+@mock.patch('airflow.plugins_manager.plugins', return_value=[])
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
+def test_entrypoint_plugin_errors_dont_raise_exceptions(
+    mock_ep_plugins, mock_plugins, mock_import_errors, caplog
+):
+    """
+    Test that Airflow does not raise an Error if there is any Exception because of the
+    Plugin.
+    """
+    from airflow.plugins_manager import load_entrypoint_plugins, import_errors
+
+    mock_entrypoint = mock.Mock()
+    mock_entrypoint.name = 'test-entrypoint'
+    mock_entrypoint.module_name = 'test.plugins.test_plugins_manager'
+    mock_entrypoint.load.side_effect = Exception('Version Conflict')
+    mock_ep_plugins.return_value = [mock_entrypoint]
+
+    # Clear Logs
+    caplog.clear()

Review comment:
       Hopefully should work now 🤞 - used self.assertLogs




----------------------------------------------------------------
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.

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



[GitHub] [airflow] ashb commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420782432



##########
File path: airflow/plugins_manager.py
##########
@@ -141,13 +141,16 @@ def load_entrypoint_plugins():
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception as e:  # pylint: disable=broad-except
+            log.exception(e)

Review comment:
       We should log _which_ plugin it was that failed/caused the error too.
   
   Additionally you don't need to include `e`, log.exception will already log that




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420991903



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,32 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.import_errors', return_value={})
+@mock.patch('airflow.plugins_manager.plugins', return_value=[])
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
+def test_entrypoint_plugin_errors_dont_raise_exceptions(
+    mock_ep_plugins, mock_plugins, mock_import_errors, caplog
+):
+    """
+    Test that Airflow does not raise an Error if there is any Exception because of the
+    Plugin.
+    """
+    from airflow.plugins_manager import load_entrypoint_plugins, import_errors
+
+    mock_entrypoint = mock.Mock()
+    mock_entrypoint.name = 'test-entrypoint'
+    mock_entrypoint.module_name = 'test.plugins.test_plugins_manager'
+    mock_entrypoint.load.side_effect = Exception('Version Conflict')
+    mock_ep_plugins.return_value = [mock_entrypoint]
+
+    # Clear Logs
+    caplog.clear()

Review comment:
       I suspect that the side effect in this file:  https://github.com/apache/airflow/blob/master/tests/test_logging_config.py




----------------------------------------------------------------
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420895690



##########
File path: airflow/plugins_manager.py
##########
@@ -135,19 +135,23 @@ def load_entrypoint_plugins():
     Load and register plugins AirflowPlugin subclasses from the entrypoints.
     The entry_point group should be 'airflow.plugins'.
     """
+    global import_errors  # pylint: disable=global-statement
     global plugins  # pylint: disable=global-statement
 
     entry_points = pkg_resources.iter_entry_points('airflow.plugins')
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception:  # pylint: disable=broad-except
+            log.exception("Failed to import plugin %s", entry_point.name)

Review comment:
       Done




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420789097



##########
File path: airflow/plugins_manager.py
##########
@@ -141,13 +141,16 @@ def load_entrypoint_plugins():
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception as e:  # pylint: disable=broad-except
+            log.exception(e)

Review comment:
       Should we add it to import_errors - line 36?




----------------------------------------------------------------
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420895556



##########
File path: airflow/plugins_manager.py
##########
@@ -141,13 +141,16 @@ def load_entrypoint_plugins():
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception as e:  # pylint: disable=broad-except
+            log.exception(e)

Review comment:
       Done




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420789097



##########
File path: airflow/plugins_manager.py
##########
@@ -141,13 +141,16 @@ def load_entrypoint_plugins():
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception as e:  # pylint: disable=broad-except
+            log.exception(e)

Review comment:
       Should we add it to import_errors - line 36? This will make this information available on the Web UI.




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420849958



##########
File path: airflow/plugins_manager.py
##########
@@ -135,19 +135,23 @@ def load_entrypoint_plugins():
     Load and register plugins AirflowPlugin subclasses from the entrypoints.
     The entry_point group should be 'airflow.plugins'.
     """
+    global import_errors  # pylint: disable=global-statement
     global plugins  # pylint: disable=global-statement
 
     entry_points = pkg_resources.iter_entry_points('airflow.plugins')
 
     log.debug("Loading plugins from entrypoints")
 
-    for entry_point in entry_points:
+    for entry_point in entry_points:  # pylint: disable=too-many-nested-blocks
         log.debug('Importing entry_point plugin %s', entry_point.name)
-        plugin_obj = entry_point.load()
-        if is_valid_plugin(plugin_obj):
-            if callable(getattr(plugin_obj, 'on_load', None)):
-                plugin_obj.on_load()
-                plugins.append(plugin_obj)
+        try:
+            plugin_obj = entry_point.load()
+            if is_valid_plugin(plugin_obj):
+                if callable(getattr(plugin_obj, 'on_load', None)):
+                    plugin_obj.on_load()
+                    plugins.append(plugin_obj)
+        except Exception:  # pylint: disable=broad-except
+            log.exception("Failed to import plugin %s", entry_point.name)

Review comment:
       Should we add it to import_errors - line 36? This will make this information available on the Web UI. I see you added global statement, but you haven't used the variable still.




----------------------------------------------------------------
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.

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



[GitHub] [airflow] kaxil commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420915340



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,28 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')

Review comment:
       Fixed




----------------------------------------------------------------
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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8732: Make loading plugins from entrypoint fault-tolerant

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8732:
URL: https://github.com/apache/airflow/pull/8732#discussion_r420900346



##########
File path: tests/plugins/test_plugins_manager.py
##########
@@ -64,3 +65,28 @@ def test_app_blueprints(self):
         # Blueprint should be present in the app
         self.assertTrue('test_plugin' in self.app.blueprints)
         self.assertEqual(self.app.blueprints['test_plugin'].name, bp.name)
+
+
+@mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')

Review comment:
       ```suggestion
   @mock.patch('airflow.plugins_manager.pkg_resources.iter_entry_points')
   @mock.patch('airflow.plugins_manager. import_errors', {})
   ```
   It prevents side effects.




----------------------------------------------------------------
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.

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