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

ScheduledCapacity Metrics Producer API #194

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 28 additions & 7 deletions pkg/apis/autoscaling/v1alpha1/metricsproducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type MetricsProducerSpec struct {
ReservedCapacity *ReservedCapacitySpec `json:"reservedCapacity,omitempty"`
// ScheduledCapacity produces a metric according to a specified schedule.
// +optional
ScheduledCapacity *ScheduledCapacitySpec `json:"scheduledCapacity,omitempty"`
Schedule *ScheduleSpec `json:"scheduleSpec,omitempty"`
}

type ReservedCapacitySpec struct {
Expand All @@ -46,17 +46,38 @@ type PendingCapacitySpec struct {
NodeSelector map[string]string `json:"nodeSelector"`
}

type ScheduledCapacitySpec struct {
// NodeSelector specifies a node group. The selector must uniquely identify a set of nodes.
NodeSelector map[string]string `json:"nodeSelector"`
type Timezone string

type ScheduleSpec struct {
// Behaviors may be layered to achieve complex scheduling autoscaling logic
Behaviors []ScheduledBehavior `json:"behaviors"`
// Defaults to UTC. Users will specify their schedules assuming this is their timezone
Copy link
Contributor

Choose a reason for hiding this comment

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

Should default to the cluster's local timezone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure you're able to set a timezone for a cluster?

// ref: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
// +optional
Timezone *Timezone `json:"timezone,omitempty"`
// A schedule defaults to this value when no behaviors are active
DefaultReplicas int32 `json:"defaultReplicas"`
}

// ScheduledBehavior defines a crontab which sets the metric to a specific replica value on a schedule.
// ScheduledBehavior sets the metric to a replica value based on a start and end pattern.
type ScheduledBehavior struct {
Crontab string `json:"crontab"`
Replicas int32 `json:"replicas"`
// The value the MetricsProducer will emit when the current time is within start and end
Replicas int32 `json:"replicas"`
Start *Pattern `json:"start"`
End *Pattern `json:"end"`
}

// Pattern is a strongly-typed version of crontabs
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add doc on what it means if a field is omitted? Also what are the rules about which fields can or cannot be specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Let me know if that covers what you meant.

type Pattern struct {
// When minutes or hours are left out, they are assumed to match to 0
Minutes *string `json:"minutes,omitempty"`
Hours *string `json:"hours,omitempty"`
// When Days, Months, or Weekdays are left out, they are represented by wildcards, meaning any time matches
Days *string `json:"days,omitempty"`
// List of 3-letter abbreviations i.e. Jan, Feb, Mar
Months *string `json:"months,omitempty"`
// List of 3-letter abbreviations i.e. "Mon, Tue, Wed"
Weekdays *string `json:"weekdays,omitempty"`
ellistarn marked this conversation as resolved.
Show resolved Hide resolved
}

// PendingPodsSpec outputs a metric that identifies scheduling opportunities for pending pods in specified node groups.
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/autoscaling/v1alpha1/metricsproducer_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ type QueueStatus struct {
}

type ScheduledCapacityStatus struct {
// The current recommendation - the metric the MetricsProducer is emitting
CurrentValue *int32 `json:"currentValue,omitempty"`

// The time in the future where CurrentValue will switch to NextValue
NextValueTime *apis.VolatileTime `json:"nextValueTime,omitempty"`

// The next recommendation for the metric
NextValue *int32 `json:"nextValue,omitempty"`
}

// We use knative's libraries for ConditionSets to manage status conditions.
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/autoscaling/v1alpha1/metricsproducer_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (mp *MetricsProducerSpec) Validate() error {
if mp.ReservedCapacity != nil {
return mp.ReservedCapacity.validate()
}
if mp.ScheduledCapacity != nil {
return mp.ScheduledCapacity.validate()
if mp.Schedule != nil {
return mp.Schedule.validate()
}
return nil
}
Expand All @@ -64,6 +64,6 @@ func (s *ReservedCapacitySpec) validate() error {
}

// Validate ScheduledCapacity
func (s *ScheduledCapacitySpec) validate() error {
func (s *ScheduleSpec) validate() error {
return nil
}
2 changes: 1 addition & 1 deletion pkg/metrics/producers/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (f *Factory) For(mp *v1alpha1.MetricsProducer) metrics.Producer {
Client: f.Client,
}
}
if mp.Spec.ScheduledCapacity != nil {
if mp.Spec.Schedule != nil {
return &scheduledcapacity.Producer{
MetricsProducer: mp,
}
Expand Down