handlers

package
v0.0.0-...-91b6c24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxReplicas = 20

DefaultMaxReplicas is the amount of replicas a service will auto-scale up to.

View Source
const DefaultMinReplicas = 1

DefaultMinReplicas is the minimal amount of replicas for a service.

View Source
const DefaultScalingFactor = 20

DefaultScalingFactor is the defining proportion for the scaling increments.

View Source
const MaxScaleLabel = "com.openfaas.scale.max"

MaxScaleLabel label indicating max scale for a function

View Source
const MinScaleLabel = "com.openfaas.scale.min"

MinScaleLabel label indicating min scale for a function

View Source
const ScalingFactorLabel = "com.openfaas.scale.factor"

ScalingFactorLabel label indicates the scaling factor for a function

Variables

This section is empty.

Functions

func CalculateReplicas

func CalculateReplicas(status string, currentReplicas uint64, maxReplicas uint64, minReplicas uint64, scalingFactor uint64) uint64

CalculateReplicas decides what replica count to set depending on current/desired amount

func DecorateWithBasicAuth

func DecorateWithBasicAuth(next http.HandlerFunc, credentials *types.BasicAuthCredentials) http.HandlerFunc

DecorateWithBasicAuth enforces basic auth as a middleware with given credentials

func DecorateWithCORS

func DecorateWithCORS(upstream http.Handler, allowedHost string) http.Handler

DecorateWithCORS decorate a handler with CORS-injecting middleware

func MakeAlertHandler

func MakeAlertHandler(service ServiceQuery) http.HandlerFunc

MakeAlertHandler handles alerts from Prometheus Alertmanager

func MakeAsyncReport

func MakeAsyncReport(metrics metrics.MetricOptions) http.HandlerFunc

MakeAsyncReport makes a handler for asynchronous invocations to report back into.

func MakeCallIDMiddleware

func MakeCallIDMiddleware(next http.HandlerFunc) http.HandlerFunc

MakeCallIDMiddleware middleware tags a request with a uid

func MakeForwardingProxyHandler

func MakeForwardingProxyHandler(proxy *types.HTTPClientReverseProxy, notifiers []HTTPNotifier, baseURLResolver BaseURLResolver) http.HandlerFunc

MakeForwardingProxyHandler create a handler which forwards HTTP requests

func MakeInfoHandler

func MakeInfoHandler(h http.Handler) http.HandlerFunc

MakeInfoHandler is responsible for display component version information

func MakeQueuedProxy

func MakeQueuedProxy(metrics metrics.MetricOptions, wildcard bool, canQueueRequests queue.CanQueueRequests) http.HandlerFunc

MakeQueuedProxy accepts work onto a queue

func MakeScalingHandler

func MakeScalingHandler(next http.HandlerFunc, upstream http.HandlerFunc, config ScalingConfig) http.HandlerFunc

MakeScalingHandler creates handler which can scale a function from zero to 1 replica(s).

Types

type BaseURLResolver

type BaseURLResolver interface {
	Resolve(r *http.Request) string
}

BaseURLResolver URL resolver for upstream requests

type CORSHandler

type CORSHandler struct {
	Upstream    *http.Handler
	AllowedHost string
}

CORSHandler set custom CORS instructions for the store.

func (CORSHandler) ServeHTTP

func (c CORSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FunctionAsHostBaseURLResolver

type FunctionAsHostBaseURLResolver struct {
	FunctionSuffix string
}

FunctionAsHostBaseURLResolver resolves URLs using a function from the URL as a host

func (FunctionAsHostBaseURLResolver) Resolve

Resolve the base URL for a request

type FunctionCache

type FunctionCache struct {
	Cache  map[string]*FunctionMeta
	Expiry time.Duration
	Sync   sync.Mutex
}

FunctionCache provides a cache of Function replica counts

func (*FunctionCache) Get

func (fc *FunctionCache) Get(functionName string) (ServiceQueryResponse, bool)

Get replica count for functionName

func (*FunctionCache) Set

func (fc *FunctionCache) Set(functionName string, serviceQueryResponse ServiceQueryResponse)

Set replica count for functionName

type FunctionMeta

type FunctionMeta struct {
	LastRefresh          time.Time
	ServiceQueryResponse ServiceQueryResponse
}

FunctionMeta holds the last refresh and any other meta-data needed for caching.

func (*FunctionMeta) Expired

func (fm *FunctionMeta) Expired(expiry time.Duration) bool

Expired find out whether the cache item has expired with the given expiry duration from when it was stored.

type HTTPNotifier

type HTTPNotifier interface {
	Notify(method string, URL string, statusCode int, duration time.Duration)
}

HTTPNotifier notify about HTTP request/response

type LoggingNotifier

type LoggingNotifier struct {
}

LoggingNotifier notifies a log about a request

func (LoggingNotifier) Notify

func (LoggingNotifier) Notify(method string, URL string, statusCode int, duration time.Duration)

Notify a log about a request

type PrometheusFunctionNotifier

type PrometheusFunctionNotifier struct {
	Metrics *metrics.MetricOptions
}

PrometheusFunctionNotifier records metrics to Prometheus

func (PrometheusFunctionNotifier) Notify

func (p PrometheusFunctionNotifier) Notify(method string, URL string, statusCode int, duration time.Duration)

Notify records metrics in Prometheus

type ScalingConfig

type ScalingConfig struct {
	MaxPollCount         uint
	FunctionPollInterval time.Duration
	CacheExpiry          time.Duration
	ServiceQuery         ServiceQuery
}

ScalingConfig for scaling behaviours

type ServiceQuery

type ServiceQuery interface {
	GetReplicas(service string) (response ServiceQueryResponse, err error)
	SetReplicas(service string, count uint64) error
}

ServiceQuery provides interface for replica querying/setting

type ServiceQueryResponse

type ServiceQueryResponse struct {
	Replicas          uint64
	MaxReplicas       uint64
	MinReplicas       uint64
	ScalingFactor     uint64
	AvailableReplicas uint64
}

ServiceQueryResponse response from querying a function status

type SingleHostBaseURLResolver

type SingleHostBaseURLResolver struct {
	BaseURL string
}

SingleHostBaseURLResolver resolves URLs against a single BaseURL

func (SingleHostBaseURLResolver) Resolve

Resolve the base URL for a request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL