MCPcopy
hub / github.com/openfaas/faas / scaleService

Function scaleService

gateway/handlers/alerthandler.go:77–101  ·  view source on GitHub ↗
(alert requests.PrometheusInnerAlert, service scaling.ServiceQuery, defaultNamespace string)

Source from the content-addressed store, hash-verified

75}
76
77func scaleService(alert requests.PrometheusInnerAlert, service scaling.ServiceQuery, defaultNamespace string) error {
78 var err error
79
80 serviceName, namespace := middleware.GetNamespace(defaultNamespace, alert.Labels.FunctionName)
81
82 if len(serviceName) > 0 {
83 queryResponse, getErr := service.GetReplicas(serviceName, namespace)
84 if getErr == nil {
85 status := alert.Status
86
87 newReplicas := CalculateReplicas(status, queryResponse.Replicas, uint64(queryResponse.MaxReplicas), queryResponse.MinReplicas, queryResponse.ScalingFactor)
88
89 log.Printf("[Scale] function=%s %d => %d.\n", serviceName, queryResponse.Replicas, newReplicas)
90 if newReplicas == queryResponse.Replicas {
91 return nil
92 }
93
94 updateErr := service.SetReplicas(serviceName, namespace, newReplicas)
95 if updateErr != nil {
96 err = updateErr
97 }
98 }
99 }
100 return err
101}
102
103// CalculateReplicas decides what replica count to set depending on current/desired amount
104func CalculateReplicas(status string, currentReplicas uint64, maxReplicas uint64, minReplicas uint64, scalingFactor uint64) uint64 {

Callers 1

handleAlertsFunction · 0.85

Calls 4

GetNamespaceFunction · 0.92
CalculateReplicasFunction · 0.85
GetReplicasMethod · 0.65
SetReplicasMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…