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:
Alex Ellis
2018-03-21 10:28:50 +00:00
parent a841e3d7f3
commit 0c7e59fe8a
9 changed files with 172 additions and 26 deletions

View File

@ -0,0 +1,31 @@
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package handlers
import (
"strconv"
"time"
"github.com/openfaas/faas/gateway/metrics"
"github.com/prometheus/client_golang/prometheus"
)
func trackInvocation(service string, metrics metrics.MetricOptions, code int) {
metrics.GatewayFunctionInvocation.With(
prometheus.Labels{"function_name": service,
"code": strconv.Itoa(code)}).Inc()
}
func trackTime(then time.Time, metrics metrics.MetricOptions, name string) {
since := time.Since(then)
metrics.GatewayFunctionsHistogram.
WithLabelValues(name).
Observe(since.Seconds())
}
func trackTimeExact(duration time.Duration, metrics metrics.MetricOptions, name string) {
metrics.GatewayFunctionsHistogram.
WithLabelValues(name).
Observe(float64(duration))
}