Skip to content

Commit 1e250d5

Browse files
Promote singleInstanceAssignment and filter to GA (#13250) (#21760)
[upstream:72e30993f29eb7e86d583bf1631a955deffc6bf6] Signed-off-by: Modular Magician <[email protected]>
1 parent 1761c22 commit 1e250d5

File tree

4 files changed

+101
-5
lines changed

4 files changed

+101
-5
lines changed

.changelog/13250.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: promote fields `singleInstanceAssignment` and `filter` to GA for `google_compute_autoscaler` resource
3+
```

google/services/compute/resource_compute_autoscaler.go

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,63 @@ be a positive float value. If not defined, the default is 0.8.`,
170170
The metric cannot have negative values.
171171
172172
The metric must have a value type of INT64 or DOUBLE.`,
173+
},
174+
"filter": {
175+
Type: schema.TypeString,
176+
Optional: true,
177+
Description: `A filter string to be used as the filter string for
178+
a Stackdriver Monitoring TimeSeries.list API call.
179+
This filter is used to select a specific TimeSeries for
180+
the purpose of autoscaling and to determine whether the metric
181+
is exporting per-instance or per-group data.
182+
183+
You can only use the AND operator for joining selectors.
184+
You can only use direct equality comparison operator (=) without
185+
any functions for each selector.
186+
You can specify the metric in both the filter string and in the
187+
metric field. However, if specified in both places, the metric must
188+
be identical.
189+
190+
The monitored resource type determines what kind of values are
191+
expected for the metric. If it is a gce_instance, the autoscaler
192+
expects the metric to include a separate TimeSeries for each
193+
instance in a group. In such a case, you cannot filter on resource
194+
labels.
195+
196+
If the resource type is any other value, the autoscaler expects
197+
this metric to contain values that apply to the entire autoscaled
198+
instance group and resource label filtering can be performed to
199+
point autoscaler at the correct TimeSeries to scale upon.
200+
This is called a per-group metric for the purpose of autoscaling.
201+
202+
If not specified, the type defaults to gce_instance.
203+
204+
You should provide a filter that is selective enough to pick just
205+
one TimeSeries for the autoscaled group or for each of the instances
206+
(if you are using gce_instance resource type). If multiple
207+
TimeSeries are returned upon the query execution, the autoscaler
208+
will sum their respective values to obtain its scaling value.`,
209+
Default: "resource.type = gce_instance",
210+
},
211+
"single_instance_assignment": {
212+
Type: schema.TypeFloat,
213+
Optional: true,
214+
Description: `If scaling is based on a per-group metric value that represents the
215+
total amount of work to be done or resource usage, set this value to
216+
an amount assigned for a single instance of the scaled group.
217+
The autoscaler will keep the number of instances proportional to the
218+
value of this metric, the metric itself should not change value due
219+
to group resizing.
220+
221+
For example, a good metric to use with the target is
222+
'pubsub.googleapis.com/subscription/num_undelivered_messages'
223+
or a custom metric exporting the total number of requests coming to
224+
your instances.
225+
226+
A bad example would be a metric exporting an average or median
227+
latency, since this value can't include a chunk assignable to a
228+
single instance, it could be better used with utilization_target
229+
instead.`,
173230
},
174231
"target": {
175232
Type: schema.TypeFloat,
@@ -890,9 +947,11 @@ func flattenComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d *schema.Re
890947
continue
891948
}
892949
transformed = append(transformed, map[string]interface{}{
893-
"name": flattenComputeAutoscalerAutoscalingPolicyMetricName(original["metric"], d, config),
894-
"target": flattenComputeAutoscalerAutoscalingPolicyMetricTarget(original["utilizationTarget"], d, config),
895-
"type": flattenComputeAutoscalerAutoscalingPolicyMetricType(original["utilizationTargetType"], d, config),
950+
"name": flattenComputeAutoscalerAutoscalingPolicyMetricName(original["metric"], d, config),
951+
"single_instance_assignment": flattenComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(original["singleInstanceAssignment"], d, config),
952+
"target": flattenComputeAutoscalerAutoscalingPolicyMetricTarget(original["utilizationTarget"], d, config),
953+
"type": flattenComputeAutoscalerAutoscalingPolicyMetricType(original["utilizationTargetType"], d, config),
954+
"filter": flattenComputeAutoscalerAutoscalingPolicyMetricFilter(original["filter"], d, config),
896955
})
897956
}
898957
return transformed
@@ -901,6 +960,10 @@ func flattenComputeAutoscalerAutoscalingPolicyMetricName(v interface{}, d *schem
901960
return v
902961
}
903962

963+
func flattenComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
964+
return v
965+
}
966+
904967
func flattenComputeAutoscalerAutoscalingPolicyMetricTarget(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
905968
return v
906969
}
@@ -909,6 +972,10 @@ func flattenComputeAutoscalerAutoscalingPolicyMetricType(v interface{}, d *schem
909972
return v
910973
}
911974

975+
func flattenComputeAutoscalerAutoscalingPolicyMetricFilter(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
976+
return v
977+
}
978+
912979
func flattenComputeAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
913980
if v == nil {
914981
return nil
@@ -1217,6 +1284,13 @@ func expandComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d tpgresource
12171284
transformed["metric"] = transformedName
12181285
}
12191286

1287+
transformedSingleInstanceAssignment, err := expandComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(original["single_instance_assignment"], d, config)
1288+
if err != nil {
1289+
return nil, err
1290+
} else if val := reflect.ValueOf(transformedSingleInstanceAssignment); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1291+
transformed["singleInstanceAssignment"] = transformedSingleInstanceAssignment
1292+
}
1293+
12201294
transformedTarget, err := expandComputeAutoscalerAutoscalingPolicyMetricTarget(original["target"], d, config)
12211295
if err != nil {
12221296
return nil, err
@@ -1231,6 +1305,13 @@ func expandComputeAutoscalerAutoscalingPolicyMetric(v interface{}, d tpgresource
12311305
transformed["utilizationTargetType"] = transformedType
12321306
}
12331307

1308+
transformedFilter, err := expandComputeAutoscalerAutoscalingPolicyMetricFilter(original["filter"], d, config)
1309+
if err != nil {
1310+
return nil, err
1311+
} else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1312+
transformed["filter"] = transformedFilter
1313+
}
1314+
12341315
req = append(req, transformed)
12351316
}
12361317
return req, nil
@@ -1240,6 +1321,10 @@ func expandComputeAutoscalerAutoscalingPolicyMetricName(v interface{}, d tpgreso
12401321
return v, nil
12411322
}
12421323

1324+
func expandComputeAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1325+
return v, nil
1326+
}
1327+
12431328
func expandComputeAutoscalerAutoscalingPolicyMetricTarget(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
12441329
return v, nil
12451330
}
@@ -1248,6 +1333,10 @@ func expandComputeAutoscalerAutoscalingPolicyMetricType(v interface{}, d tpgreso
12481333
return v, nil
12491334
}
12501335

1336+
func expandComputeAutoscalerAutoscalingPolicyMetricFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1337+
return v, nil
1338+
}
1339+
12511340
func expandComputeAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
12521341
l := v.([]interface{})
12531342
if len(l) == 0 || l[0] == nil {

google/services/compute/resource_compute_autoscaler_generated_meta.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ fields:
1414
api_field: 'autoscaling_policy.load_balancing_utilization.utilization_target'
1515
- field: 'autoscaling_policy.max_replicas'
1616
api_field: 'autoscaling_policy.max_num_replicas'
17+
- field: 'autoscaling_policy.metric.filter'
18+
api_field: 'autoscaling_policy.custom_metric_utilizations.filter'
1719
- field: 'autoscaling_policy.metric.name'
1820
api_field: 'autoscaling_policy.custom_metric_utilizations.metric'
21+
- field: 'autoscaling_policy.metric.single_instance_assignment'
22+
api_field: 'autoscaling_policy.custom_metric_utilizations.single_instance_assignment'
1923
- field: 'autoscaling_policy.metric.target'
2024
api_field: 'autoscaling_policy.custom_metric_utilizations.utilization_target'
2125
- field: 'autoscaling_policy.metric.type'

website/docs/r/compute_autoscaler.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ The following arguments are supported:
370370
The metric must have a value type of INT64 or DOUBLE.
371371

372372
* `single_instance_assignment` -
373-
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
373+
(Optional)
374374
If scaling is based on a per-group metric value that represents the
375375
total amount of work to be done or resource usage, set this value to
376376
an amount assigned for a single instance of the scaled group.
@@ -404,7 +404,7 @@ The following arguments are supported:
404404
Possible values are: `GAUGE`, `DELTA_PER_SECOND`, `DELTA_PER_MINUTE`.
405405

406406
* `filter` -
407-
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
407+
(Optional)
408408
A filter string to be used as the filter string for
409409
a Stackdriver Monitoring TimeSeries.list API call.
410410
This filter is used to select a specific TimeSeries for

0 commit comments

Comments
 (0)