Skip to content

Commit e3ac3f7

Browse files
committed
Merge branch 'develop'
2 parents de2d1f9 + cb4e296 commit e3ac3f7

File tree

6 files changed

+25
-84
lines changed

6 files changed

+25
-84
lines changed

.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.2.3
2+
current_version = 0.2.4
33
commit = False
44
tag = False
55
files = setup.py netuitive/__init__.py

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ script:
2929

3030
after_success:
3131
- make coverage
32-
- coveralls
32+
- coveralls
33+
deploy:
34+
provider: pypi
35+
user: netuitive
36+
password:
37+
secure: QrivuUGSznm01ZniDcJ51hLIEM9pKkArxhQEljpYCABklqh0IneTyGQn7yQP0x+kaGOjD6RtkxFgfNg8HKCikw/KSVAU9kH07Qu5HVeECTdPf5dx5Y7xG9njzo0M8AuZwrQWLhlH2JUhYTx1P8NVye46SEpSt79Q3zx/TC0dbdLKTbznLN5DjUoYJz++FNQ3+Dh1E8k9McUc2Pjtbq3oMamuFylkDOh+4DEpx17WsRH/IMNAaLCfYHh+TjByBs+QahKPPKiYI3rGx1fr4su9LWq6e5bk8Yi36XVeLBp+CdoqRsTgXsH2OthGqvqpHopchaibenuw9EGx8BaAUCdhanolZ6jH+YeUwCjMW0ypF5WV3Jw4TmOYxpWtxPZ+yJN7MewaNW0HVyuJ75qhHFOWI+xzNTk2fk1dsG4Ed+t9Xfa79eEpTrProtnRUAIDHCp4iT6OYv1js2+rrG7M+f2oKxrFsYf/m5IQjzZDT2NLCf+hKsLdnce1XckklUKM4QbLgcDBY2JOXRkGEhxAgQ9VE78BO/RLZ6bBkv4xu+Rwt5dVPUkniwhQmRTx3GY4uzQAYlFaJ9lh5JV4BIXYWscRf791TSEWH5qfoGTkCEqz8mJ6ExpGzmYo9SbNS/rkEy8VxUHk08luSr1QkpatFHYF0TfrYplBtTKFnMs4PTAUIXg=
38+
on:
39+
tags: true
40+
distributions: sdist bdist_wheel
41+
repo: Netuitive/netuitive-client-python

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.2.3'
4+
__version__ = '0.2.4'
55

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

netuitive/client.py

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def __init__(self, url='https://api.app.netuitive.com/ingest',
4242
uri=urlparse(url))
4343
self.eventurl = self.dataurl.replace('/ingest/', '/ingest/events/', 1)
4444
self.agent = agent
45-
self.max_metrics = 10000
46-
self.element_dict = {}
4745
self.disabled = False
4846
self.kill_codes = [410, 418]
4947
self.post_error_count = 0
@@ -66,46 +64,22 @@ def post(self, element):
6664
if element.id is None:
6765
raise Exception('element id is not set')
6866

69-
if element.id not in self.element_dict:
70-
self.element_dict[element.id] = []
67+
payload = json.dumps(
68+
[element], default=lambda o: o.__dict__, sort_keys=True)
69+
logging.debug(payload)
7170

72-
for m in element.metrics:
73-
if m.id not in self.element_dict[element.id]:
74-
self.element_dict[element.id].append(m.id)
75-
76-
metric_count = len(self.element_dict[element.id])
77-
78-
if metric_count <= self.max_metrics:
79-
80-
payload = json.dumps(
81-
[element], default=lambda o: o.__dict__, sort_keys=True)
82-
logging.debug(payload)
83-
84-
headers = {'Content-Type': 'application/json',
85-
'User-Agent': self.agent}
86-
request = urllib2.Request(
87-
self.dataurl, data=payload, headers=headers)
88-
resp = urllib2.urlopen(request)
89-
logging.debug("Response code: %d", resp.getcode())
90-
91-
resp.close()
92-
93-
self.post_error_count = 0
94-
95-
return(True)
96-
97-
else:
71+
headers = {'Content-Type': 'application/json',
72+
'User-Agent': self.agent}
73+
request = urllib2.Request(
74+
self.dataurl, data=payload, headers=headers)
75+
resp = urllib2.urlopen(request)
76+
logging.debug("Response code: %d", resp.getcode())
9877

99-
errmsg = ('the {0} element has {1} metrics. '
100-
'the max is {2} metrics.'.format(
101-
element.id, metric_count, self.max_metrics))
78+
resp.close()
10279

103-
logging.debug('{0} has the following metrics: {1}'.format(
104-
element.id,
105-
json.dumps(self.element_dict[element.id])))
80+
self.post_error_count = 0
10681

107-
logging.error(errmsg)
108-
raise Exception(errmsg)
82+
return(True)
10983

11084
except urllib2.HTTPError as e:
11185
logging.debug("Response code: %d", e.code)

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.2.3',
27+
version='0.2.4',
2828
description="Python Client for Netuitive Cloud",
2929
long_description=readme + '\n\n' + history,
3030
author="Netuitive",

tests/test_netuitive_client.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
except ImportError:
3333
import urllib2
3434

35-
3635
def getFixtureDirPath():
3736
path = os.path.join(
3837
os.path.dirname('tests/'),
@@ -177,47 +176,6 @@ def test_failure_general(self, mock_logging, mock_post):
177176
self.assertEqual(mock_logging.exception.call_args_list[0][0][
178177
0], 'error posting payload to api ingest endpoint (%s): %s')
179178

180-
@mock.patch('netuitive.client.urllib2.urlopen')
181-
@mock.patch('netuitive.client.logging')
182-
def test_too_many_metrics(self, mock_logging, mock_post):
183-
184-
mock_post.return_value = MockResponse(code=202)
185-
# test infrastructure endpoint url creation
186-
a = netuitive.Client(api_key='apikey')
187-
a.max_metrics = 100
188-
189-
e = netuitive.Element()
190-
191-
for i in range(101):
192-
e.add_sample(
193-
'metric-' + str(i), 1434110794, 1, 'COUNTER', host='hostname')
194-
195-
resp = a.post(e)
196-
197-
self.assertNotEqual(resp, True)
198-
199-
self.assertEqual(mock_logging.exception.call_args_list[0][0][
200-
0], 'error posting payload to api ingest endpoint (%s): %s')
201-
202-
@mock.patch('netuitive.client.urllib2.urlopen')
203-
def test_just_enough_metrics(self, mock_post):
204-
205-
mock_post.return_value = MockResponse(code=202)
206-
# test infrastructure endpoint url creation
207-
a = netuitive.Client(api_key='apikey')
208-
a.max_metrics = 100
209-
210-
e = netuitive.Element()
211-
212-
e.clear_samples()
213-
for i in range(100):
214-
e.add_sample(
215-
'metric-' + str(i), 1434110794, 1, 'COUNTER', host='hostname')
216-
217-
resp = a.post(e)
218-
219-
self.assertEqual(resp, True)
220-
221179
@mock.patch('netuitive.client.urllib2.urlopen')
222180
@mock.patch('netuitive.client.logging')
223181
def test_null_element_id(self, mock_logging, mock_post):

0 commit comments

Comments
 (0)