Feature for probing functions

Introduces a single-flight call to a function's health
endpoint to verify that it is registered with an Istio
sidecar (Envoy) before letting the invocation through.

Results are cached for 5 seconds, before a probe is
required again.

Tested without Istio, with probe_functions environment
variable set to true, I saw a probe execute in the logs.

Fixes: #1721 for Istio users.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2022-06-29 10:09:01 +01:00
committed by Alex Ellis
parent 01841f605c
commit 88eea5f62e
43 changed files with 784 additions and 468 deletions

View File

@ -0,0 +1,34 @@
// Copyright (c) OpenFaaS Author(s). All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package middleware
import (
"net/http"
"testing"
)
func Test_Transform_DoesntTransformRootPath(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, "/", nil)
transformer := TransparentURLPathTransformer{}
want := req.URL.Path
got := transformer.Transform(req)
if want != got {
t.Errorf("want: %s, got: %s", want, got)
}
}
func Test_Transform_DoesntTransformAdditionalPath(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, "/employees/", nil)
transformer := TransparentURLPathTransformer{}
want := req.URL.Path
got := transformer.Transform(req)
if want != got {
t.Errorf("want: %s, got: %s", want, got)
}
}