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 2021/04/07 23:04:17 UTC

[GitHub] [airflow] jedcunningham opened a new pull request #15263: Add worker_pod_pending_timeout support

jedcunningham opened a new pull request #15263:
URL: https://github.com/apache/airflow/pull/15263


   Instead of allowing pending worker pods to be stuck in pending forever,
   we define a timeout after which point they will be deleted and marked as
   failed. This allows the retry mechanism to be applied to these tasks as
   well.
   
   closes: #15218


-- 
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] jedcunningham commented on a change in pull request #15263: Add worker_pod_pending_timeout support

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



##########
File path: airflow/executors/kubernetes_executor.py
##########
@@ -589,6 +598,44 @@ def sync(self) -> None:
                 break
         # pylint: enable=too-many-nested-blocks
 
+        # Run any pending timed events
+        next_event = self.event_scheduler.run(blocking=False)
+        self.log.debug("Next timed event is in %f", next_event)
+
+    def _check_worker_pods_pending_timeout(self):
+        """Check if any pending worker pods have timed out"""
+        timeout = self.kube_config.worker_pods_pending_timeout
+        self.log.debug('Looking for pending worker pods older than %d seconds', timeout)
+
+        kwargs = {
+            'limit': self.kube_config.worker_pods_pending_timeout_batch_size,
+            'field_selector': 'status.phase=Pending',
+            'label_selector': f'airflow-worker={self.scheduler_job_id}',

Review comment:
       @kaxil, after sitting down to switch to `kubernetes_executor=True` a third time now, I'm leaning towards leaving it based on `scheduler_job_id` for now. I think it is closer to "right", but what we really need is a unique id for the airflow instance itself (most of KubernetsExecutor would actually benefit from having one, in fact).




-- 
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 merged pull request #15263: Add worker_pod_pending_timeout support

Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #15263:
URL: https://github.com/apache/airflow/pull/15263


   


-- 
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 #15263: Add worker_pod_pending_timeout support

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



##########
File path: airflow/executors/kubernetes_executor.py
##########
@@ -589,6 +598,44 @@ def sync(self) -> None:
                 break
         # pylint: enable=too-many-nested-blocks
 
+        # Run any pending timed events
+        next_event = self.event_scheduler.run(blocking=False)
+        self.log.debug("Next timed event is in %f", next_event)
+
+    def _check_worker_pods_pending_timeout(self):
+        """Check if any pending worker pods have timed out"""
+        timeout = self.kube_config.worker_pods_pending_timeout
+        self.log.debug('Looking for pending worker pods older than %d seconds', timeout)
+
+        kwargs = {
+            'limit': self.kube_config.worker_pods_pending_timeout_batch_size,
+            'field_selector': 'status.phase=Pending',
+            'label_selector': f'airflow-worker={self.scheduler_job_id}',

Review comment:
       Yeah I think it would be better to do `kubernetes_executor=True` and catch error (`NotFound` and similar errors) in that loop to avoid race condition.




-- 
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] jedcunningham commented on a change in pull request #15263: Add worker_pod_pending_timeout support

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



##########
File path: airflow/executors/kubernetes_executor.py
##########
@@ -589,6 +598,44 @@ def sync(self) -> None:
                 break
         # pylint: enable=too-many-nested-blocks
 
+        # Run any pending timed events
+        next_event = self.event_scheduler.run(blocking=False)
+        self.log.debug("Next timed event is in %f", next_event)
+
+    def _check_worker_pods_pending_timeout(self):
+        """Check if any pending worker pods have timed out"""
+        timeout = self.kube_config.worker_pods_pending_timeout
+        self.log.debug('Looking for pending worker pods older than %d seconds', timeout)
+
+        kwargs = {
+            'limit': self.kube_config.worker_pods_pending_timeout_batch_size,
+            'field_selector': 'status.phase=Pending',
+            'label_selector': f'airflow-worker={self.scheduler_job_id}',

Review comment:
       The only downside I can see with that is if you had more than 1 instance of Airflow running in a namespace, or on the cluster with multi-namespace mode, you could timeout other instances tasks. Assuming they all have the same timeout it's fine 🤠. Even scheduler_job_id is brittle, just less so. Do we have a better 'unique' something per instance we could use?




-- 
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] jedcunningham commented on a change in pull request #15263: Add worker_pod_pending_timeout support

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



##########
File path: airflow/executors/kubernetes_executor.py
##########
@@ -589,6 +598,44 @@ def sync(self) -> None:
                 break
         # pylint: enable=too-many-nested-blocks
 
+        # Run any pending timed events
+        next_event = self.event_scheduler.run(blocking=False)
+        self.log.debug("Next timed event is in %f", next_event)
+
+    def _check_worker_pods_pending_timeout(self):
+        """Check if any pending worker pods have timed out"""
+        timeout = self.kube_config.worker_pods_pending_timeout
+        self.log.debug('Looking for pending worker pods older than %d seconds', timeout)
+
+        kwargs = {
+            'limit': self.kube_config.worker_pods_pending_timeout_batch_size,
+            'field_selector': 'status.phase=Pending',
+            'label_selector': f'airflow-worker={self.scheduler_job_id}',

Review comment:
       I've limited it to only pending pods from this scheduler, but it could easily be expanded to do any with `kubernetes_executor=True` instead (though, seems this could be a race between schedulers).




-- 
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] jedcunningham commented on a change in pull request #15263: Add worker_pod_pending_timeout support

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



##########
File path: airflow/utils/event_scheduler.py
##########
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import sched
+from typing import Callable
+
+
+class EventScheduler(sched.scheduler):

Review comment:
       If we are happy with moving this into util, I'll add tests 👍
   Also happy to entertain better names.

##########
File path: airflow/executors/kubernetes_executor.py
##########
@@ -589,6 +598,44 @@ def sync(self) -> None:
                 break
         # pylint: enable=too-many-nested-blocks
 
+        # Run any pending timed events
+        next_event = self.event_scheduler.run(blocking=False)
+        self.log.debug("Next timed event is in %f", next_event)
+
+    def _check_worker_pods_pending_timeout(self):
+        """Check if any pending worker pods have timed out"""
+        timeout = self.kube_config.worker_pods_pending_timeout
+        self.log.debug('Looking for pending worker pods older than %d seconds', timeout)
+
+        kwargs = {
+            'limit': self.kube_config.worker_pods_pending_timeout_batch_size,
+            'field_selector': 'status.phase=Pending',
+            'label_selector': f'airflow-worker={self.scheduler_job_id}',

Review comment:
       I've limited it only pending pods from this scheduler, but it could easily be expanded to do any with `kubernetes_executor=True` instead (though, seems this could be a race between schedulers).




-- 
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 #15263: Add worker_pod_pending_timeout support

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



##########
File path: airflow/utils/event_scheduler.py
##########
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import sched
+from typing import Callable
+
+
+class EventScheduler(sched.scheduler):

Review comment:
       No strong opinion on it




-- 
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] jedcunningham commented on a change in pull request #15263: Add worker_pod_pending_timeout support

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



##########
File path: airflow/utils/event_scheduler.py
##########
@@ -0,0 +1,42 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import sched
+from typing import Callable
+
+
+class EventScheduler(sched.scheduler):

Review comment:
       Added test coverage.




-- 
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] github-actions[bot] commented on pull request #15263: Add worker_pod_pending_timeout support

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #15263:
URL: https://github.com/apache/airflow/pull/15263#issuecomment-815338443


   [The Workflow run](https://github.com/apache/airflow/actions/runs/727691986) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


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