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

Code review PR of #789 - HTTP paths for functions #832

Merged
merged 9 commits into from
Aug 29, 2018

Conversation

alexellis
Copy link
Member

@alexellis alexellis commented Aug 24, 2018

Description

Closes #789

Docker image for testing: alexellis/gateway:http-paths

telackey and others added 5 commits August 24, 2018 09:33
…atchdog.

Previously, only the query string of the URL was passed through the Gateway.
With this change, the entire path requested by the client is passed through as well as the query string.

While fwatchdog already supported passing the path through, in practice this would not happen
since the Gateway would have swallowed it before forwarding the request to the watchdog.

With this change, the path portion after the function name is added to the Http_Path environment
variable, provided that cgiHeaders are enabled.  This is similar to the of-watchdog equivalent.

Signed-off-by: Thomas E Lackey <[email protected]>
…tion prefix trimming instead of baking it in. Also add a configuration option, 'pass_url_path_to_functions' to control whether the full path is passed to the functions or not.

Signed-off-by: Thomas E Lackey <[email protected]>
This reviews the code and fixes up suggestions made by team for
the HTTP paths PR #789.

- Removed feature-flag (this is backwards-compatible, so I see
no value in adding the flag)
- There was a URL transform happening for calls proxied to the
back end, I changed this for the nil-transform - i.e. it does not
change anything in the URL
- Introduced variables to describe the regex indicies used in
the URL trimming.

Tested with Docker Swarm with a ruby-microservice, with
system calls and with function calls using the UI.

Signed-off-by: Alex Ellis (VMware) <[email protected]>
@alexellis
Copy link
Member Author

Async Path passing is now tested:

faas-cli deploy --name env --fprocess env --network func_functions --image functions/alpine:latest

curl -d "" http://127.0.0.1:8080/async-function/env/path_here

func_queue-worker.1.qk96166nz9ji@nuc    | [#3] Received on [faas-request]: 'sequence:6 subject:"faas-request" data:"{\"Header\":{\"Accept\":[\"*/*\"],\"Content-Length\":[\"0\"],\"Content-Type\":[\"application/x-www-form-urlencoded\"],\"User-Agent\":[\"curl/7.55.1\"],\"X-Call-Id\":[\"09577dcb-46bd-473b-9bf6-ede3f44e96a4\"],\"X-Start-Time\":[\"1535102101843119850\"]},\"Host\":\"127.0.0.1:8080\",\"Body\":\"\",\"Method\":\"POST\",\"Path\":\"/path_here\",\"QueryString\":\"\",\"Function\":\"env\",\"CallbackUrl\":null}" timestamp:1535102101843442385 '

"Path\":\"/path_here\"

Also tested with ?qs=1 and saw that passed through.

Path is empty when nothing is passed after /async-function/env

I tested the path work via Ivana's Ruby guestbook including GET/POST endpoints at different paths.

faas-cli deploy --name guestbook --network func_functions --image docwareiy/guestbook:0.1

screen shot 2018-08-24 at 10 17 16 am

@alexellis
Copy link
Member Author

@telackey please confirm that the original intent is still matched in this follow-up PR.

  • I tested a guestbook microservice in Ruby using GET/POST - worked fine.
  • I tested the UI + CLI + paths were passed to the back-end and routed as expected
  • I tested the Java of-watchdog template which still worked fine when no path was passed
  • I tested async functions include the path variable.

This was altered to "alexellis" for building a testing image,
but shouldn't have been pushed. Reverting.

Signed-off-by: Alex Ellis (VMware) <[email protected]>
@ivanayov
Copy link
Contributor

I tested with docwareiy/guestbook:0.2 for path parameters + url query:
http://127.0.0.1:8080/function/guestbook/signatures?guest=foo%20bar&firstname=foo&lastname=bar
Output:
Visitor foo bar has signed the Guestbook..

http://127.0.0.1:8080/function/guestbook/signatures?guest=test%20bar&firstname=test&lastname=bar
Output:
Visitor test bar has not signed the Guestbook..

Also tested async functions with path parameters.

@ivanayov
Copy link
Contributor

Using this gateway, function invocation count does not increase. Tested both in the UI and Prometheus by gateway_function_invocation_total{function_name="figlet"}.

After reverting to openfaas/gateway:0.8.11 it works as expected.

@alexellis
Copy link
Member Author

Can you find out why?

@ivanayov
Copy link
Contributor

@alexellis I'm looking into it

return func(w http.ResponseWriter, r *http.Request) {
baseURL := baseURLResolver.Resolve(r)

requestURL := r.URL.Path
requestURL := urlPathTransformer.Transform(r)
Copy link
Contributor

@ivanayov ivanayov Aug 24, 2018

Choose a reason for hiding this comment

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

This line seems to break the invocation count bug

This prevented Prometheus metrics from being gathered from the
URL.

Signed-off-by: Alex Ellis (VMware) <[email protected]>
@ivanayov
Copy link
Contributor

Derek add label: blocked

@derek derek bot added the blocked label Aug 27, 2018
@ivanayov
Copy link
Contributor

Derek remove label: blocked

@derek derek bot removed the blocked label Aug 27, 2018
@telackey
Copy link
Contributor

@alexellis

please confirm that the original intent is still matched in this follow-up PR.

Yes, looks good.

@alexellis alexellis merged commit 9c2f6dd into master Aug 29, 2018
Copy link
Member

@LucasRoesler LucasRoesler left a comment

Choose a reason for hiding this comment

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

Everything looks good to me, no glaring holes that I can see.

@alexellis alexellis deleted the alexellis/function_http_paths branch September 1, 2018 17:15
@alexellis
Copy link
Member Author

Appreciated Lucas.

@alexellis
Copy link
Member Author

@telackey do the upstream templates have the ability to pass on a path to their handlers yet?

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.

4 participants