Giter Club home page Giter Club logo

faas-provider's Introduction

faas-provider

This faas-provider can be used to write your own back-end for OpenFaaS. The Golang SDK can be vendored into your project so that you can provide a provider which is compliant and compatible with the OpenFaaS gateway.

Conceptual diagram

The faas-provider provides CRUD for functions and an invoke capability. If you complete the required endpoints then you will be able to use your container orchestrator or back-end system with the existing OpenFaaS ecosystem and tooling.

Read more: The power of interfaces in OpenFaaS

Recommendations

The following is used in OpenFaaS and recommended for those seeking to build their own back-ends:

  • License: MIT
  • Language: Golang

How to use this project

All the required HTTP routes are configured automatically including a HTTP server on port 8080. Your task is to implement the supplied HTTP handler functions.

Examples:

OpenFaaS for Kubernetes

See the main.go file in the faas-netes Kubernetes backend.

OpenFaaS for containerd (faasd)

See provider.go for the faasd backend

I.e.:

	timeout := 8 * time.Second
	bootstrapHandlers := bootTypes.FaaSHandlers{
		ListNamespaces: handlers.MakeNamespaceLister(),
		FunctionProxy:  handlers.MakeProxyHandler(),
		FunctionLister: handlers.MakeFunctionLister(),
		DeployFunction: handlers.MakeDeployFunctionHandler(),
		DeleteFunction: handlers.MakeDeleteFunctionHandler(),
		UpdateFunction: handlers.MakeUpdateFunctionHandler(),
		FunctionStatus: handlers.MakeFunctionStatusHandler(),
		ScaleFunction: 	handlers.MakeScaleFunctionHandler(),
		Secrets: 	  	handlers.MakeSecretHandler(),
		Logs: 			handlers.MakeLogsHandler(),
		Info: 			handlers.MakeInfoHandler(),
		Health: 		handlers.MakeHealthHandler(),
	}

	var port int
	port = 8080
	bootstrapConfig := bootTypes.FaaSConfig{
		ReadTimeout:  timeout,
		WriteTimeout: timeout,
		TCPPort:      &port,
	}

	bootstrap.Serve(&bootstrapHandlers, &bootstrapConfig)

faas-provider's People

Contributors

acornies avatar alexellis avatar burtonr avatar dependabot[bot] avatar ewilde avatar johnmccabe avatar lucasroesler avatar mkimberley avatar nitishkumar71 avatar utsavanand2 avatar viveksyngh avatar welteki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

faas-provider's Issues

Fix 0.12.1 tag

Version 0.12.1 was tagged as 012.1.

Tools like dep are currently pulling it in as version 12.1.0, making it the latest release.

Migrate from Travis to Github Actions

As proposed in openfaas/faas#1585 we should move all our repos to Github Actions because of it's generous free-tier as we're not able to get enough builds out of the free credits that Travis provides.
Current Behaviour
We're running all our CI builds using Travis CI
Possible Solution
Move to Github Actions

Proposal: List functions without any form of authentication

Create a new endpoint, like /functions, with only the functions' names in a JSON format which can be called from an upper API in order to display them.

The JSON could be like this :

[
    {
        "name": "<function_name_1>",
        "labels": {
            "function": "true"
        }
    },
    {
        "name": "<function_name_2>",
        "labels": {
            "function": "true"
        }
    },
    {
        "name": "<function_name_3>",
        "labels": {
            "function": "true"
        }
    },
    {
        "name": "<function_name_...>",
        "labels": {
            "function": "true"
        }
    },
    {
        "name": "<function_name_n>",
        "labels": {
            "function": "true"
        }
    }
]

Note : This JSON is already used for the endpoint /system/functions with only "name" and "function" in "labels" keys

This will avoid any call to /system/functions and/or passing credential in a function or environment variables.
A feature of this endpoint can be to be allowed or not in a parameter when installing OpenFaas

Invalid import of httputils

The rename httputils -> httputil done in 8baf21d was not 100% complete. This results in a dep error because the package is malformed

Solving failure: No versions of github.com/openfaas/faas-provider met constraints:
	0.9.0: Could not introduce github.com/openfaas/[email protected], as it is not allowed by constraint ^0.9.2 from project github.com/openfaas/faas-swarm.
	0.9.2: "github.com/openfaas/faas-provider/proxy" imports "github.com/openfaas/faas-provider/httputils", which contains malformed code: no package exists at "github.com/openfaas/faas-provider/httputils"

We should

  1. obviously fix the import, but also
  2. add travisci so that this kind of mistake doesn't sneak in again

Package references

Update package references to point to openfaas/faas-provider from alexellis/faas-provider

More specific error response for timeout

faas-netes log

2022/01/14 10:07:51 error with proxy request to: http://10.32.130.24:8080, Post "http://10.32.130.24:8080\": context canceled

gateway logs

2022/01/14 10:07:51 Forwarded [POST] to /function/fn-2100e53c784e4a88a864449e78ba50b462703696.openfaas-fn-6ccc8843-d78d-49e8-84c4-3734a4af9929 - [500] - 120.004119s seconds

On our side we get a 500 containing "Can't reach service"
We have in the past also seen 502's without body for timeouts from https://github.com/openfaas/faas/blob/52d0165c3f22b5d1c269dd6e43e6e6bda6559936/gateway/handlers/forwarding_proxy.go#L132

