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

Add mode enum and scale down controls for Compute AutoScaler #3693

Merged
merged 4 commits into from
Jun 23, 2020
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
50 changes: 45 additions & 5 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,46 @@ objects:
instance may take to initialize. To do this, create an instance
and time the startup process.
default_value: 60
- !ruby/object:Api::Type::Enum
name: 'mode'
default_value: :ON
description: |
Defines operating mode for this policy.
values:
- :OFF
- :ONLY_UP
- :ON
- !ruby/object:Api::Type::NestedObject
name: 'scaleDownControl'
min_version: beta
at_least_one_of:
- scale_down_control.0.max_scaled_down_replicas
- scale_down_control.0.time_window_sec
description: |
Defines scale down controls to reduce the risk of response latency
and outages due to abrupt scale-in events
properties:
- !ruby/object:Api::Type::NestedObject
name: 'maxScaledDownReplicas'
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 at_least_one_of: for this?

It helps us prevent issues around empty blocks by requiring at least one field per block is specified.

In this case I believe it will look like:

at_least_one_of:
  - scale_down_control.0.max_scaled_down_replicas.0.fixed
  - scale_down_control.0.max_scaled_down_replicas.0.percent

And then one to scaleDownControl that looks like:

at_least_one_of:
  - scale_down_control.0.max_scaled_down_replicas
  - scale_down_control.0.time_window_sec

For example: https://github.com/GoogleCloudPlatform/magic-modules/blob/master/products/compute/api.yaml#L757

at_least_one_of:
- scale_down_control.0.max_scaled_down_replicas.0.fixed
- scale_down_control.0.max_scaled_down_replicas.0.percent
properties:
- !ruby/object:Api::Type::Integer
name: 'fixed'
description: |
Specifies a fixed number of VM instances. This must be a positive
integer.
- !ruby/object:Api::Type::Integer
name: 'percent'
description: |
Specifies a percentage of instances between 0 to 100%, inclusive.
For example, specify 80 for 80%.
- !ruby/object:Api::Type::Integer
name: 'timeWindowSec'
description: |
How long back autoscaling should look when computing recommendations
to include directives regarding slower scale down, as described above.
- !ruby/object:Api::Type::NestedObject
name: 'cpuUtilization'
description: |
Expand Down Expand Up @@ -7590,8 +7630,8 @@ objects:
The autoscaling mode. Set to one of the following:
- OFF: Disables the autoscaler.
- ON: Enables scaling in and scaling out.
- ONLY_SCALE_OUT: Enables only scaling out.
You must use this mode if your node groups are configured to
- ONLY_SCALE_OUT: Enables only scaling out.
You must use this mode if your node groups are configured to
restart their hosted VMs on minimal servers.
values:
- :OFF
Expand All @@ -7600,7 +7640,7 @@ objects:
- !ruby/object:Api::Type::Integer
name: 'minNodes'
description: |
Minimum size of the node group. Must be less
Minimum size of the node group. Must be less
than or equal to max-nodes. The default value is 0.
- !ruby/object:Api::Type::Integer
name: 'maxNodes'
Expand Down Expand Up @@ -7846,7 +7886,7 @@ objects:
description: The name of the packet mirroring rule
required: true
- !ruby/object:Api::Type::String
name: description
name: description
description: A human-readable description of the rule.
input: true
- !ruby/object:Api::Type::String
Expand Down Expand Up @@ -7890,7 +7930,7 @@ objects:
imports: 'selfLink'
description: The URL of the forwarding rule.
- !ruby/object:Api::Type::NestedObject
name: filter
name: filter
description: |
A filter for mirrored traffic. If unset, all traffic is mirrored.
properties:
Expand Down
7 changes: 5 additions & 2 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
min_version: 'beta'
vars:
address_name: "my-internal-address"
skip_docs: true # It is almost identical to internal_with_gce_endpoint
skip_docs: true # It is almost identical to internal_with_gce_endpoint
# TODO(rileykarson): Remove this example when instance is supported
- !ruby/object:Provider::Terraform::Examples
name: "instance_with_ip"
Expand Down Expand Up @@ -114,6 +114,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides
name: maxReplicas
autoscalingPolicy.coolDownPeriodSec: !ruby/object:Overrides::Terraform::PropertyOverride
name: cooldownPeriod
autoscalingPolicy.scaleDownControl: !ruby/object:Overrides::Terraform::PropertyOverride
required: false
default_from_api: true
autoscalingPolicy.cpuUtilization: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
autoscalingPolicy.cpuUtilization.utilizationTarget: !ruby/object:Overrides::Terraform::PropertyOverride
Expand Down Expand Up @@ -352,7 +355,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
Adds existing resource policies to a disk. You can only add one policy
which will be applied to this disk for scheduling snapshot creation.

~> **Note:** This resource does not support zonal disks (`google_compute_disk`). For zonal disks, please refer to [`google_compute_disk_resource_policy_attachment`](https://www.terraform.io/docs/providers/google/r/compute_disk_resource_policy_attachment.html)
~> **Note:** This resource does not support zonal disks (`google_compute_disk`). For zonal disks, please refer to [`google_compute_disk_resource_policy_attachment`](https://www.terraform.io/docs/providers/google/r/compute_disk_resource_policy_attachment.html)
examples:
- !ruby/object:Provider::Terraform::Examples
name: "region_disk_resource_policy_attachment_basic"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) {
})
}

<% unless version == 'ga' -%>
func TestAccComputeAutoscaler_scaleDownControl(t *testing.T) {
t.Parallel()

var it_name = fmt.Sprintf("autoscaler-test-%s", randString(t, 10))
var tp_name = fmt.Sprintf("autoscaler-test-%s", randString(t, 10))
var igm_name = fmt.Sprintf("autoscaler-test-%s", randString(t, 10))
var autoscaler_name = fmt.Sprintf("autoscaler-test-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeAutoscalerDestroyProducer(t),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeAutoscaler_scaleDownControl(it_name, tp_name, igm_name, autoscaler_name),
},
resource.TestStep{
ResourceName: "google_compute_autoscaler.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
<% end -%>

func testAccComputeAutoscaler_scaffolding(it_name, tp_name, igm_name string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down Expand Up @@ -188,3 +215,30 @@ resource "google_compute_autoscaler" "foobar" {
}
`, autoscaler_name)
}

<% unless version == 'ga' -%>
func testAccComputeAutoscaler_scaleDownControl(it_name, tp_name, igm_name, autoscaler_name string) string {
return testAccComputeAutoscaler_scaffolding(it_name, tp_name, igm_name) + fmt.Sprintf(`
resource "google_compute_autoscaler" "foobar" {
description = "Resource created for Terraform acceptance testing"
name = "%s"
zone = "us-central1-a"
target = google_compute_instance_group_manager.foobar.self_link
autoscaling_policy {
max_replicas = 10
min_replicas = 1
cooldown_period = 60
cpu_utilization {
target = 0.5
}
scale_down_control {
max_scaled_down_replicas {
percent = 80
}
time_window_sec = 300
}
}
}
`, autoscaler_name)
}
<% end -%>