mirror of
https://github.com/openfaas/faas.git
synced 2025-06-23 15:23:29 +00:00
Update comments
- updates comments and adds where missing - updates locks so that unlock is done via defer instead of at the end of the statement - extracts timeout variable in two places - remove makeClient() unused method from metrics package No-harm changes tested via go build. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
@ -14,23 +14,25 @@ import (
|
||||
"github.com/openfaas/faas/gateway/requests"
|
||||
)
|
||||
|
||||
// DefaultMinReplicas is the minimal amount of replicas for a service.
|
||||
const DefaultMinReplicas = 1
|
||||
const (
|
||||
// DefaultMinReplicas is the minimal amount of replicas for a service.
|
||||
DefaultMinReplicas = 1
|
||||
|
||||
// DefaultMaxReplicas is the amount of replicas a service will auto-scale up to.
|
||||
const DefaultMaxReplicas = 20
|
||||
// DefaultMaxReplicas is the amount of replicas a service will auto-scale up to.
|
||||
DefaultMaxReplicas = 20
|
||||
|
||||
// DefaultScalingFactor is the defining proportion for the scaling increments.
|
||||
const DefaultScalingFactor = 20
|
||||
// DefaultScalingFactor is the defining proportion for the scaling increments.
|
||||
DefaultScalingFactor = 20
|
||||
|
||||
// MinScaleLabel label indicating min scale for a function
|
||||
const MinScaleLabel = "com.openfaas.scale.min"
|
||||
// MinScaleLabel label indicating min scale for a function
|
||||
MinScaleLabel = "com.openfaas.scale.min"
|
||||
|
||||
// MaxScaleLabel label indicating max scale for a function
|
||||
const MaxScaleLabel = "com.openfaas.scale.max"
|
||||
// MaxScaleLabel label indicating max scale for a function
|
||||
MaxScaleLabel = "com.openfaas.scale.max"
|
||||
|
||||
// ScalingFactorLabel label indicates the scaling factor for a function
|
||||
const ScalingFactorLabel = "com.openfaas.scale.factor"
|
||||
// ScalingFactorLabel label indicates the scaling factor for a function
|
||||
ScalingFactorLabel = "com.openfaas.scale.factor"
|
||||
)
|
||||
|
||||
// MakeAlertHandler handles alerts from Prometheus Alertmanager
|
||||
func MakeAlertHandler(service ServiceQuery) http.HandlerFunc {
|
||||
@ -130,5 +132,6 @@ func CalculateReplicas(status string, currentReplicas uint64, maxReplicas uint64
|
||||
} else { // Resolved event.
|
||||
newReplicas = minReplicas
|
||||
}
|
||||
|
||||
return newReplicas
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
// functionMatcher parses out the service name (group 1) and rest of path (group 2).
|
||||
var functionMatcher = regexp.MustCompile("^/?(?:async-)?function/([^/?]+)([^?]*)")
|
||||
|
||||
// Indicies and meta-data for functionMatcher regex parts
|
||||
// Indices and meta-data for functionMatcher regex parts
|
||||
const (
|
||||
hasPathCount = 3
|
||||
routeIndex = 0 // routeIndex corresponds to /function/ or /async-function/
|
||||
|
@ -31,6 +31,7 @@ type FunctionCache struct {
|
||||
// Set replica count for functionName
|
||||
func (fc *FunctionCache) Set(functionName string, serviceQueryResponse ServiceQueryResponse) {
|
||||
fc.Sync.Lock()
|
||||
defer fc.Sync.Unlock()
|
||||
|
||||
if _, exists := fc.Cache[functionName]; !exists {
|
||||
fc.Cache[functionName] = &FunctionMeta{}
|
||||
@ -40,23 +41,23 @@ func (fc *FunctionCache) Set(functionName string, serviceQueryResponse ServiceQu
|
||||
entry.LastRefresh = time.Now()
|
||||
entry.ServiceQueryResponse = serviceQueryResponse
|
||||
|
||||
fc.Sync.Unlock()
|
||||
}
|
||||
|
||||
// Get replica count for functionName
|
||||
func (fc *FunctionCache) Get(functionName string) (ServiceQueryResponse, bool) {
|
||||
|
||||
fc.Sync.Lock()
|
||||
defer fc.Sync.Unlock()
|
||||
|
||||
replicas := ServiceQueryResponse{
|
||||
AvailableReplicas: 0,
|
||||
}
|
||||
|
||||
hit := false
|
||||
fc.Sync.Lock()
|
||||
|
||||
if val, exists := fc.Cache[functionName]; exists {
|
||||
replicas = val.ServiceQueryResponse
|
||||
hit = !val.Expired(fc.Expiry)
|
||||
}
|
||||
|
||||
fc.Sync.Unlock()
|
||||
return replicas, hit
|
||||
}
|
||||
|
Reference in New Issue
Block a user