@@ -35,6 +35,8 @@ type metricsAPIScaler struct {
3535type metricsAPIScalerMetadata struct {
3636 targetValue float64
3737 activationTargetValue float64
38+ ignoreUnavailable bool
39+ defaultValue float64
3840 url string
3941 format APIFormat
4042 valueLocation string
@@ -156,6 +158,24 @@ func parseMetricsAPIMetadata(config *scalersconfig.ScalerConfig) (*metricsAPISca
156158 meta .activationTargetValue = activationTargetValue
157159 }
158160
161+ meta .ignoreUnavailable = false
162+ if val , ok := config .TriggerMetadata ["ignoreUnavailable" ]; ok {
163+ ignoreUnavailable , err := strconv .ParseBool (val )
164+ if err != nil {
165+ return nil , fmt .Errorf ("targetValue parsing error %w" , err )
166+ }
167+ meta .ignoreUnavailable = ignoreUnavailable
168+ }
169+
170+ meta .defaultValue = 0
171+ if val , ok := config .TriggerMetadata ["defaultValue" ]; ok {
172+ defaultValue , err := strconv .ParseFloat (val , 64 )
173+ if err != nil {
174+ return nil , fmt .Errorf ("defaultValue parsing error %w" , err )
175+ }
176+ meta .defaultValue = defaultValue
177+ }
178+
159179 if val , ok := config .TriggerMetadata ["url" ]; ok {
160180 meta .url = val
161181 } else {
@@ -474,13 +494,18 @@ func (s *metricsAPIScaler) GetMetricSpecForScaling(context.Context) []v2.MetricS
474494// GetMetricsAndActivity returns value for a supported metric and an error if there is a problem getting the metric
475495func (s * metricsAPIScaler ) GetMetricsAndActivity (ctx context.Context , metricName string ) ([]external_metrics.ExternalMetricValue , bool , error ) {
476496 val , err := s .getMetricValue (ctx )
497+
477498 if err != nil {
478- return []external_metrics.ExternalMetricValue {}, false , fmt .Errorf ("error requesting metrics endpoint: %w" , err )
499+ if ! s .metadata .ignoreUnavailable {
500+ return []external_metrics.ExternalMetricValue {}, false , fmt .Errorf ("error requesting metrics endpoint: %w" , err )
501+ } else {
502+ metric := GenerateMetricInMili (metricName , s .metadata .defaultValue )
503+ return []external_metrics.ExternalMetricValue {metric }, val > s .metadata .activationTargetValue , nil
504+ }
505+ } else {
506+ metric := GenerateMetricInMili (metricName , val )
507+ return []external_metrics.ExternalMetricValue {metric }, val > s .metadata .activationTargetValue , nil
479508 }
480-
481- metric := GenerateMetricInMili (metricName , val )
482-
483- return []external_metrics.ExternalMetricValue {metric }, val > s .metadata .activationTargetValue , nil
484509}
485510
486511func getMetricAPIServerRequest (ctx context.Context , meta * metricsAPIScalerMetadata ) (* http.Request , error ) {
0 commit comments