-
Notifications
You must be signed in to change notification settings - Fork 501
Enable setting PodAutoscaler configuration via YAML labels #409
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,19 @@ limitations under the License. | |
|
|
||
| package common | ||
|
|
||
| import ( | ||
| "strconv" | ||
|
|
||
| autoscalingv1alpha1 "github.com/aibrix/aibrix/api/autoscaling/v1alpha1" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| const ( | ||
| AutoscalingLabelPrefix = "autoscaling.aibrix.ai/" | ||
| maxScaleUpRateLabel = AutoscalingLabelPrefix + "max-scale-up-rate" | ||
| maxScaleDownRateLabel = AutoscalingLabelPrefix + "max-scale-down-rate" | ||
| ) | ||
|
|
||
| // ScalingContext defines the generalized common that holds all necessary data for scaling calculations. | ||
| type ScalingContext interface { | ||
| GetTargetValue() float64 | ||
|
|
@@ -24,6 +37,7 @@ type ScalingContext interface { | |
| GetMaxScaleUpRate() float64 | ||
| GetMaxScaleDownRate() float64 | ||
| GetCurrentUsePerPod() float64 | ||
| UpdateByPaTypes(pa *autoscalingv1alpha1.PodAutoscaler) error | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, when Another benefit is that |
||
| } | ||
|
|
||
| // BaseScalingContext provides a base implementation of the ScalingContext interface. | ||
|
|
@@ -42,6 +56,8 @@ type BaseScalingContext struct { | |
| currentUsePerPod float64 | ||
| } | ||
|
|
||
| var _ ScalingContext = (*BaseScalingContext)(nil) | ||
|
|
||
| // NewBaseScalingContext creates a new instance of BaseScalingContext with default values. | ||
| func NewBaseScalingContext() *BaseScalingContext { | ||
| return &BaseScalingContext{ | ||
|
|
@@ -53,6 +69,36 @@ func NewBaseScalingContext() *BaseScalingContext { | |
| } | ||
| } | ||
|
|
||
| // UpdateByPaTypes should be invoked in any scaling context that embeds BaseScalingContext. | ||
| func (b *BaseScalingContext) UpdateByPaTypes(pa *autoscalingv1alpha1.PodAutoscaler) error { | ||
| b.ScalingMetric = pa.Spec.TargetMetric | ||
| // parse target value | ||
| targetValue, err := strconv.ParseFloat(pa.Spec.TargetValue, 64) | ||
| if err != nil { | ||
| klog.ErrorS(err, "Failed to parse target value", "targetValue", pa.Spec.TargetValue) | ||
| return err | ||
| } | ||
| b.TargetValue = targetValue | ||
|
|
||
| for key, value := range pa.Labels { | ||
| switch key { | ||
| case maxScaleUpRateLabel: | ||
| v, err := strconv.ParseFloat(value, 64) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| b.MaxScaleUpRate = v | ||
| case maxScaleDownRateLabel: | ||
| v, err := strconv.ParseFloat(value, 64) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| b.MaxScaleDownRate = v | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (b *BaseScalingContext) SetCurrentUsePerPod(value float64) { | ||
| b.currentUsePerPod = value | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we plan to use other units like min etc? If not, should we alway use
secondso we do not need to parse thesthereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could remain the form of "30s" for some reason:
autoscaling.knative.dev/window: "40s"(doc).time.Duration. If we only keep 30, we still need to add* time.secondmanually.