Skip to content

Commit

Permalink
[mq] working branch - merge acb7974 on top of main at 1777fa0
Browse files Browse the repository at this point in the history
{"baseBranch":"main","baseCommit":"1777fa09aad96fbf38625ddbebd2f5db5ef08ec7","createdAt":"2025-01-21T09:48:40.474342Z","headSha":"acb7974c6960aa40618a5ff780529e1f0bded77f","id":"01a8193e-f43d-4e00-ad93-a3f226179957","priority":"200","pullRequestNumber":"266","queuedAt":"2025-01-21T09:48:40.473939Z","status":"STATUS_QUEUED"}
  • Loading branch information
dd-mergequeue[bot] authored Jan 21, 2025
2 parents 0e2005d + acb7974 commit a197bcb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions controllers/datadoghq/replica_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ func (c *ReplicaCalculator) GetRecommenderReplicas(logger logr.Logger, target *a
}

utilizationQuantity := int64(reco.ObservedTargetValue * 1000) // We need to multiply by 1000 to convert it to milliValue
replicaCount, metricPos := adjustReplicaCount(logger, target.Status.Replicas, currentReadyReplicas, wpa, metricName, int32(reco.Replicas), int32(reco.ReplicasLowerBound), int32(reco.ReplicasUpperBound))

labelsWithMetricName := prometheus.Labels{wpaNamePromLabel: wpa.Name, wpaNamespacePromLabel: wpa.Namespace, resourceNamespacePromLabel: wpa.Namespace, resourceNamePromLabel: wpa.Spec.ScaleTargetRef.Name, resourceKindPromLabel: wpa.Spec.ScaleTargetRef.Kind, metricNamePromLabel: metricName}
value.With(labelsWithMetricName).Set(float64(utilizationQuantity))

replicaCount, metricPos := adjustReplicaCount(logger, target.Status.Replicas, currentReadyReplicas, wpa, int32(reco.Replicas), int32(reco.ReplicasLowerBound), int32(reco.ReplicasUpperBound))
logger.Info("Replicas Recommender replica calculation", "metricName", metricName, "replicaCount", replicaCount, "utilizationQuantity", utilizationQuantity, "timestamp", reco.Timestamp, "currentReadyReplicas", currentReadyReplicas)
return ReplicaCalculation{replicaCount, utilizationQuantity, reco.Timestamp, currentReadyReplicas, metricPos, reco.Details}, nil
}
Expand Down Expand Up @@ -472,11 +476,8 @@ func getReplicaCount(logger logr.Logger, currentReplicas, currentReadyReplicas i
return replicaCount, utilizationQuantity.MilliValue(), position
}

func adjustReplicaCount(logger logr.Logger, currentReplicas, currentReadyReplicas int32, wpa *v1alpha1.WatermarkPodAutoscaler, name string, recommendedReplicaCount, upperBoundReplicas, lowerBoundReplicas int32) (replicaCount int32, position metricPosition) {
func adjustReplicaCount(logger logr.Logger, currentReplicas, currentReadyReplicas int32, wpa *v1alpha1.WatermarkPodAutoscaler, recommendedReplicaCount, upperBoundReplicas, lowerBoundReplicas int32) (replicaCount int32, position metricPosition) {
labelsWithReason := prometheus.Labels{wpaNamePromLabel: wpa.Name, wpaNamespacePromLabel: wpa.Namespace, resourceNamespacePromLabel: wpa.Namespace, resourceNamePromLabel: wpa.Spec.ScaleTargetRef.Name, resourceKindPromLabel: wpa.Spec.ScaleTargetRef.Kind, reasonPromLabel: withinBoundsPromLabelVal}
labelsWithMetricName := prometheus.Labels{wpaNamePromLabel: wpa.Name, wpaNamespacePromLabel: wpa.Namespace, resourceNamespacePromLabel: wpa.Namespace, resourceNamePromLabel: wpa.Spec.ScaleTargetRef.Name, resourceKindPromLabel: wpa.Spec.ScaleTargetRef.Kind, metricNamePromLabel: name}

value.With(labelsWithMetricName).Set(float64(recommendedReplicaCount))
msg := ""

position.isBelow = currentReplicas > upperBoundReplicas
Expand Down
8 changes: 5 additions & 3 deletions controllers/datadoghq/watermarkpodautoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,11 @@ func (r *WatermarkPodAutoscalerReconciler) computeReplicasWithRecommender(logger

status := autoscalingv2.MetricStatus{
Type: autoscalingv2.ResourceMetricSourceType,
Resource: &autoscalingv2.ResourceMetricStatus{
Name: corev1.ResourceName(recommenderName),
CurrentAverageValue: *resource.NewMilliQuantity(replicaCalculation.utilization, resource.DecimalSI),
// This is not exactly an external metric, but this will be used to display the recommendation in the CLI.
External: &autoscalingv2.ExternalMetricStatus{
MetricSelector: &metav1.LabelSelector{},
MetricName: recommenderName,
CurrentValue: *resource.NewMilliQuantity(replicaCalculation.utilization, resource.DecimalSI),
},
}

Expand Down

0 comments on commit a197bcb

Please sign in to comment.