-
Notifications
You must be signed in to change notification settings - Fork 184
[FLINK-16730][docs] Python SDK Getting Started #77
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
Conversation
4181369 to
61b208d
Compare
rmetzger
left a comment
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.
Looks good overall, left some comments
docs/getting-started/walkthrough.md
Outdated
| It reads and updates the number of times that user has been seen and sends a greeting to the egress. | ||
| ## Configuring for Runtime | ||
|
|
||
| The Apache Flink runtime makes requests to the greeter function by making `http` calls to the `Flask` server. |
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.
Just a thought: Not sure how we are positioning StateFun, but this sounds like something coming directly from Flink?
Maybe we could somehow phrase this to come from the "server side" of statefun running in Flink?
If we are doing a good job, we might have users who are not even really aware that this is powered by Flink.
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'll find a way to rephrase it, you're right, you don't need to understand Flink for this getting started.
That said, I don't think you could go to production without understanding the project's relationship to Flink. We may want to follow up with a dedicated page explaining how these projects are related.
| $ docker-compose exec kafka-broker kafka-console-producer.sh \ | ||
| --broker-list localhost:9092 \ | ||
| --topic names | ||
| $ docker-compose up -d |
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 this supposed to work?
Building master
Step 1/3 : FROM statefun
ERROR: Service 'master' failed to build: pull access denied for statefun, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
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.
Not yet because we haven't released :) In the mean time you can build the image locally using the ./tools/docker/build-stateful-functions.sh script in the tools folder.
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.
Thx. That worked
Step 5/9 : RUN pip install -r requirements.txt
---> Running in 7a9ee7fda4f7
ERROR: Could not find a version that satisfies the requirement apache-flink-statefun (from -r requirements.txt (line 17)) (from versions: none)
ERROR: No matching distribution found for apache-flink-statefun (from -r requirements.txt (line 17))
ERROR: Service 'python-worker' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
How do I get apache-flink-statefun into that Docker build?
I managed to create a RELEASE_VERSION=2.0 ./create_python_sdk_release.sh release
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.
Update greeter/Dockerfile to be
FROM python:3.7-alpine
RUN mkdir -p /app
WORKDIR /app
COPY apache_flink_statefun-snapshot-py3-none-any.whl /app
RUN pip install apache_flink_statefun-snapshot-py3-none-any.whl
COPY requirements.txt /app
RUN pip install -r requirements.txt
COPY greeter.py /app
COPY messages_pb2.py /app
EXPOSE 8000
CMD ["gunicorn", "-b", "0.0.0.0:8000", "-w 4", "greeter:app"]
Again, just a stop gap until the first release. This is why I have the warning that we do not publish snapshot versions of the python sdk.
|
I think it would be very nice to have this for Java as well! |
docs/getting-started/walkthrough.md
Outdated
| ## Persistence | ||
| {% highlight python %} | ||
| @functions.bind("example/greeter") | ||
| def greet(context, message: GreetRequest): |
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.
| def greet(context, message: GreetRequest): | |
| def greet(context, greet_request: GreetRequest): |
Because I get
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/app/greeter.py", line 72, in handle
response_data = handler(request.data)
File "/usr/local/lib/python3.7/site-packages/statefun/request_reply.py", line 39, in __call__
reply = self.handle_invocation(request)
File "/usr/local/lib/python3.7/site-packages/statefun/request_reply.py", line 54, in handle_invocation
self.invoke_batch(batch, context, target_function)
File "/usr/local/lib/python3.7/site-packages/statefun/request_reply.py", line 99, in invoke_batch
fun(context, invocation.argument)
File "/app/greeter.py", line 52, in greet
response = compute_greeting(greet_request.name, state.seen)
NameError: name 'greet_request' is not defined
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.
nice catch
rmetzger
left a comment
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.
Thanks a lot for your work! It is a really nice step by step guide to interactively get a simple development environment for statefun.
Except for one potential issue, I'm +1 on merging this.
Let me know if you are happy with it, I can merge it for you.
3e6ad13 to
b13208b
Compare
|
Thanks for taking the time to review @rmetzger. I just squashed my commits and am happy for you to commit. |
|
Backporting to |
This replaces the old Java walkthrough, which we all agreed was lacking, with an updated Python walkthrough. I think having python only is fine but I'm also comfortable adding Java as a follow up if there is consensus.