Skip to content

Commit

Permalink
Add documentation for scaling handler
Browse files Browse the repository at this point in the history
- documents ScalingConfig and MakeScalingHandler

Signed-off-by: Alex Ellis (VMware) <[email protected]>
  • Loading branch information
alexellis committed Oct 28, 2018
1 parent 0601794 commit 101b062
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions gateway/handlers/scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 101b062

Please sign in to comment.