Towards our users we would like to report this as a timeout, a few questions pop up:

  • How do we know a response comes from the openfaas middleware vs the actual function? Maybe some specific headers can be set for all responses from openfaas proxies?
  • How do we reconstruct this is a timeout from the generic "Can't reach service"? A standardized error response format would be welcome.
  • Any reason why there is no standard log format in use on openfaas components where log level, namespace, deployment and other info can be filtered on?

Reported here as this repo came up searching for the error messages

Break out proxying code from all providers

The proxying code is repeated in faas-swarm, faas-netes, openfaas-operator and possibly faas-fargate/faas-nomad.

At least the code for the first three should be moved here.

The proxying code is rarely used apart from when direct_functions is set to false. For some reason Capital One need this feature, so we should move the code into one place for maintenance. Each provider will then be able to utilize the package.

A similar move was made for the basic auth middleware that I wrote.

In addition the path parsing/trimming code that passes a HTTP Path to functions needs to be ported over so that functions are not invoked with a PATH like /function/<name>/param1/param2 but with /param1/param2 directly. This code resides in the gateway currently and so it may make sense to also refactor it into a package here.

Summary/tasks

To test turn off direct_functions on your API gateway

  • Refactor/move out the proxying code to a common type package here. Unit tests must be copied/added
  • Add path trimming support to match the gateway's direct_functions approach

Once the above is done and we have a release of faas-provider:

  • Remove code from each provider and have them vendor the package here

InfoRequest should be named InfoResponse

This struct https://github.com/openfaas/faas-provider/blame/master/types/requests.go#L12

Is actually used as a response, so it should be called InfoResponse. See https://github.com/openfaas/faas-swarm/blob/ecf4229ce7dea59ccf8bbf3f96e6f11a669ffe60/handlers/info.go#L18-L43 and https://github.com/openfaas/faas-netes/blob/85492c470c36065f8dc2bba59b5a212d7779a2e9/handlers/info.go#L21-L46

The current name can be confusing when implementing a new provider.

Also, it seems like we could probably completely standardize the the InfoHandler by passing the provider version info, name, and identifier to

func Serve(handlers *types.FaaSHandlers, config *types.FaaSConfig) {
via the FaasConfig object

[Question] Should we remove the Dockerfile

I was about to open a PR for the Go modules migration when I realized that this Dockerfile may need to be updated https://github.com/openfaas/faas-provider/blob/master/Dockerfile

But then I realized I wasn't sure what it was for. It is not referenced in the CI flow or the Readme. It looks like it was an early demo prototype for how the faas-provider works. The Readme now references the concrete implementation in faas-netes, perhaps we can remove this Dockerfile?

Copy remaining request structs from the gateway

While working on the certifier, I wanted to update the vendored code and I realized that many of the request structs had moved to the provider (see #22) but AsyncReport and DeleteFunctionRequest are both still in the gateway.

At the minimum it seems like we should move the delete request. the AsyncReport seems like a response type, not a request type, but it probably make sense to move it too.

Return a typed error from the proxy when there are no endpoints available

Current behaviour

We get a general error then return a HTTP 404 status code, which may be confusing for consumers of the invocation endpoint in the gateway.

Expected behaviour

Return a typed error from the proxy when there are no endpoints available

Context

Returning an error such as 'no endpoints ready' could allow us to tell the gateway to retry an invocation.

Update provider proxy to match gateway's settings

Task

Update provider proxy to match gateway's settings

Context

The tuning done in the gateway copies that which Prometheus, Minio and other projects needed to implement cope with high requests per second.

  • MaxIdleConns
  • MaxIdleConnsPerHost

https://github.com/openfaas/faas/blob/master/gateway/types/proxy_client.go#L14

I was able to crash the proxy code and get time-outs / no files available with 50 concurrent requests in openfaas/faas-netes#533

Once this is complete, I'll revendor faas-provider and test again, I believe it will accept the higher concurrency since it relieved the issue in the gateway originally.

Add created / updated into API for sorting / auditing

Schema change

Add created / updated into API for sorting / auditing

I had a use-case where I wanted to sort the functions by time created, and I couldn't find a way to do that with the function spec. This could also be useful for auditing purposes.

faas-netes

This is available in the Deployment spec already

faasd

The container creation date is probably available, but there isn't a way to update a container without re-creating it, so the created and modified dates would be the same.

Proxy status code is always 200 OK

response, err := proxyClient.Do(proxyReq.WithContext(ctx))
seconds := time.Since(start)
if err != nil {
log.Printf("error with proxy request to: %s, %s\n", proxyReq.URL.String(), err.Error())
writeError(w, http.StatusInternalServerError, "Can't reach service for: %s.", functionName)
return
}
log.Printf("%s took %f seconds\n", functionName, seconds.Seconds())
clientHeader := w.Header()
copyHeaders(clientHeader, &response.Header)
w.Header().Set("Content-Type", getContentType(response.Header, originalReq.Header))
w.WriteHeader(http.StatusOK)
io.Copy(w, response.Body)

Apologies if this was the intention! Just want to understand why we don't proxy the status code back on the response to the client. I got tripped up up debugging an issue where the upstream provider was returning 404, but downstream the response to the client was 200

w.WriteHeader(http.StatusOK)

bug: http status is sometimes 0 in the metrics

When looking at the metrics, we see that the status code is sometimes 0.
image

We expect that this should actually be 200, not 0.

We found that this is caused by two issues in the middleware:

  1. The HTTP response recorder used by the metrics middleware does not always set the status code on the first call to the Write method. To match the stdlb behavior, this should be setting the status code to 200, if it is not set yet.
  2. when the metrics are recorded, it uses the StatusCode field instead of the Status() method, which protects against the 0 value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.