Skip to content

Commit 071b8cb

Browse files
authored
feat(spanner): support totalCPUUtilizationPercent in autoscaling target for spanner instances (#15919)
1 parent fa323c1 commit 071b8cb

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

mmv1/products/spanner/Instance.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ properties:
235235
Specifies the target storage utilization percentage that the autoscaler
236236
should be trying to achieve for the instance.
237237
This number is on a scale from 0 (no utilization) to 100 (full utilization).
238+
- name: 'totalCpuUtilizationPercent'
239+
type: Integer
240+
description: |
241+
The target total cpu utilization percentage that the autoscaler should be trying to achieve for the instance.
242+
This number is on a scale from 0 (no utilization) to 100 (full utilization). The valid range is [10, 90] inclusive.
243+
If not specified or set to 0, the autoscaler will skip scaling based on total cpu utilization.
244+
The value should be higher than high_priority_cpu_utilization_percent if present.
238245
239246
- name: 'asymmetricAutoscalingOptions'
240247
type: Array

mmv1/templates/terraform/encoders/spanner_instance_update.go.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ if d.HasChange("autoscaling_config") {
5252
if d.HasChange("autoscaling_config.0.autoscaling_targets.0.storage_utilization_percent") {
5353
updateMask = append(updateMask, "autoscalingConfig.autoscalingTargets.storageUtilizationPercent")
5454
}
55+
if d.HasChange("autoscaling_config.0.autoscaling_targets.0.total_cpu_utilization_percent") {
56+
updateMask = append(updateMask, "autoscalingConfig.autoscalingTargets.totalCpuUtilizationPercent")
57+
}
5558
if d.HasChange("autoscaling_config.0.asymmetric_autoscaling_options") {
5659
updateMask = append(updateMask, "autoscalingConfig.asymmetricAutoscalingOptions")
5760
}

mmv1/third_party/terraform/services/spanner/resource_spanner_instance_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,45 @@ func TestAccSpannerInstance_freeInstanceBasicUpdate(t *testing.T) {
543543
})
544544
}
545545

546+
func TestAccSpannerInstance_autoscalingWithTotalCPUUtilizationPercent(t *testing.T) {
547+
t.Parallel()
548+
549+
displayName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
550+
acctest.VcrTest(t, resource.TestCase{
551+
PreCheck: func() { acctest.AccTestPreCheck(t) },
552+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
553+
CheckDestroy: testAccCheckSpannerInstanceDestroyProducer(t),
554+
Steps: []resource.TestStep{
555+
{
556+
Config: testAccSpannerInstance_autoscalingWithTotalCPUUtilizationPercent(displayName, 2000, 4000, 65, 85, 95),
557+
Check: resource.ComposeTestCheckFunc(
558+
resource.TestCheckResourceAttrSet("google_spanner_instance.test", "state"),
559+
resource.TestCheckResourceAttr("google_spanner_instance.test", "autoscaling_config.0.autoscaling_targets.0.total_cpu_utilization_percent", "85"),
560+
),
561+
},
562+
{
563+
ResourceName: "google_spanner_instance.test",
564+
ImportState: true,
565+
ImportStateVerify: true,
566+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
567+
},
568+
{
569+
Config: testAccSpannerInstance_autoscalingWithTotalCPUUtilizationPercent(displayName, 3000, 5000, 75, 90, 95),
570+
Check: resource.ComposeTestCheckFunc(
571+
resource.TestCheckResourceAttrSet("google_spanner_instance.test", "state"),
572+
resource.TestCheckResourceAttr("google_spanner_instance.test", "autoscaling_config.0.autoscaling_targets.0.total_cpu_utilization_percent", "90"),
573+
),
574+
},
575+
{
576+
ResourceName: "google_spanner_instance.test",
577+
ImportState: true,
578+
ImportStateVerify: true,
579+
ImportStateVerifyIgnore: []string{"labels", "terraform_labels"},
580+
},
581+
},
582+
})
583+
}
584+
546585
func testAccSpannerInstance_basic(name string) string {
547586
return fmt.Sprintf(`
548587
resource "google_spanner_instance" "basic" {
@@ -701,6 +740,7 @@ resource "google_spanner_instance" "basic" {
701740
}
702741
autoscaling_targets {
703742
high_priority_cpu_utilization_percent = %v
743+
total_cpu_utilization_percent = 85
704744
storage_utilization_percent = %v
705745
}
706746
}
@@ -905,3 +945,25 @@ resource "google_spanner_instance" "main" {
905945
}
906946
`, context)
907947
}
948+
949+
func testAccSpannerInstance_autoscalingWithTotalCPUUtilizationPercent(name string, minProcessingUnits, maxProcessingUnits, highPriorityCPU, totalCPU, storageUtilization int) string {
950+
return fmt.Sprintf(`
951+
resource "google_spanner_instance" "test" {
952+
name = "%s"
953+
config = "regional-us-central1"
954+
display_name = "%s"
955+
autoscaling_config {
956+
autoscaling_limits {
957+
max_processing_units = %d
958+
min_processing_units = %d
959+
}
960+
autoscaling_targets {
961+
high_priority_cpu_utilization_percent = %d
962+
total_cpu_utilization_percent = %d
963+
storage_utilization_percent = %d
964+
}
965+
}
966+
edition = "ENTERPRISE"
967+
}
968+
`, name, name, maxProcessingUnits, minProcessingUnits, highPriorityCPU, totalCPU, storageUtilization)
969+
}

0 commit comments

Comments
 (0)