Conversation
568df92 to
7b075cb
Compare
7b075cb to
14fc194
Compare
|
|
||
| class SumoLogic(object): | ||
|
|
||
| def __init__(self, accessId, accessKey, endpoint=None, cookieFile='cookies.txt'): |
There was a problem hiding this comment.
there are a couple of rough edges here:
- cookies have to be added back if they are really needed
- remove explicitly setting the read timeout to infinity. I don't why but while fetching results for some search jobs I frequently got TimeOutErrors. I think this should be configurable at least.
sumologic/async.py
Outdated
| self.endpoint = str(response.url).replace('/collectors', '') # dirty hack to sanitise URI and retain domain | ||
|
|
||
| async def delete(self, method, params=None): | ||
| await self._guard_endpoint() |
There was a problem hiding this comment.
I did it this way because I felt async constructors are unidiomatic. Are they?
| @@ -0,0 +1,162 @@ | |||
| from copy import copy | |||
There was a problem hiding this comment.
I don't like it that the whole file is basically copied, but I couldn't find a better way. Is there?
| response = await self.session.get('https://api.sumologic.com/api/v1/collectors') # Dummy call to get endpoint | ||
| self.endpoint = str(response.url).replace('/collectors', '') # dirty hack to sanitise URI and retain domain | ||
| async def _set_endpoint(self): | ||
| if self._endpoint is None: |
There was a problem hiding this comment.
double checked locking to avoid sending the request more than once
| params = {'query': query, 'from': fromTime, 'to': toTime, 'timeZone': timeZone} | ||
| r = await self.post('/search/jobs', params) | ||
| return json.loads(await r.text()) | ||
| async with r: |
There was a problem hiding this comment.
prevents leaking response objects
| return json.loads(await r.text()), r.headers['etag'] | ||
|
|
||
| async def create_source(self, collector_id, source): | ||
| return await self.post('/collectors/' + str(collector_id) + '/sources', source) |
There was a problem hiding this comment.
i cannot prevent leaking here without changing the API, as this returns the request object itself.
| SumoLogic REST API endpoint changes based on the geo location of the client. | ||
| For example, If the client geolocation is Australia then the REST end point is | ||
| https://api.au.sumologic.com/api/v1 | ||
| async def __aenter__(self): |
There was a problem hiding this comment.
for safely closing the connection
There was a problem hiding this comment.
also it maybe wort exposing a close method.
| async def search_metrics(self, query, fromTime=None, toTime=None, requestedDataPoints=600, maxDataPoints=800): | ||
| '''Perform a single Sumo metrics query''' | ||
|
|
||
| def millisectimestamp(ts): |
There was a problem hiding this comment.
I believe the common functions should be extracted to a util namespace to reduce code duplications.
I added a proof of concept implementation for this lib whihc uses async http:
https://aiohttp.readthedocs.io/en/stable/index.html
I don't know yet how to include this code in a way that does not break interpreters below 3.5. I want to avoid putting it into a string and execing.
I am not very familiar with Python yet, so I appricieate any help on this. Thanks!