Skip to content

Commit aa9fdc1

Browse files
committed
Merge branch '0.1.4'
2 parents 2c29445 + b26a78f commit aa9fdc1

4 files changed

Lines changed: 111 additions & 3 deletions

File tree

HISTORY.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
History
44
-------
55

6+
0.1.4 (2016-04-07)
7+
---------------------
8+
9+
* improve HTTP response error handling
10+
* Update Development Status to 4 - Beta
11+
612
0.1.3 (2016-03-21)
713
---------------------
814

915
* Add user agent to time offset check
10-
* better handling of null element ids
16+
* Better handling of null element ids
1117

1218
0.1.2 (2016-03-09)
1319
---------------------

netuitive/client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def __init__(self, url='https://api.app.netuitive.com/ingest',
4444
self.agent = agent
4545
self.max_metrics = 10000
4646
self.element_dict = {}
47+
self.disabled = False
48+
self.kill_codes = [410, 418]
4749

4850
def post(self, element):
4951
"""
@@ -53,6 +55,11 @@ def post(self, element):
5355

5456
try:
5557

58+
if self.disabled is True:
59+
element.clear_samples()
60+
raise Exception('Posting has been disabled. \
61+
See previous errors for details.')
62+
5663
if element.id is None:
5764
raise Exception('element id is not set')
5865

@@ -80,6 +87,11 @@ def post(self, element):
8087

8188
resp.close()
8289

90+
if resp.getcode() in self.kill_codes:
91+
self.disabled = True
92+
raise Exception('Posting has been disabled. \
93+
See previous errors for details.')
94+
8395
return(True)
8496

8597
else:
@@ -118,6 +130,11 @@ def post_event(self, event):
118130
logging.debug("Response code: %d", resp.getcode())
119131
resp.close()
120132

133+
if resp.getcode() in self.kill_codes:
134+
self.disabled = True
135+
raise Exception('Posting has been disabled. '
136+
'See previous errors for details.')
137+
121138
return(True)
122139

123140
except Exception as e:

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
setup(
2626
name='netuitive',
27-
version='0.1.3',
27+
version='0.1.4',
2828
description="Python Client for Netuitive Cloud",
2929
long_description=readme + '\n\n' + history,
3030
author="Netuitive",
@@ -41,7 +41,7 @@
4141
zip_safe=False,
4242
keywords='netuitive',
4343
classifiers=[
44-
'Development Status :: 2 - Pre-Alpha',
44+
'Development Status :: 4 - Beta',
4545
'Intended Audience :: Developers',
4646
'License :: OSI Approved :: Apache Software License',
4747
'Topic :: Software Development :: Libraries :: Python Modules',

tests/test_netuitive_client.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,51 @@ def test_null_element_id(self, mock_logging, mock_post):
185185
self.assertEqual(str(mock_logging.exception.call_args_list[0][0][2]),
186186
'element id is not set')
187187

188+
@mock.patch('netuitive.client.urllib2.urlopen')
189+
@mock.patch('netuitive.client.logging')
190+
def test_kill_switch_410(self, mock_logging, mock_post):
191+
192+
mock_post.return_value = MockResponse(code=410)
193+
194+
a = netuitive.Client(api_key='apikey')
195+
e = netuitive.Element()
196+
197+
e.add_sample(
198+
'nonsparseDataStrategy', 1434110794, 1, 'COUNTER', host='hostname')
199+
200+
resp = a.post(e)
201+
resp2 = a.post(e)
202+
203+
self.assertNotEqual(resp, True)
204+
self.assertNotEqual(resp2, True)
205+
206+
self.assertTrue(a.disabled)
207+
208+
self.assertEqual(mock_logging.exception.call_args_list[0][0][
209+
0], 'error posting payload to api ingest endpoint (%s): %s')
210+
211+
@mock.patch('netuitive.client.urllib2.urlopen')
212+
@mock.patch('netuitive.client.logging')
213+
def test_kill_switch_418(self, mock_logging, mock_post):
214+
215+
mock_post.return_value = MockResponse(code=418)
216+
217+
a = netuitive.Client(api_key='apikey')
218+
e = netuitive.Element()
219+
220+
e.add_sample(
221+
'nonsparseDataStrategy', 1434110794, 1, 'COUNTER', host='hostname')
222+
223+
resp = a.post(e)
224+
resp2 = a.post(e)
225+
226+
self.assertNotEqual(resp, True)
227+
self.assertNotEqual(resp2, True)
228+
self.assertTrue(a.disabled)
229+
230+
self.assertEqual(mock_logging.exception.call_args_list[0][0][
231+
0], 'error posting payload to api ingest endpoint (%s): %s')
232+
188233
def tearDown(self):
189234
pass
190235

@@ -232,6 +277,46 @@ def test_failure_general(self, mock_logging, mock_post):
232277
self.assertEqual(mock_logging.exception.call_args_list[0][0][
233278
0], 'error posting payload to api ingest endpoint (%s): %s')
234279

280+
@mock.patch('netuitive.client.urllib2.urlopen')
281+
@mock.patch('netuitive.client.logging')
282+
def test_kill_switch_410(self, mock_logging, mock_post):
283+
284+
mock_post.return_value = MockResponse(code=410)
285+
286+
# test infrastructure endpoint url creation
287+
a = netuitive.Client(api_key='apikey')
288+
289+
e = netuitive.Event(
290+
'test', 'INFO', 'test event', 'big old test message', 'INFO')
291+
292+
resp = a.post_event(e)
293+
294+
self.assertNotEqual(resp, True)
295+
self.assertTrue(a.disabled)
296+
297+
self.assertEqual(mock_logging.exception.call_args_list[0][0][
298+
0], 'error posting payload to api ingest endpoint (%s): %s')
299+
300+
@mock.patch('netuitive.client.urllib2.urlopen')
301+
@mock.patch('netuitive.client.logging')
302+
def test_kill_switch_418(self, mock_logging, mock_post):
303+
304+
mock_post.return_value = MockResponse(code=418)
305+
306+
# test infrastructure endpoint url creation
307+
a = netuitive.Client(api_key='apikey')
308+
309+
e = netuitive.Event(
310+
'test', 'INFO', 'test event', 'big old test message', 'INFO')
311+
312+
resp = a.post_event(e)
313+
314+
self.assertNotEqual(resp, True)
315+
self.assertTrue(a.disabled)
316+
317+
self.assertEqual(mock_logging.exception.call_args_list[0][0][
318+
0], 'error posting payload to api ingest endpoint (%s): %s')
319+
235320
def tearDown(self):
236321
pass
237322

0 commit comments

Comments
 (0)