Skip to content
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

Serializing mode sends nothing in stdin #47

Open
kdubuc opened this issue Feb 5, 2019 · 5 comments
Open

Serializing mode sends nothing in stdin #47

kdubuc opened this issue Feb 5, 2019 · 5 comments
Labels

Comments

@kdubuc
Copy link

kdubuc commented Feb 5, 2019

How serializing works ?

Expected Behaviour

Hi all, I use serializing mode, and I get nothing in STDIN (while streaming works).
Overall, how to use serializing mode ? I want to manipulate the stdin request and set status code, body, headers ... inside my handler, and send out to the stdout. I think it's the best suited mode, but i can get nothing.

Current Behaviour

POST http://openfaas_gateway:8000/function/name
{"foo": "bar"}

With a PHP script :

<?php

$stdin = file_get_contents("php://stdin");

// $stdin is empty ...

fwrite(STDOUT, $stdout); 

// How to write a HTTP response correctly with stdout ?

Steps to Reproduce (for bugs)

This Dockerfile with the script above.

FROM php:alpine
RUN apk add --no-cache git curl
RUN curl -sSLf https://github.com/openfaas-incubator/of-watchdog/releases/download/0.4.6/of-watchdog > /usr/bin/fwatchdog && chmod +x /usr/bin/fwatchdog
COPY index.php /usr/src/function
WORKDIR /usr/src/function
ENV function_process="php index.php"
ENV mode="serializing"
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
CMD ["fwatchdog"]

Context

I want to manipulate the stdin request and set status code, body, headers ... inside my function with stdout.

Your Environment

Docker 18.09.1
Docker swarm
macOs
PHP 7.3

@alexellis
Copy link
Member

Hi how did you decide to use of-watchdog for this?

We already have an official PHP template with the classic watchdog that achieves the same thing.

Alex

@alexellis
Copy link
Member

I want to manipulate and set status code, body, headers ... inside my handle

You can't do that with the serialising mode, what gave you that impression?

You must use http mode to set explicit headers.

If that's something you need to do then look at my example template with of-watchdog and Swoole (PHP) https://github.com/alexellis/php7-swoole-template

Alex

@alexellis
Copy link
Member

Derek add label: support

@derek derek bot added the support label Feb 5, 2019
@alexellis
Copy link
Member

If you need help please join us on Slack as advised on the website. https://docs.openfaas.com/community - there you can join the #templates channel and chat with us more.

@kdubuc
Copy link
Author

kdubuc commented Feb 6, 2019

Thanks for your replies.

Hi how did you decide to use of-watchdog for this?

We already have an official PHP template with the classic watchdog that achieves the same thing.

Alex

The power of openfaas I think is the ability to use any docker images, and turn them into a powerfull FaaS in a microservices universe. The watchdog is a tiny layer, to make it happen. Ideally, the FaaS Dockerfile should be independant of the gateway, but this is a little compromise.
So, I like the fact i can build my Dockerfile, and have total control over them (repository public / private, packages ...), and not being tied to pre-packaged runtimes (like AWS, OpenWhisk, or openfaas templates ...).

I want to manipulate and set status code, body, headers ... inside my handle

You can't do that with the serialising mode, what gave you that impression?

You must use http mode to set explicit headers.

If that's something you need to do then look at my example template with of-watchdog and Swoole (PHP) https://github.com/alexellis/php7-swoole-template

Alex

https://github.com/openfaas-incubator/of-watchdog/blob/master/README.md#L89 :

Reads entire request into memory from the HTTP request. At this point we serialize or modify if required. That is then written into the stdin pipe. Stdout pipe is read into memory and then serialized or modified if necessary before being written back to the HTTP response.

This line confuse me. Overall, multi modes confuses me, because i went into openfaas because the communication between gateway and function is very light and powerful. But, the way stdin and stdout are managed by watchdog depending of types is difficult for me.

It would be great to pass http request as a standardized message into our functions in stdin, no matter of mode. Like :

{
  "type": "httprequest",
  "headers": [...],
  "method": "...",
  "protocol: "...",
  "uri": "...",
  "foo": "body param ..",
  "bar": "query param ..."
}

We process the message, and send in stdout :

{
  "type": "httpresponse",
  "headers": [...],
  "status_code": "xxx",
  "body": "json / octet / base64 ... response"
}

The watch dog transform this message into a proper HTTP response to the gateway.

Also, this can trigger an event like :

{
  "type": "event",
  "topic": "...",
  "foo": "",
  "bar": ""
}

And execute another function ...

It would be a very clear interface between openfass and functions, and avoid confusion 😉

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

No branches or pull requests

2 participants