mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 12:06:37 +00:00
Add direct_functions mode to gateway for tuning
Adds a pair of configuration options for performance tuning. The gateway can now invoke functions directly and can bypass the provider. See updated table in README.md for configuration values. BaseURLResolver is added with unit tests that decouples resolving upstream URL from the reverse proxy client code. - SingleHostBaseURLResolver resolves a single upstream host - FunctionAsHostBaseURLResolver resolves host based upon conventions within the URL of the request to a function for direct access Tested with Kubernetes (faas-netes) and faas-swarm through UI, CLI calling system endpoints and functions directly. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
55
gateway/handlers/baseurlresolver_test.go
Normal file
55
gateway/handlers/baseurlresolver_test.go
Normal file
@ -0,0 +1,55 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSingleHostBaseURLResolver(t *testing.T) {
|
||||
|
||||
urlVal, _ := url.Parse("http://upstream:8080/")
|
||||
r := SingleHostBaseURLResolver{BaseURL: urlVal.String()}
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/function/hello", nil)
|
||||
|
||||
resolved := r.Resolve(req)
|
||||
want := "http://upstream:8080"
|
||||
if resolved != want {
|
||||
t.Logf("r.Resolve failed, want: %s got: %s", want, resolved)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
const watchdogPort = 8080
|
||||
|
||||
func TestFunctionAsHostBaseURLResolver_WithSuffix(t *testing.T) {
|
||||
suffix := "openfaas-fn.local.cluster.svc."
|
||||
r := FunctionAsHostBaseURLResolver{FunctionSuffix: suffix}
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/function/hello", nil)
|
||||
|
||||
resolved := r.Resolve(req)
|
||||
want := fmt.Sprintf("http://hello.%s:%d", suffix, watchdogPort)
|
||||
|
||||
if resolved != want {
|
||||
t.Logf("r.Resolve failed, want: %s got: %s", want, resolved)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestFunctionAsHostBaseURLResolver_WithoutSuffix(t *testing.T) {
|
||||
suffix := ""
|
||||
r := FunctionAsHostBaseURLResolver{FunctionSuffix: suffix}
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, "http://localhost/function/hello", nil)
|
||||
|
||||
resolved := r.Resolve(req)
|
||||
want := fmt.Sprintf("http://hello%s:%d", suffix, watchdogPort)
|
||||
|
||||
if resolved != want {
|
||||
t.Logf("r.Resolve failed, want: %s got: %s", want, resolved)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user