-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define bool to determine when local fallback active
- Loading branch information
Showing
3 changed files
with
128 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
pkg/clusteragent/autoscaling/workload/model/recommendations.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2024-present Datadog, Inc. | ||
|
||
//go:build kubeapiserver | ||
|
||
package model | ||
|
||
import ( | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
||
datadoghq "github.com/DataDog/datadog-operator/apis/datadoghq/v1alpha1" | ||
) | ||
|
||
// ScalingValues represents the scaling values (horizontal and vertical) for a target | ||
type ScalingValues struct { | ||
// HorizontalError refers to an error encountered by Datadog while computing the horizontal scaling values | ||
HorizontalError error | ||
Horizontal *HorizontalScalingValues | ||
|
||
// VerticalError refers to an error encountered by Datadog while computing the vertical scaling values | ||
VerticalError error | ||
Vertical *VerticalScalingValues | ||
|
||
// Error refers to a general error encountered by Datadog while computing the scaling values | ||
Error error | ||
} | ||
|
||
// HorizontalScalingValues holds the horizontal scaling values for a target | ||
type HorizontalScalingValues struct { | ||
// Source is the source of the value | ||
Source datadoghq.DatadogPodAutoscalerValueSource | ||
|
||
// Timestamp is the time at which the data was generated | ||
Timestamp time.Time | ||
|
||
// Replicas is the desired number of replicas for the target | ||
Replicas int32 | ||
} | ||
|
||
// VerticalScalingValues holds the vertical scaling values for a target | ||
type VerticalScalingValues struct { | ||
// Source is the source of the value | ||
Source datadoghq.DatadogPodAutoscalerValueSource | ||
|
||
// Timestamp is the time at which the data was generated | ||
Timestamp time.Time | ||
|
||
// ResourcesHash is the hash of containerResources | ||
ResourcesHash string | ||
|
||
// ContainerResources holds the resources for a container | ||
ContainerResources []datadoghq.DatadogPodAutoscalerContainerResources | ||
} | ||
|
||
// SumCPUMemoryRequests sums the CPU and memory requests of all containers | ||
func (v *VerticalScalingValues) SumCPUMemoryRequests() (cpu, memory resource.Quantity) { | ||
for _, container := range v.ContainerResources { | ||
cpuReq := container.Requests.Cpu() | ||
if cpuReq != nil { | ||
cpu.Add(*cpuReq) | ||
} | ||
|
||
memoryReq := container.Requests.Memory() | ||
if memoryReq != nil { | ||
memory.Add(*memoryReq) | ||
} | ||
} | ||
|
||
return | ||
} |