From 101b06243bb5451a4991eca6533500cbae2aed32 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (VMware)" Date: Sun, 28 Oct 2018 12:24:25 +0000 Subject: [PATCH] Add documentation for scaling handler - documents ScalingConfig and MakeScalingHandler Signed-off-by: Alex Ellis (VMware) --- gateway/handlers/scaling.go | 20 +++++++++++++++----- gateway/server.go | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gateway/handlers/scaling.go b/gateway/handlers/scaling.go index aa32a5ce..a9dcb171 100644 --- a/gateway/handlers/scaling.go +++ b/gateway/handlers/scaling.go @@ -12,15 +12,25 @@ import ( // ScalingConfig for scaling behaviours type ScalingConfig struct { - MaxPollCount uint + // MaxPollCount attempts to query a function before giving up + MaxPollCount uint + + // FunctionPollInterval delay or interval between polling a function's readiness status FunctionPollInterval time.Duration - CacheExpiry time.Duration - ServiceQuery ServiceQuery + + // CacheExpiry life-time for a cache entry before considering invalid + CacheExpiry time.Duration + + // ServiceQuery queries available/ready replicas for function + ServiceQuery ServiceQuery } // MakeScalingHandler creates handler which can scale a function from -// zero to 1 replica(s). -func MakeScalingHandler(next http.HandlerFunc, upstream http.HandlerFunc, config ScalingConfig) http.HandlerFunc { +// zero to N replica(s). After scaling the next http.HandlerFunc will +// be called. If the function is not ready after the configured +// amount of attempts / queries then next will not be invoked and a status +// will be returned to the client. +func MakeScalingHandler(next http.HandlerFunc, config ScalingConfig) http.HandlerFunc { cache := FunctionCache{ Cache: make(map[string]*FunctionMeta), Expiry: config.CacheExpiry, diff --git a/gateway/server.go b/gateway/server.go index 8c8ab25d..9a3d1545 100644 --- a/gateway/server.go +++ b/gateway/server.go @@ -141,7 +141,7 @@ func main() { ServiceQuery: alertHandler, } - functionProxy = handlers.MakeScalingHandler(faasHandlers.Proxy, faasHandlers.QueryFunction, scalingConfig) + functionProxy = handlers.MakeScalingHandler(faasHandlers.Proxy, scalingConfig) } // r.StrictSlash(false) // This didn't work, so register routes twice. r.HandleFunc("/function/{name:[-a-zA-Z_0-9]+}", functionProxy)