openfaas / workshop

Learn Serverless for Kubernetes with OpenFaaS
https://www.openfaas.com
MIT License
957 stars 317 forks source link

Lab4: Sentiment Analysis only works randomly, and requests.get() does't work #191

Open cheimu opened 3 years ago

cheimu commented 3 years ago

Two problems when doing lab4:

  1. When I try lab4 function chaining, I firstly try echo -n "California is great, it's always sunny there." | faas-cli invoke sentimentanalysis, sometimes it works, but most of time it returns: Server returned unexpected status code: 502 -
  2. When I try function chaining using exactly same code in lab4, but exceptions raised. Cannot recognize gateway in url.

    Expected Behaviour

  3. $ echo -n "California is great, it's always sunny there." | faas-cli invoke sentimentanalysis {"polarity": 0.8, "sentence_count": 1, "subjectivity": 0.75}
  4. "That was probably positive"

    Current Behaviour

  5. Server returned unexpected status code: 502 -
  6. Server returned unexpected status code: 500 - exit status 1 Traceback (most recent call last): File "/home/app/python/urllib3/connection.py", line 169, in _new_conn conn = connection.create_connection( File "/home/app/python/urllib3/util/connection.py", line 73, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "/usr/local/lib/python3.9/socket.py", line 953, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name does not resolve During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/app/python/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/home/app/python/urllib3/connectionpool.py", line 394, in _make_request conn.request(method, url, **httplib_request_kw) File "/home/app/python/urllib3/connection.py", line 234, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "/usr/local/lib/python3.9/http/client.py", line 1255, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/lib/python3.9/http/client.py", line 1301, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.9/http/client.py", line 1250, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.9/http/client.py", line 1010, in _send_output self.send(msg) File "/usr/local/lib/python3.9/http/client.py", line 950, in send self.connect() File "/home/app/python/urllib3/connection.py", line 200, in connect conn = self._new_conn() File "/home/app/python/urllib3/connection.py", line 181, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa86c4c86a0>: Failed to establish a new connection: [Errno -2] Name does not resolve

Possible Solution

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

Your Environment

cheimu commented 3 years ago

I guess I know where the problem is my first question and totally fix my second question where requests.get() does't work.

The solution to my second question: requests.get() does't work the lab4's spec has one typo and one place a little bit confusing 1 typo. It says

Kubernetes

Suffix the gateway host with openfaas namespace:

    r = requests.get("http://gateway.openfaas:8080/function/sentimentanalysis", text= test_sentence)

But it should be r = requests.get("http://gateway.openfaas:8080/function/sentimentanalysis", data= test_sentence) instead. It's data not text !!!

  1. Confusion. Spec says

    Kubernetes

Suffix the gateway host with openfaas namespace:

    r = requests.get("http://gateway.openfaas:8080/function/sentimentanalysis", text= test_sentence)

Or via an environmental variable:

    gateway_hostname = os.getenv("gateway_hostname", "gateway") # uses a default of "gateway" for when "gateway_hostname" is not set
    test_sentence = "California is great, it's always sunny there."
    r = requests.get("http://" + gateway_hostname + ":8080/function/sentimentanalysis", data= test_sentence)

However, "Or via an environmental variable" part description is the syntax for swarm rather than for k8s. For k8s it should be r = requests.get("http://" + gateway_hostname + ".openfaas:8080/function/sentimentanalysis", data= test_sentence) instead. K8s requires namespace openfaas.

As for my first question: Sentiment Analysis only works randomly I can close the issue, since I think it is because sentimentanalysis takes a long time to deploy and my open-faas service is not stable, somethings kubectl port-forward svc/gateway -n openfaas 8080:8080 got broken. E0304 18:44:15.028897 9123 portforward.go:340] error creating error stream for port 8080 -> 8080: EOF Could I get confirmed? Thank you in advance!