Skip to content

Commit 76d7b07

Browse files
author
Yahong Gu
committed
Merge branch 'develop'
* develop: bump version to 0.3.3 break long lines into multiple lines to make lint pass add connection timout to client and remove generic exception catching to allow it to propagate, e.g. SIGALRMException
2 parents 3c53fbe + d95f0a6 commit 76d7b07

5 files changed

Lines changed: 20 additions & 30 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.3.2
2+
current_version = 0.3.3
33
commit = False
44
tag = False
55
files = setup.py netuitive/__init__.py

netuitive/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
__author__ = 'Netuitive, Inc'
4-
__version__ = '0.3.2'
4+
__version__ = '0.3.3'
55

66
from .client import Client # nopep8 # flake8: noqa
77
from .element import Element # nopep8 # flake8: noqa

netuitive/client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class Client(object):
3030
"""
3131

3232
def __init__(self, url='https://api.app.netuitive.com/ingest',
33-
api_key='apikey', agent='Netuitive-Python/' + __version__):
33+
api_key='apikey',
34+
agent='Netuitive-Python/' + __version__,
35+
connection_timeout=5):
3436

3537
if url.endswith('/'):
3638
url = url[:-1]
@@ -48,6 +50,7 @@ def __init__(self, url='https://api.app.netuitive.com/ingest',
4850
self.kill_codes = [410, 418]
4951
self.post_error_count = 0
5052
self.max_post_errors = 10
53+
self.connection_timeout = connection_timeout
5154

5255
def post(self, element):
5356
"""
@@ -171,7 +174,7 @@ def post_check(self, check):
171174
headers = {'User-Agent': self.agent}
172175
request = urllib2.Request(
173176
url, data='', headers=headers)
174-
resp = urllib2.urlopen(request)
177+
resp = urllib2.urlopen(request, timeout=self.connection_timeout)
175178
logging.debug("Response code: %d", resp.getcode())
176179
resp.close()
177180

@@ -186,14 +189,10 @@ def post_check(self, check):
186189
'See previous errors for details.')
187190
else:
188191
logging.exception(
189-
'error posting payload to api ingest endpoint (%s): %s',
192+
'HTTPError posting payload to api ingest endpoint'
193+
+ ' (%s): %s',
190194
url, e)
191195

192-
except Exception as e:
193-
logging.exception(
194-
'error posting payload to api ingest endpoint (%s): %s',
195-
url, e)
196-
197196
def check_time_offset(self, epoch=None):
198197
req = urllib2.Request(self.timeurl,
199198
headers={'User-Agent': self.agent})

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
setup(
2626
name='netuitive',
27-
version='0.3.2',
27+
version='0.3.3',
2828
description="Python Client for Netuitive Cloud",
2929
long_description=readme + '\n\n' + history,
3030
author="Netuitive",

tests/test_netuitive_client.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ class TestClientCheckPost(unittest.TestCase):
402402
def setUp(self):
403403
pass
404404

405+
def test_client_connection_timeout(self):
406+
a = netuitive.Client(connection_timeout=30)
407+
self.assertEqual(a.connection_timeout, 30)
408+
405409
@mock.patch('netuitive.client.urllib2.urlopen')
406410
@mock.patch('netuitive.client.logging')
407411
def test_success(self, mock_logging, mock_post):
@@ -417,6 +421,9 @@ def test_success(self, mock_logging, mock_post):
417421

418422
self.assertTrue(resp)
419423

424+
args, kwargs = mock_post.call_args
425+
self.assertEqual(kwargs['timeout'], 5)
426+
420427
self.assertEqual(mock_logging.exception.call_args_list, [])
421428

422429
@mock.patch('netuitive.client.urllib2.urlopen')
@@ -431,27 +438,11 @@ def test_failure_general_http(self, mock_logging, mock_post):
431438

432439
e = netuitive.Check('check', 'test', 60)
433440

434-
resp = a.post_event(e)
435-
436-
self.assertNotEqual(resp, True)
437-
438-
self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'error posting payload to api ingest endpoint (%s): %s')
439-
440-
@mock.patch('netuitive.client.urllib2.urlopen')
441-
@mock.patch('netuitive.client.logging')
442-
def test_failure_general(self, mock_logging, mock_post):
443-
mock_post.side_effect = urllib2.URLError('something')
444-
445-
# test infrastructure endpoint url creation
446-
a = netuitive.Client(api_key='apikey')
447-
448-
c = netuitive.Check('check', 'test', 60)
449-
450-
resp = a.post_check(c)
441+
resp = a.post_check(e)
451442

452443
self.assertNotEqual(resp, True)
453444

454-
self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'error posting payload to api ingest endpoint (%s): %s')
445+
self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'HTTPError posting payload to api ingest endpoint (%s): %s')
455446

456447
@mock.patch('netuitive.client.urllib2.urlopen')
457448
@mock.patch('netuitive.client.logging')
@@ -509,7 +500,7 @@ def test_not_kill_switch_504(self, mock_logging, mock_post):
509500
self.assertNotEqual(resp, True)
510501
self.assertFalse(resp2)
511502
self.assertFalse(a.disabled)
512-
self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'error posting payload to api ingest endpoint (%s): %s')
503+
self.assertEqual(mock_logging.exception.call_args_list[0][0][0], 'HTTPError posting payload to api ingest endpoint (%s): %s')
513504

514505
def tearDown(self):
515506
pass

0 commit comments

Comments
 (0)