Skip to content

Commit

Permalink
Expose Horizontal Pod Autoscaler Behavior and add hpa scaledown test (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#1077)

* Add scaledown test for autoscaling

Signed-off-by: Kevin Earls <[email protected]>

* Fix nits

Signed-off-by: Kevin Earls <[email protected]>

* Appease the linter

Signed-off-by: Kevin Earls <[email protected]>

* Don't use a default, only set scaleUp/scaleDown if they are in the CR

Signed-off-by: Kevin Earls <[email protected]>

* Removed commented out code

Signed-off-by: Kevin Earls <[email protected]>

* Change defaults for scaleUp/scaleDown

Signed-off-by: Kevin Earls <[email protected]>

* Update autoscaling scaleup/scaledown

Signed-off-by: Kevin Earls <[email protected]>

* Run generate

Signed-off-by: Kevin Earls <[email protected]>

* Ran make api-docs

Signed-off-by: Kevin Earls <[email protected]>

* Update HPA implementation to embed HorizontalPodAutoscalerBehavior

Signed-off-by: Kevin Earls <[email protected]>

* Only set behavior if it exists in the collector CR

Signed-off-by: Kevin Earls <[email protected]>

* Aded some unit tests

Signed-off-by: Kevin Earls <[email protected]>

* Add kuttl assertion that hpa scaled down

Signed-off-by: Kevin Earls <[email protected]>

* added whitespace to rerun tests

Signed-off-by: Kevin Earls <[email protected]>

Signed-off-by: Kevin Earls <[email protected]>
  • Loading branch information
kevinearls authored Sep 15, 2022
1 parent 9d224e1 commit 6f54f38
Show file tree
Hide file tree
Showing 11 changed files with 703 additions and 1 deletion.
14 changes: 14 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package v1alpha1

import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -40,6 +41,13 @@ 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"`
Expand Down Expand Up @@ -197,6 +205,12 @@ type OpenTelemetryCollectorList struct {
Items []OpenTelemetryCollector `json:"items"`
}

// AutoscalerSpec defines the OpenTelemetryCollector's pod autoscaling specification.
type AutoscalerSpec struct {
// +optional
Behavior *autoscalingv2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
}

func init() {
SchemeBuilder.Register(&OpenTelemetryCollector{}, &OpenTelemetryCollectorList{})
}
9 changes: 9 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, minReplicas should be one or more")
}

if r.Spec.Autoscaler != nil && r.Spec.Autoscaler.Behavior != nil {
if r.Spec.Autoscaler.Behavior.ScaleDown != nil && *r.Spec.Autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds < int32(1) {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleDown should be one or more")
}

if r.Spec.Autoscaler.Behavior.ScaleUp != nil && *r.Spec.Autoscaler.Behavior.ScaleUp.StabilizationWindowSeconds < int32(1) {
return fmt.Errorf("the OpenTelemetry Spec autoscale configuration is incorrect, scaleUp should be one or more")
}
}
}

