openfaas / python-flask-template

HTTP and Flask-based OpenFaaS templates for Python 3
MIT License
85 stars 86 forks source link

return statusCode ignored, move statusCode to body? #65

Closed rgschmitz1 closed 1 year ago

rgschmitz1 commented 1 year ago

My actions before raising this issue

Expected Behaviour

The return status code should be returned along with the body message.

Current Behaviour

The return 'statusCode' is currently seems to be completely ignored when using curl on an OpenFaas function endpoint. There doesn't seem to be a mechanism to retrieve the statusCode (maybe I'm missing something in the documentation).

Possible Solution

Include the status code in the return body so it can be parsed by end users. As suggested here, https://github.com/openfaas/faas-netes/issues/147#issuecomment-367953472

i.e. in handler.py

def handle(event, context):
    return {
        "body": {
            "statusCode": 200,
            "message": "Hello from OpenFaaS!"
        }
    }

Steps to Reproduce (for bugs)

  1. Modify one of the template handler.py return status codes to be something other than 200 (e.g. 500)
  2. build, push, deploy a container using the template modified
  3. execute the function and check the return status

Context

I'm a graduate student working on a masters capstone comparing performance and cost of cloud native applications running with open sourced software to proprietary solutions from cloud vendors.

Your Environment

CLI: commit: 0074051aeb837f5f160ee8736341460468b5c190 version: 0.15.4

* Docker version `docker version` (e.g. Docker 17.0.05 ):

Client: Docker Engine - Community Version: 20.10.21

* Are you using Docker Swarm or Kubernetes (FaaS-netes)?
`Kubernetes`

* Operating System and version (e.g. Linux, Windows, MacOS):

NAME="Ubuntu" VERSION="20.04.5 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.5 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal



* Code example or link to GitHub repo or gist to reproduce problem:

* Other diagnostic information / logs from [troubleshooting guide](https://docs.openfaas.com/deployment/troubleshooting)
rgschmitz1 commented 1 year ago

I failed to look at the flask-http index, this seems to be parsing the 'statusCode'