Closed DanielLee343 closed 1 year ago
The address gateway.openfaas.svc.cluster.local
is incorrect. This only works on Kubernetes.
You will not find that in the Ebook, are you sure that you have a copy?
The only reason I can think of for a function to go to not ready is because you have an unhandled exception and it crashed the function. See the notes in the troubleshooting chapter to get the logs from journalctl for specific functions. No need to copy the input commands here, but have a good look over it.
This is a really well supported use-case, and there's no reason it shouldn't work as described, but you need to get your code right.
Did you say you had a separate issue with vendoring? Do you want to raise an issue so we can support you separately, without crossing streams?
https://github.com/openfaas/golang-http-template
Alex
No, the gateway address is not from the ebook but here. The ebook does have a link in chapter 10 leading me there so I assumed it worked for faasd. Anyway, I'll look into nats-connector as alternative.
Regarding the Not Ready
error, it's because I have a log.Fatal("2", err)
inside error handling, which causes the function to exit with status 1. Removing this solves the problem.
Glad you figured out what was going wrong with your function.
We'll get this closed. Feel free to attend our weekly call if you'd like to say hello or get more support.
/lock: support question resolved
Due diligence
My actions before raising this issue
I tried the similar code on bare metal for standard http request, without any problem. Also restarting faasd didn't help.
Why do you need this?
I want to test multi-function workloads behavior on faasd (e.g., image processing). Currently stuck on inter-function call.
Who is this for?
Academic research on serverless
Expected Behaviour
fn2 should get the http request and send back response to fn1
Current Behaviour
journalctl on faasd shows
error with proxy request to: http://10.62.0.32:8080, Get "http://10.62.0.32:8080": EOF
which means fn2 does not get the request from fn1. Also, when calling fn1, it makes its status fromReady
toNot Ready
, prompts showsCan't reach service for: fn1.
Are you a GitHub Sponsor (Yes/No?)
Check at: https://github.com/sponsors/openfaas
List All Possible Solutions and Workarounds
I wrote the similar code on bare metal to perform http post to another local endpoint, which did not throw any error.
Which Solution Do You Recommend?
Steps to Reproduce (for bugs)
handler.go
:import ( "fmt" "io/ioutil" "log" "net/http" "strings"
)
func Handle(req handler.Request) (handler.Response, error) { client := &http.Client{} var payload = strings.NewReader(
payload
) req, err := http.NewRequest("POST", "http://gateway.openfaas.svc.cluster.local:8080/async-function/fn2",payload) if err != nil { log.Fatal(err) return handler.Response{ Body: []byte("error 1"), StatusCode: http.StatusInternalServerError, }, err } resp, err := client.Do(req) if err != nil { log.Fatal(err) return handler.Response{ Body: []byte("error 2"), StatusCode: http.StatusInternalServerError, }, err } defer resp.Body.Close() bodyText, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) return handler.Response{ Body: []byte("error 3"), StatusCode: http.StatusInternalServerError, }, err } message := fmt.Sprintf("response: %s\n", bodyText) return handler.Response{ Body: []byte(message), StatusCode: http.StatusOK, }, err }package function
import ( "fmt" "net/http"
)
func Handle(req handler.Request) (handler.Response, error) { var err error
}
RUN test -z "$(gofmt -l $(find . -type f -name '.go' -not -path "./vendor/" -not -path "./function/vendor/*"))" || { echo "Run \"gofmt -s -w\" on your Golang code"; exit 1; }
Jan 27 22:13:47 nu-ins-2 faasd[279975]: 2023/01/27 22:13:47 [Deploy] request: {"service":"fn2","image":"lyuze/fn2:latest","envProcess":"./handler","labels":{},"annotations":{}} Jan 27 22:13:48 nu-ins-2 faasd[279975]: 2023/01/27 22:13:48 Image for: docker.io/lyuze/fn2:latest size: 9204111, took: 0.499744s Jan 27 22:13:48 nu-ins-2 faasd[279975]: 2023/01/27 22:13:48 Container ID: fn2 Task ID fn2: Task PID: 389256 Jan 27 22:13:48 nu-ins-2 faasd[279975]: 2023/01/27 22:13:48 fn2 has IP: 10.62.0.36. Jan 27 22:13:48 nu-ins-2 faasd[279975]: 2023/01/27 22:13:48 [Update] request: {"service":"fn1","image":"lyuze/fn1:latest","envProcess":"./handler","labels":{},"annotations":{}} Jan 27 22:13:48 nu-ins-2 faasd[279975]: 2023/01/27 22:13:48 [Update] service fn1 not found Jan 27 22:13:48 nu-ins-2 faasd[279975]: 2023/01/27 22:13:48 [Deploy] request: {"service":"fn1","image":"lyuze/fn1:latest","envProcess":"./handler","labels":{},"annotations":{}} Jan 27 22:13:50 nu-ins-2 faasd[279975]: 2023/01/27 22:13:50 Image for: docker.io/lyuze/fn1:latest size: 9398317, took: 2.061220s Jan 27 22:13:50 nu-ins-2 faasd[279975]: 2023/01/27 22:13:50 Container ID: fn1 Task ID fn1: Task PID: 389420 Jan 27 22:13:50 nu-ins-2 faasd[279975]: 2023/01/27 22:13:50 fn1 has IP: 10.62.0.37.
cc@nu-ins-2:~/functions/test_fn$ faas-cli describe fn1 Name: fn1 Status: Ready Replicas: 1 Available Replicas: 1 Invocations: 4 Image: docker.io/lyuze/fn1:latest Function Process: ./handler URL: http://127.0.0.1:8080/function/fn1 Async URL: http://127.0.0.1:8080/async-function/fn1 Environment: mode: http prefix_logs: false upstream_url: http://127.0.0.1:8082
cc@nu-ins-2:~/functions/test_fn$ curl http://127.0.0.1:8080/function/fn1 Can't reach service for: fn1.
Jan 27 22:14:23 nu-ins-2 faasd[279975]: 2023/01/27 22:14:23 Resolve: "fn1" Jan 27 22:14:23 nu-ins-2 faasd[279975]: 2023/01/27 22:14:23 error with proxy request to: http://10.62.0.37:8080, Get "http://10.62.0.37:8080": EOF
cc@nu-ins-2:~/functions/test_fn$ faas-cli describe fn1 Name: fn1 Status: Not Ready Replicas: 0 Available Replicas: 0 Invocations: 10 Image: docker.io/lyuze/fn1:latest Function Process: ./handler URL: http://127.0.0.1:8080/function/fn1 Async URL: http://127.0.0.1:8080/async-function/fn1 Environment: mode: http prefix_logs: false upstream_url: http://127.0.0.1:8082