return nil
Expand Down
28 changes: 27 additions & 1 deletion apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,130 @@ spec:
description: Args is the set of arguments to pass to the OpenTelemetry
Collector binary
type: object
autoscaler:
description: Autoscaler specifies the pod autoscaling configuration
to use for the OpenTelemetryCollector workload.
properties:
behavior:
description: HorizontalPodAutoscalerBehavior configures the scaling
behavior of the target in both Up and Down directions (scaleUp
and scaleDown fields respectively).
properties:
scaleDown:
description: scaleDown is scaling policy for scaling Down.
If not set, the default value is to allow to scale down
to minReplicas pods, with a 300 second stabilization window
(i.e., the highest recommendation for the last 300sec is
used).
properties:
policies:
description: policies is a list of potential scaling polices
which can be used during scaling. At least one policy
must be specified, otherwise the HPAScalingRules will
be discarded as invalid
items:
description: HPAScalingPolicy is a single policy which
must hold true for a specified past interval.
properties:
periodSeconds:
description: PeriodSeconds specifies the window
of time for which the policy should hold true.
PeriodSeconds must be greater than zero and less
than or equal to 1800 (30 min).
format: int32
type: integer
type:
description: Type is used to specify the scaling
policy.
type: string
value:
description: Value contains the amount of change
which is permitted by the policy. It must be greater
than zero
format: int32
type: integer
required:
- periodSeconds
- type
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
description: selectPolicy is used to specify which policy
should be used. If not set, the default value Max is
used.
type: string
stabilizationWindowSeconds:
description: 'StabilizationWindowSeconds is the number
of seconds for which past recommendations should be
considered while scaling up or scaling down. StabilizationWindowSeconds
must be greater than or equal to zero and less than
or equal to 3600 (one hour). If not set, use the default
values: - For scale up: 0 (i.e. no stabilization is
done). - For scale down: 300 (i.e. the stabilization
window is 300 seconds long).'
format: int32
type: integer
type: object
scaleUp:
description: 'scaleUp is scaling policy for scaling Up. If
not set, the default value is the higher of: * increase
no more than 4 pods per 60 seconds * double the number of
pods per 60 seconds No stabilization is used.'
properties:
policies:
description: policies is a list of potential scaling polices
which can be used during scaling. At least one policy
must be specified, otherwise the HPAScalingRules will
be discarded as invalid
items:
description: HPAScalingPolicy is a single policy which
must hold true for a specified past interval.
properties:
periodSeconds:
description: PeriodSeconds specifies the window
of time for which the policy should hold true.
PeriodSeconds must be greater than zero and less
than or equal to 1800 (30 min).
format: int32
type: integer
type:
description: Type is used to specify the scaling
policy.
type: string
value:
description: Value contains the amount of change
which is permitted by the policy. It must be greater
than zero
format: int32
type: integer
required:
- periodSeconds
- type
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
description: selectPolicy is used to specify which policy
should be used. If not set, the default value Max is
used.
type: string
stabilizationWindowSeconds:
description: 'StabilizationWindowSeconds is the number
of seconds for which past recommendations should be
considered while scaling up or scaling down. StabilizationWindowSeconds
must be greater than or equal to zero and less than
or equal to 3600 (one hour). If not set, use the default
values: - For scale up: 0 (i.e. no stabilization is
done). - For scale down: 300 (i.e. the stabilization
window is 300 seconds long).'
format: int32
type: integer
type: object
type: object
type: object
config:
description: Config is the raw JSON to be used as the collector's
configuration. Refer to the OpenTelemetry Collector documentation
Expand Down
124 changes: 124 additions & 0 deletions config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,130 @@ spec:
description: Args is the set of arguments to pass to the OpenTelemetry
Collector binary
type: object
autoscaler:
description: Autoscaler specifies the pod autoscaling configuration
to use for the OpenTelemetryCollector workload.
properties:
behavior:
description: HorizontalPodAutoscalerBehavior configures the scaling
behavior of the target in both Up and Down directions (scaleUp
and scaleDown fields respectively).
properties:
scaleDown:
description: scaleDown is scaling policy for scaling Down.
If not set, the default value is to allow to scale down
to minReplicas pods, with a 300 second stabilization window
(i.e., the highest recommendation for the last 300sec is
used).
properties:
policies:
description: policies is a list of potential scaling polices
which can be used during scaling. At least one policy
must be specified, otherwise the HPAScalingRules will
be discarded as invalid
items:
description: HPAScalingPolicy is a single policy which
must hold true for a specified past interval.
properties:
periodSeconds:
description: PeriodSeconds specifies the window
of time for which the policy should hold true.
PeriodSeconds must be greater than zero and less
than or equal to 1800 (30 min).
format: int32
type: integer
type:
description: Type is used to specify the scaling
policy.
type: string
value:
description: Value contains the amount of change
which is permitted by the policy. It must be greater
than zero
format: int32
type: integer
required:
- periodSeconds
- type
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
description: selectPolicy is used to specify which policy
should be used. If not set, the default value Max is
used.
type: string
stabilizationWindowSeconds:
description: 'StabilizationWindowSeconds is the number
of seconds for which past recommendations should be
considered while scaling up or scaling down. StabilizationWindowSeconds
must be greater than or equal to zero and less than
or equal to 3600 (one hour). If not set, use the default
values: - For scale up: 0 (i.e. no stabilization is
done). - For scale down: 300 (i.e. the stabilization
window is 300 seconds long).'
format: int32
type: integer
type: object
scaleUp:
description: 'scaleUp is scaling policy for scaling Up. If
not set, the default value is the higher of: * increase
no more than 4 pods per 60 seconds * double the number of
pods per 60 seconds No stabilization is used.'
properties:
policies:
description: policies is a list of potential scaling polices
which can be used during scaling. At least one policy
must be specified, otherwise the HPAScalingRules will
be discarded as invalid
items:
description: HPAScalingPolicy is a single policy which
must hold true for a specified past interval.
properties:
periodSeconds:
description: PeriodSeconds specifies the window
of time for which the policy should hold true.
PeriodSeconds must be greater than zero and less
than or equal to 1800 (30 min).
format: int32
type: integer
type:
description: Type is used to specify the scaling
policy.
type: string
value:
description: Value contains the amount of change
which is permitted by the policy. It must be greater
than zero
format: int32
type: integer
required:
- periodSeconds
- type
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
description: selectPolicy is used to specify which policy
should be used. If not set, the default value Max is
used.
type: string
stabilizationWindowSeconds:
description: 'StabilizationWindowSeconds is the number
of seconds for which past recommendations should be
considered while scaling up or scaling down. StabilizationWindowSeconds
must be greater than or equal to zero and less than
or equal to 3600 (one hour). If not set, use the default
values: - For scale up: 0 (i.e. no stabilization is
done). - For scale down: 300 (i.e. the stabilization
window is 300 seconds long).'
format: int32
type: integer
type: object
type: object
type: object
config:
description: Config is the raw JSON to be used as the collector's
configuration. Refer to the OpenTelemetry Collector documentation
Expand Down
Loading

0 comments on commit 6f54f38

Please sign in to comment.