Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Horizontal Pod Autoscaler Behavior and add hpa scaledown test #1077

Merged
merged 17 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: did we consider embedding the HPA spec in here? Or at least embed the autoscaling behavior spec here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just adding enough code to be able to get an e2e test to work within the time allocated, which means we need to scale down much quicker that the default 300 seconds.

@pavolloffay what do you think? Do I need to add the other values of PA scaling rules here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my use case, I know that I would like to be able to specify policies and not just StabilizationWindowSeconds. Embedding only StabilizationWindowSeconds is going to make it so we need to add in each feature on request, making a code change for each one.


// SecurityContext will be set as the container security context.
// +optional
SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"`
Expand Down Expand Up @@ -195,6 +202,31 @@ type OpenTelemetryCollectorList struct {
Items []OpenTelemetryCollector `json:"items"`
}

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

// AutoscalerBehaviorSpec configures the scaling behavior of the target.
type AutoscalerBehaviorSpec struct {
// ScaleUp is the policy for scaling up
// +optional
ScaleUp *AutoScalerRules `json:"scaleUp,omitempty"`

// ScaleDown is policy for scaling down
//
// +optional
ScaleDown *AutoScalerRules `json:"scaleDown,omitempty"`
}

// AutoScalerRules configures the scaling behavior for one direction.
type AutoScalerRules struct {
// +optional
// +kubebuilder:validation:Minimum=0
StabilizationWindowSeconds *int32 `json:"stabilizationWindowSeconds,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
70 changes: 70 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

26 changes: 26 additions & 0 deletions bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ 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: AutoscalerBehaviorSpec configures the scaling behavior
of the target
properties:
scaleDown:
description: ScaleDown is policy for scaling down
properties:
stabilizationWindowSeconds:
format: int32
minimum: 0
type: integer
type: object
scaleUp:
description: ScaleUp is the policy for scaling up
properties:
stabilizationWindowSeconds:
format: int32
minimum: 0
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
26 changes: 26 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,32 @@ 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: AutoscalerBehaviorSpec configures the scaling behavior
of the target
properties:
scaleDown:
description: ScaleDown is policy for scaling down
properties:
stabilizationWindowSeconds:
format: int32
minimum: 0
type: integer
type: object
scaleUp:
description: ScaleUp is the policy for scaling up
properties:
stabilizationWindowSeconds:
format: int32
minimum: 0
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
128 changes: 128 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,13 @@ OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
Args is the set of arguments to pass to the OpenTelemetry Collector binary<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspecautoscaler">autoscaler</a></b></td>
<td>object</td>
<td>
Autoscaler specifies the pod autoscaling configuration to use for the OpenTelemetryCollector workload.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>config</b></td>
<td>string</td>
Expand Down Expand Up @@ -1866,6 +1873,127 @@ OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
</table>


### OpenTelemetryCollector.spec.autoscaler
<sup><sup>[↩ Parent](#opentelemetrycollectorspec)</sup></sup>



Autoscaler specifies the pod autoscaling configuration to use for the OpenTelemetryCollector workload.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b><a href="#opentelemetrycollectorspecautoscalerbehavior">behavior</a></b></td>
<td>object</td>
<td>
AutoscalerBehaviorSpec configures the scaling behavior of the target<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### OpenTelemetryCollector.spec.autoscaler.behavior
<sup><sup>[↩ Parent](#opentelemetrycollectorspecautoscaler)</sup></sup>



AutoscalerBehaviorSpec configures the scaling behavior of the target

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b><a href="#opentelemetrycollectorspecautoscalerbehaviorscaledown">scaleDown</a></b></td>
<td>object</td>
<td>
ScaleDown is policy for scaling down<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#opentelemetrycollectorspecautoscalerbehaviorscaleup">scaleUp</a></b></td>
<td>object</td>
<td>
ScaleUp is the policy for scaling up<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### OpenTelemetryCollector.spec.autoscaler.behavior.scaleDown
<sup><sup>[↩ Parent](#opentelemetrycollectorspecautoscalerbehavior)</sup></sup>



ScaleDown is policy for scaling down

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>stabilizationWindowSeconds</b></td>
<td>integer</td>
<td>
<br/>
<br/>
<i>Format</i>: int32<br/>
<i>Minimum</i>: 0<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### OpenTelemetryCollector.spec.autoscaler.behavior.scaleUp
<sup><sup>[↩ Parent](#opentelemetrycollectorspecautoscalerbehavior)</sup></sup>



ScaleUp is the policy for scaling up

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>stabilizationWindowSeconds</b></td>
<td>integer</td>
<td>
<br/>
<br/>
<i>Format</i>: int32<br/>
<i>Minimum</i>: 0<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### OpenTelemetryCollector.spec.env[index]
<sup><sup>[↩ Parent](#opentelemetrycollectorspec)</sup></sup>

Expand Down
Loading