openfaas / faasd

A lightweight & portable faas engine
https://store.openfaas.com/l/serverless-for-everyone-else
MIT License
2.97k stars 213 forks source link

Is Scale to Zero included in the Community Edition of OpenFaaS? #353

Closed jaydenrasmussen closed 6 months ago

jaydenrasmussen commented 8 months ago

Due diligence

My actions before raising this issue

Before you ask for help or support, make sure that you've consulted the manual for faasd. We can't answer questions that are already covered by the manual.

Why do you need this?

Scaling to/from zero is a documented use case for faasd

Who is this for?

What company is this for? Are you listed in the ADOPTERS.md file?

Expected Behaviour

Functions scale to zero, per this post and the manual. Example request should work (based on the swagger example)

curl -X POST http://$FAASD_USER:$FAASD_PASS@$FAASD_GATEWAY:8080/system/scale-function/nodeinfo \
-d '{"service":"nodeinfo", "replicas": 0}'

The above linked post actually differs from the swagger doc included in the manual serviceName instead of service.

Current Behaviour

Making a request to the scale-function/{functionName} endpoint with a body containing "service" fails with a 404. The same request using "serviceName" in place of "service" succeeds with 200 however will not scale a function below 1.

List All Possible Solutions and Workarounds

To my knowledge there's not a workaround using faas-cli or the API. If the user has ssh access to the machine they could manually kill the task with ctr.

Which Solution Do You Recommend?

  1. Allow scaling to zero or remove it from the documentation
  2. Fix the swagger documentation (and example)
  3. (optional) add a scale command to the cli faas-cli scale {functionName} 0

Steps to Reproduce (for bugs)

  1. faas-cli store deploy nodeinfo
  2. `curl -X POST http://admin:$(cat /var/lib/faasd/secrets/basic-auth-password)@127.0.0.1:8080/system/scale-function/nodeinfo -d '{"serviceName":"nodeinfo","replicas":0}'
  3. faas-cli list

Your Environment

go version
# not installed
containerd -version
containerd github.com/containerd/containerd v1.7.0 1fbd70374134b891f97ce19c70b6e50c7b9f4e0d

uname -a
Linux bravo 5.15.0-86-generic #96-Ubuntu SMP Wed Sep 20 08:23:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
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"
UBUNTU_CODENAME=jammy

faasd version
  __                     _ 
 / _| __ _  __ _ ___  __| |
| |_ / _` |/ _` / __|/ _` |
|  _| (_| | (_| \__ \ (_| |
|_|  \__,_|\__,_|___/\__,_|

faasd version: 0.18.2   commit: 078043b168d8e18fa2671de9cc1f9aca27d4e9ba
jaydenrasmussen commented 8 months ago

After some further research I came across the following article which makes mention of adding faas-idler to the faasd docker-compose yaml to enable this behavior. Is it expected for users to do this to enable scale to zero? Both the blog post and the official documentation make it seem like this is out of the box functionality.

nitishkumar71 commented 8 months ago

Yes, you are correct. fasad is never supposed to support scaling functionality.

You can use openfass pro or community edition for further use case.

jaydenrasmussen commented 8 months ago

If that's the case then why does the /system/scale-function endpoint exist?

nitishkumar71 commented 8 months ago

Aah, my bad I mistook it for scaling across nodes. I will dig into it.

rgee0 commented 8 months ago

I've reproduced this. It was working in 16.5 (the version I already had available on a microvm) it isn't working with faasd version: 0.18.2 commit: 078043b168d8e18fa2671de9cc1f9aca27d4e9baa

To isolate the problem I would ignore faas-idler for the time being - this would generate the request to the endpoint in the same way you are doing manually.

The gateway returns a 200:

Jan 07 09:32:55 faasd openfaas:gateway[6351]: 2024/01/07 09:32:55 Forwarded [GET] to /system/functions - [200] - 0.0349s
Jan 07 09:33:13 faasd openfaas:gateway[6351]: 2024/01/07 09:33:13 Forwarded [POST] to /system/scale-function/nodeinfo - [200] - 0.0173s
Jan 07 09:33:15 faasd openfaas:gateway[6351]: 2024/01/07 09:33:15 Forwarded [GET] to /system/functions - [200] - 0.0529s
Jan 07 09:36:02 faasd openfaas:gateway[6351]: 2024/01/07 09:36:02 Forwarded [POST] to /system/scale-function/nodeinfo - [200] - 0.0204s

System services deployed:

CONTAINER       IMAGE                                      RUNTIME                  
gateway         ghcr.io/openfaas/gateway:0.27.2            io.containerd.runc.v2    
nats            docker.io/library/nats-streaming:0.25.5    io.containerd.runc.v2    
prometheus      docker.io/prom/prometheus:v2.47.0          io.containerd.runc.v2    
queue-worker    ghcr.io/openfaas/queue-worker:0.14.0       io.containerd.runc.v2 
nitishkumar71 commented 6 months ago

I have been trying to debug it in my local. Yes it's not working as expected. Although, we are sending replicas as 0 in request body as shown in below curl request curl -v -X POST http://$FAASD_USER:$FAASD_PASS@$FAASD_GATEWAY:8080/system/scale-function/env-store-test \ -d '{"serviceName":"env-store-test", "replicas": 0}'

But in faasd logs received request have replica is 1 as shown below Feb 18 20:00:39 faasd-test faasd[7170]: 2024/02/18 20:00:39 [Scale] request: {"serviceName":"env-store-test","replicas":1}

alexellis commented 6 months ago

Hi, scale to zero isn't supported for the Community Edition of OpenFaaS, a commercial license is required for OpenFaaS Standard, which for faasd, we offer at a significant discount per installation vs. the Kubernetes pricing.

faas-idler is a commercial feature of OpenFaaS Standard.

Feel free to reach out.

Alex

alexellis commented 6 months ago

/set title: Is Scale to Zero included in the Community Edition of OpenFaaS?