Skip to content

Conversation

robert-close
Copy link
Contributor

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.

@robert-close
Copy link
Contributor Author

These test failures are not clear to me. Is it a 2.7 problem?


class Insights:
# Example of correct insights:
# {
Copy link
Contributor

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})

Copy link
Contributor Author

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

# {"aKey2":"aValue2"}
# }
def __init__(self, insights):
# TODO should we get the URL from a config?
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@robert-close robert-close marked this pull request as ready for review September 10, 2020 18:51
@robert-close
Copy link
Contributor Author

The build is failing for an unrelated test. Any help would be appreciated.

@dinoboy197
Copy link
Contributor

@kennydaniel the failure in the tests seems to be:

__________________________ AlgoTest.test_call_binary ___________________________

self = <Test.algo_test.AlgoTest testMethod=test_call_binary>

    def test_call_binary(self):
        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)
E       AssertionError: bytearray(b'foo') != 'Zm9v'

Given that you and Ben worked on this recently, would you have any idea what this might be caused by?

Copy link
Contributor

@dinoboy197 dinoboy197 left a 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',
Copy link
Contributor

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 ?

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 😕

Copy link
Contributor Author

@robert-close robert-close Sep 15, 2020

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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)

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments:

  1. why are we returning theInsights object? Seems like void return type makes more sense here.
  2. 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.

@dinoboy197
Copy link
Contributor

Will rebuild this PR once AQR with binary payload fix is deployed to production public marketplace.

@dinoboy197 dinoboy197 requested a review from a team October 2, 2020 23:53
@dinoboy197
Copy link
Contributor

@algorithmiaio/developer-technologies-contractors ping for a review please!

@John-Bragg John-Bragg closed this Oct 6, 2020
@dinoboy197
Copy link
Contributor

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.

@dinoboy197 dinoboy197 reopened this Oct 6, 2020
@dinoboy197
Copy link
Contributor

@robert-close ready for you to merge!

@robert-close robert-close merged commit 1d0b5b3 into master Oct 6, 2020
@robert-close robert-close deleted the INSIGHTS-12 branch October 6, 2020 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants