diff --git a/pkg/hpa/service.go b/pkg/hpa/service.go index 9bfd1237..2fe5bd87 100644 --- a/pkg/hpa/service.go +++ b/pkg/hpa/service.go @@ -393,8 +393,10 @@ func (c *Service) ChangeHPAFromTortoiseRecommendation(tortoise *autoscalingv1bet if err != nil { return nil, tortoise, fmt.Errorf("get minReplicas recommendation: %w", err) } - metrics.AppliedHPAMinReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(recommendMin)) - metrics.AppliedHPAMaxReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(recommendMax)) + if recordMetrics { + metrics.ProposedHPAMinReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(recommendMin)) + metrics.ProposedHPAMaxReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(recommendMax)) + } // the minReplicas to be applied is not always the same as the recommended one. var minToActuallyApply int32 @@ -416,8 +418,11 @@ func (c *Service) ChangeHPAFromTortoiseRecommendation(tortoise *autoscalingv1bet minToActuallyApply = recommendMin } hpa.Spec.MinReplicas = &minToActuallyApply - metrics.AppliedHPAMinReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(*hpa.Spec.MinReplicas)) - metrics.AppliedHPAMaxReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(hpa.Spec.MaxReplicas)) + if tortoise.Spec.UpdateMode != autoscalingv1beta2.UpdateModeOff && recordMetrics { + // We don't want to record applied* metric when UpdateMode is Off. + metrics.AppliedHPAMinReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(*hpa.Spec.MinReplicas)) + metrics.AppliedHPAMaxReplicas.WithLabelValues(tortoise.Name, tortoise.Namespace, hpa.Name).Set(float64(hpa.Spec.MaxReplicas)) + } return hpa, tortoise, nil } diff --git a/pkg/vpa/service.go b/pkg/vpa/service.go index 39844d63..19f00e80 100644 --- a/pkg/vpa/service.go +++ b/pkg/vpa/service.go @@ -212,11 +212,17 @@ func (c *Service) UpdateVPAFromTortoiseRecommendation(ctx context.Context, torto for resourcename, value := range r.RecommendedResource { if resourcename == corev1.ResourceCPU { metrics.ProposedCPURequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.MilliValue())) - metrics.AppliedCPURequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.MilliValue())) + if tortoise.Spec.UpdateMode == autoscalingv1beta2.UpdateModeOff { + // We don't want to record applied* metric when UpdateMode is Off. + metrics.AppliedCPURequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.MilliValue())) + } } if resourcename == corev1.ResourceMemory { metrics.ProposedMemoryRequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.Value())) - metrics.AppliedMemoryRequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.Value())) + if tortoise.Spec.UpdateMode == autoscalingv1beta2.UpdateModeOff { + // We don't want to record applied* metric when UpdateMode is Off. + metrics.AppliedMemoryRequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.Value())) + } } } metricsRecorded = true