You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by di...@apache.org on 2020/10/17 00:34:52 UTC

[airflow] branch master updated: Fix tcp keepalive parameters parsing (#11594)

This is an automated email from the ASF dual-hosted git repository.

dimberman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 210a948  Fix tcp keepalive parameters parsing (#11594)
210a948 is described below

commit 210a948658b96ef596e3d6f068be033e7fa87b73
Author: MichaƂ Misiewicz <mi...@gmail.com>
AuthorDate: Sat Oct 17 02:34:11 2020 +0200

    Fix tcp keepalive parameters parsing (#11594)
---
 airflow/kubernetes/kube_client.py |  6 +++---
 tests/kubernetes/test_client.py   | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/airflow/kubernetes/kube_client.py b/airflow/kubernetes/kube_client.py
index 3c30807..e51274f 100644
--- a/airflow/kubernetes/kube_client.py
+++ b/airflow/kubernetes/kube_client.py
@@ -78,9 +78,9 @@ def _enable_tcp_keepalive() -> None:
 
     from urllib3.connection import HTTPConnection, HTTPSConnection
 
-    tcp_keep_idle = conf.get('kubernetes', 'tcp_keep_idle', fallback=120)
-    tcp_keep_intvl = conf.get('kubernetes', 'tcp_keep_intvl', fallback=30)
-    tcp_keep_cnt = conf.get('kubernetes', 'tcp_keep_cnt', fallback=6)
+    tcp_keep_idle = conf.getint('kubernetes', 'tcp_keep_idle', fallback=120)
+    tcp_keep_intvl = conf.getint('kubernetes', 'tcp_keep_intvl', fallback=30)
+    tcp_keep_cnt = conf.getint('kubernetes', 'tcp_keep_cnt', fallback=6)
 
     socket_options = [
         (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
diff --git a/tests/kubernetes/test_client.py b/tests/kubernetes/test_client.py
index 8aa83a2..a67efae 100644
--- a/tests/kubernetes/test_client.py
+++ b/tests/kubernetes/test_client.py
@@ -15,11 +15,13 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import socket
 import unittest
 
 import mock
+from urllib3.connection import HTTPConnection, HTTPSConnection
 
-from airflow.kubernetes.kube_client import RefreshConfiguration, get_kube_client
+from airflow.kubernetes.kube_client import RefreshConfiguration, _enable_tcp_keepalive, get_kube_client
 
 
 class TestClient(unittest.TestCase):
@@ -34,3 +36,18 @@ class TestClient(unittest.TestCase):
     def test_load_file_config(self, _, _2):
         client = get_kube_client(in_cluster=False)
         assert isinstance(client.api_client.configuration, RefreshConfiguration)
+
+    def test_enable_tcp_keepalive(self):
+        socket_options = [
+            (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
+            (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 120),
+            (socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 30),
+            (socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 6),
+        ]
+        expected_http_connection_options = HTTPConnection.default_socket_options + socket_options
+        expected_https_connection_options = HTTPSConnection.default_socket_options + socket_options
+
+        _enable_tcp_keepalive()
+
+        self.assertEqual(HTTPConnection.default_socket_options, expected_http_connection_options)
+        self.assertEqual(HTTPSConnection.default_socket_options, expected_https_connection_options)