-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Fix k8s pod.execute randomly stuck indefinitely by logs consumption (#23497) #23658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ccdbd54
Fix k8s pod.execute randomly stuck indefinitely by logs consumption (…
schattian 362c150
Add event loop if not running; make linter happy
schattian beeb883
Merge branch 'main' into 23497-tasks-stuck
schattian 109f87b
Fix merge conflicts
schattian 5605a5a
Fix crash when container logs are empty
schattian 86171ff
Add test for kube api hanging logs stream
schattian 67474cc
Fix asyncio loop leaking
schattian 79d38f3
Merge branch 'main' of github.com:apache/airflow into 23497-tasks-stuck
schattian 4c931d5
FIx asyncio loop leaking when task is cancelled
schattian 4ae688b
Shutdown leaking executor
schattian 3050c4e
Merge branch 'main' into 23497-tasks-stuck
schattian 1e291d7
Fix staticcheck
schattian 3177e7f
Do not rely on default executor shutdown
schattian 1daf873
Replace asyncio w/executor with process
schattian f13dd83
Add comment
schattian 2116736
Rm useless comment
schattian d6dbb7d
Merge branch 'main' into 23497-tasks-stuck
schattian 545f09c
Close process
schattian 1cfed55
Add sleep 1s for back compat with following completed logs
schattian 3bee746
Remove special case
schattian d5c916b
Add shared logger in tests to count calls in process
schattian 9e2b444
Merge branch 'main' into 23497-tasks-stuck
schattian 5e63221
Make new methods private
schattian 86a2851
Merge branch 'main' into 23497-tasks-stuck
schattian 644e16c
Revert "Make new methods private"
schattian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # 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 multiprocessing | ||
|
|
||
|
|
||
| class SharedLogger: | ||
| def __init__(self, str_to_count: str, level: str): | ||
| self.counter = multiprocessing.Value('i') | ||
| self.str_to_count = str_to_count | ||
| self.level = level | ||
|
|
||
| def info(self, message, *args): | ||
| self._count(message, "info") | ||
|
|
||
| def warning(self, message, *args): | ||
| self._count(message, "warning") | ||
|
|
||
| def debug(self, message, *args): | ||
| self._count(message, "debug") | ||
|
|
||
| def error(self, message, *args): | ||
| self._count(message, "error") | ||
|
|
||
| def _count(self, message, level): | ||
| if level != self.level: | ||
| return | ||
| if message == self.str_to_count: | ||
| self.counter.value += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| from airflow.utils import timezone | ||
| from airflow.utils.types import DagRunType | ||
| from airflow.version import version as airflow_version | ||
| from kubernetes_tests.kubernetes_test_utils import SharedLogger | ||
|
|
||
| HOOK_CLASS = "airflow.providers.cncf.kubernetes.operators.kubernetes_pod.KubernetesHook" | ||
| POD_MANAGER_CLASS = "airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager" | ||
|
|
@@ -430,7 +431,9 @@ def test_port(self): | |
| assert self.expected_pod == actual_pod | ||
|
|
||
| def test_volume_mount(self): | ||
| with mock.patch.object(PodManager, 'log') as mock_logger: | ||
| with mock.patch.object( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. notice a non-thread-safe counter (default) makes this test flaky or impossible to do as the call of log.info happens in a process. |
||
| PodManager, 'log', new=SharedLogger("retrieved from mount", "info") | ||
| ) as mock_logger: | ||
| volume_mount = k8s.V1VolumeMount( | ||
| name='test-volume', mount_path='/tmp/test_volume', sub_path=None, read_only=False | ||
| ) | ||
|
|
@@ -459,7 +462,9 @@ def test_volume_mount(self): | |
| ) | ||
| context = create_context(k) | ||
| k.execute(context=context) | ||
| mock_logger.info.assert_any_call('retrieved from mount') | ||
|
|
||
| assert mock_logger.counter.value == 1 | ||
|
|
||
| actual_pod = self.api_client.sanitize_for_serialization(k.pod) | ||
| self.expected_pod['spec']['containers'][0]['args'] = args | ||
| self.expected_pod['spec']['containers'][0]['volumeMounts'] = [ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.