diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go
index 1c9382fe21..197162ac47 100644
--- a/apis/v1alpha1/opentelemetrycollector_types.go
+++ b/apis/v1alpha1/opentelemetrycollector_types.go
@@ -41,13 +41,11 @@ type OpenTelemetryCollectorSpec struct {
// MaxReplicas sets an upper bound to the autoscaling feature. If MaxReplicas is set autoscaling is enabled.
// +optional
MaxReplicas *int32 `json:"maxReplicas,omitempty"`
-
// Autoscaler specifies the pod autoscaling configuration to use
// for the OpenTelemetryCollector workload.
//
// +optional
Autoscaler *AutoscalerSpec `json:"autoscaler,omitempty"`
-
// SecurityContext will be set as the container security context.
// +optional
SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"`
@@ -216,6 +214,10 @@ type OpenTelemetryCollectorList struct {
type AutoscalerSpec struct {
// +optional
Behavior *autoscalingv2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
+ // TargetCPUUtilization sets the target average CPU used across all replicas.
+ // If average CPU exceeds this value, the HPA will scale up. Defaults to 90 percent.
+ // +optional
+ TargetCPUUtilization *int32 `json:"targetCPUUtilization,omitempty"`
}
func init() {
diff --git a/apis/v1alpha1/opentelemetrycollector_webhook.go b/apis/v1alpha1/opentelemetrycollector_webhook.go
index 39e5f617df..78e9719628 100644
--- a/apis/v1alpha1/opentelemetrycollector_webhook.go
+++ b/apis/v1alpha1/opentelemetrycollector_webhook.go
@@ -65,6 +65,12 @@ func (r *OpenTelemetryCollector) Default() {
if r.Spec.TargetAllocator.Enabled && r.Spec.TargetAllocator.Replicas == nil {
r.Spec.TargetAllocator.Replicas = &one
}
+
+ // Set default targetCPUUtilization for autoscaler
+ if r.Spec.MaxReplicas != nil && r.Spec.Autoscaler.TargetCPUUtilization == nil {
+ defaultCPUTarget := int32(90)
+ r.Spec.Autoscaler.TargetCPUUtilization = &defaultCPUTarget
+ }
}
// +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1alpha1-opentelemetrycollector,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=opentelemetrycollectors,versions=v1alpha1,name=vopentelemetrycollectorcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
@@ -141,6 +147,10 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleUp should be one or more")
}
}
+ if r.Spec.Autoscaler.TargetCPUUtilization != nil && (*r.Spec.Autoscaler.TargetCPUUtilization < int32(1) || *r.Spec.Autoscaler.TargetCPUUtilization > int32(99)) {
+ return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, targetCPUUtilization should be greater than 0 and less than 100")
+ }
+
}
return nil
diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go
index f2b8397930..e41120b723 100644
--- a/apis/v1alpha1/zz_generated.deepcopy.go
+++ b/apis/v1alpha1/zz_generated.deepcopy.go
@@ -539,4 +539,4 @@ func (in *ScaleSubresourceStatus) DeepCopy() *ScaleSubresourceStatus {
out := new(ScaleSubresourceStatus)
in.DeepCopyInto(out)
return out
-}
+}
\ No newline at end of file
diff --git a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
index 1572235e13..c1e4aa95ae 100644
--- a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
+++ b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
@@ -182,6 +182,12 @@ spec:
type: integer
type: object
type: object
+ targetCPUUtilization:
+ description: TargetCPUUtilization sets the target average CPU
+ used across all replicas. If average CPU exceeds this value,
+ the HPA will scale up. Defaults to 90 percent.
+ format: int32
+ type: integer
type: object
config:
description: Config is the raw JSON to be used as the collector's
diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
index 27e6e0180e..291ce4177e 100644
--- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
+++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
@@ -180,6 +180,12 @@ spec:
type: integer
type: object
type: object
+ targetCPUUtilization:
+ description: TargetCPUUtilization sets the target average CPU
+ used across all replicas. If average CPU exceeds this value,
+ the HPA will scale up. Defaults to 90 percent.
+ format: int32
+ type: integer
type: object
config:
description: Config is the raw JSON to be used as the collector's
diff --git a/docs/api.md b/docs/api.md
index dac36db06f..cfcf113717 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -1896,6 +1896,15 @@ Autoscaler specifies the pod autoscaling configuration to use for the OpenTeleme
HorizontalPodAutoscalerBehavior configures the scaling behavior of the target in both Up and Down directions (scaleUp and scaleDown fields respectively).