-
Notifications
You must be signed in to change notification settings - Fork 38
Insights 12 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insights 12 #38
Conversation
…emoved the ability to collect insights before sending, now the every time the user invokes the collectInsights method, it will also send. This prevents any State issues with the algorithm.
These test failures are not clear to me. Is it a 2.7 problem? |
Algorithmia/insights.py
Outdated
|
||
class Insights: | ||
# Example of correct insights: | ||
# { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to use a more streamlined key / value pair structure? For example, what we've written up in the documentation proposal for Python so far? (Sorry I didn't get this to you last week):
client.report_insights({"cats_in_image": 4, "dogs_in_image": 7})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I had not seen that document before. I changed the method signatures as well
Algorithmia/insights.py
Outdated
# {"aKey2":"aValue2"} | ||
# } | ||
def __init__(self, insights): | ||
# TODO should we get the URL from a config? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see this use an environment variable with a fallback to localhost. First of all, when doing local dev, 9000 will often already be taken by play server (but this is expecting to hit a sidecar right?). Also, it's difficult to get users to update python client on a schedule, so having more flexibility from the start is valuable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this Jira to set the env variable. https://algorithmia.atlassian.net/browse/INSIGHTS-36. This code has been updated to default to the localhost:9000 if it is not set.
Test/algo_test.py
Outdated
result = self.client.algo('util/Echo').pipe(bytearray('foo','utf-8')) | ||
self.assertEquals('binary', result.metadata.content_type) | ||
self.assertEquals(bytearray('foo','utf-8'), result.result) | ||
# todo fix this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unrelated to the insights code, why did the test need to be commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing in the pipeline, I am not sure what is causing it.
The build is failing for an unrelated test. Any help would be appreciated. |
@kennydaniel the failure in the tests seems to be:
Given that you and Ben worked on this recently, would you have any idea what this might be caused by? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about that failing test; I can't see how it's related to your code, but I'm hoping Kenny might have a thought on that?
setup.py
Outdated
import os | ||
|
||
from setuptools import setup | ||
|
||
setup( | ||
name='algorithmia', | ||
version='1.4.0', | ||
version='1.4.4', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're adding new functionality, it seems like a minor version bump (1.4.0
-> 1.5.0
) would be more appropriate given semver - thoughts @ZachEddy ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I agree. Bumping the minor version makes sense here.
Sidenote: weirdly, this is the only Slack notification that GitHub sent me for this pull request, so I've been missing tons of activity 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to wait to do that bump until we are fully tested as we can only use 1.5.0 once in Pypi, but I will add this to the commit here. I can change it locally when I push to Pypi for testing.
setup.py
Outdated
@@ -1,10 +1,11 @@ | |||
import distutils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is distutils
a new library that is needed for setup but somehow wasn't before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, that was a left over from an unneeded change I tried.
Algorithmia/insights.py
Outdated
headers['Content-Type'] = 'application/json' | ||
AQR_URL = os.getenv('ALGORITHM_QUEUE_READER_URL') or "http://localhost:9000" | ||
|
||
requests.post(AQR_URL+"/insights", data=json.dumps(insights).encode('utf-8'), headers=headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something that came out of the design review: the endpoint in AQR should be prefixed with /v1/
so we can safely make breaking API changes without breaking the v1.X.X
client code.
I still need to modify AQR and add the prefix but that is a small change, so let's go ahead and make the change in this PR.
/insights --> /v1/insights
@@ -40,6 +41,11 @@ def dir(self, dataUrl): | |||
if dataUrl.startswith('file://'): return LocalDataDirectory(self, dataUrl) | |||
else: return DataDirectory(self, dataUrl) | |||
|
|||
# Used to send insight data to Algorithm Queue Reader in cluster | |||
def report_insights(self, insights): | |||
return Insights(insights) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments:
- why are we returning theInsights object? Seems like void return type makes more sense here.
- I think this should be wrapped in a try/catch so make local running easier. Right now I think it will throw exception if running locally with insights.
Will rebuild this PR once AQR with binary payload fix is deployed to production public marketplace. |
@algorithmiaio/developer-technologies-contractors ping for a review please! |
Thanks for your approval @John-Bragg ! You can just leave the PRs open once you approve them because we use Github to merge the changes. |
@robert-close ready for you to merge! |
Adding method to allow users to send insight information from a python algorithm to the queue reader. I am not very experienced with Python, so please point out any areas for improvement or correction. This is a pretty simple flow and I could have just called the request.post from the client, but I feel it is cleaner to have the Insights class segregated.