Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Python and Ruby runtimes don't expose event.extensions.response #28

Open
jmtoball opened this issue Apr 10, 2019 · 6 comments
Open

Python and Ruby runtimes don't expose event.extensions.response #28

jmtoball opened this issue Apr 10, 2019 · 6 comments

Comments

@jmtoball
Copy link

jmtoball commented Apr 10, 2019

While the documentation lists it and the PHP, Go and Node runtimes include the response-object in the event extensions, the Python and Ruby runtimes do not. As do the ballerina, Java and .Net-runtimes, but their Handlers seem a bit different anyway, while the Bottle/Sinatra-Request/Response objects could probably be handled similarly to the express ones.

Is this on purpose or an oversight?

My usecase is to add headers to the response, which the nodejs runtime allows via the exposed response object, but the Python and Ruby ones don't. If there is another way to do this, I'd be happy about suggestions.

@andresmgot
Copy link
Contributor

Initially only the request was available for all the runtimes but then some others added support for the response object. Depending on the language (and the framework used) the value returned by the function is used as the full response (like in the case of python and ruby) or just as the body of the response (like in NodeJS).

I am unaware if that is something we can achieve with Python and Ruby (even though it seems that it should be something possible). We are open to contributions in that front.

@jmtoball
Copy link
Author

jmtoball commented Apr 11, 2019

I'm pretty positive about python as it's something you can definitely do with the bottle response-object and sinatry should have similar options. I actually wanted to start on a contribution, but it seems the integration tests or their setup-tooling does not really match reality anymore (looks like they expect the runtimes.jsonnet-file required to build the kubeless.yaml to still be in the kubeless-repo) and I fear I lack the know-how about the two projects to fix that.

I'll still look into the changes necessary on kubeless.py tomorrow and maybe someone can help me out with the test-setup.

@jmtoball
Copy link
Author

I see now why this has not been added before. With the separate memory of the spawned processes, propagating changes to the response-object is not very straight forward.
I managed to get something working using a multiprocessing Manager and Namespace, but it's really ugly: master...jmtoball:expose-response-in-python-runtime

@andresmgot
Copy link
Contributor

Thanks for giving it a try @jmtoball! I am not really a python developer so I have a couple of questions:

  • Is it possible to just forward bottle.response? Something like:
def funcWrap(q, event, c, namespace, bottle):
    event["extensions"]["response"] = bottle.response
  • If the above is not possible, what are the downsides of your solution?

@jmtoball
Copy link
Author

Hey!
funcWrap is executed in a different process. bottle.response would therefore be a new blank response-object. Additionally, once the function was executed, the result would only live in the process scope again. The namespace is the vehicle for crossing the process boundaries.

What I don't like is the fact that I have to copy protected (_-prefixed) members between response instances. Unfortunately, I couldn't find a way around that as the changes aren't automatically propagated via the namespace for complex objects.

@andresmgot
Copy link
Contributor

I see, it seems that we'll be likely introducing new bugs for that. My only suggestion here is not to rely on HTTP headers and adding the required information in the response object that we have.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants