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

Promote metric settings in compute region autoscaler to GA #17519

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10103.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: promoted `metric.single_instance_assignment` and `metric.filter` for `google_compute_region_autoscaler` to GA
```
94 changes: 91 additions & 3 deletions google/services/compute/resource_compute_region_autoscaler.go
Expand Up @@ -167,6 +167,62 @@ be a positive float value. If not defined, the default is 0.8.`,
The metric cannot have negative values.

The metric must have a value type of INT64 or DOUBLE.`,
},
"filter": {
Type: schema.TypeString,
Optional: true,
Description: `A filter string to be used as the filter string for
a Stackdriver Monitoring TimeSeries.list API call.
This filter is used to select a specific TimeSeries for
the purpose of autoscaling and to determine whether the metric
is exporting per-instance or per-group data.

You can only use the AND operator for joining selectors.
You can only use direct equality comparison operator (=) without
any functions for each selector.
You can specify the metric in both the filter string and in the
metric field. However, if specified in both places, the metric must
be identical.

The monitored resource type determines what kind of values are
expected for the metric. If it is a gce_instance, the autoscaler
expects the metric to include a separate TimeSeries for each
instance in a group. In such a case, you cannot filter on resource
labels.

If the resource type is any other value, the autoscaler expects
this metric to contain values that apply to the entire autoscaled
instance group and resource label filtering can be performed to
point autoscaler at the correct TimeSeries to scale upon.
This is called a per-group metric for the purpose of autoscaling.

If not specified, the type defaults to gce_instance.

You should provide a filter that is selective enough to pick just
one TimeSeries for the autoscaled group or for each of the instances
(if you are using gce_instance resource type). If multiple
TimeSeries are returned upon the query execution, the autoscaler
will sum their respective values to obtain its scaling value.`,
},
"single_instance_assignment": {
Type: schema.TypeFloat,
Optional: true,
Description: `If scaling is based on a per-group metric value that represents the
total amount of work to be done or resource usage, set this value to
an amount assigned for a single instance of the scaled group.
The autoscaler will keep the number of instances proportional to the
value of this metric, the metric itself should not change value due
to group resizing.

For example, a good metric to use with the target is
'pubsub.googleapis.com/subscription/num_undelivered_messages'
or a custom metric exporting the total number of requests coming to
your instances.

A bad example would be a metric exporting an average or median
latency, since this value can't include a chunk assignable to a
single instance, it could be better used with utilization_target
instead.`,
},
"target": {
Type: schema.TypeFloat,
Expand Down Expand Up @@ -878,9 +934,11 @@ func flattenComputeRegionAutoscalerAutoscalingPolicyMetric(v interface{}, d *sch
continue
}
transformed = append(transformed, map[string]interface{}{
"name": flattenComputeRegionAutoscalerAutoscalingPolicyMetricName(original["metric"], d, config),
"target": flattenComputeRegionAutoscalerAutoscalingPolicyMetricTarget(original["utilizationTarget"], d, config),
"type": flattenComputeRegionAutoscalerAutoscalingPolicyMetricType(original["utilizationTargetType"], d, config),
"name": flattenComputeRegionAutoscalerAutoscalingPolicyMetricName(original["metric"], d, config),
"single_instance_assignment": flattenComputeRegionAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(original["singleInstanceAssignment"], d, config),
"target": flattenComputeRegionAutoscalerAutoscalingPolicyMetricTarget(original["utilizationTarget"], d, config),
"type": flattenComputeRegionAutoscalerAutoscalingPolicyMetricType(original["utilizationTargetType"], d, config),
"filter": flattenComputeRegionAutoscalerAutoscalingPolicyMetricFilter(original["filter"], d, config),
})
}
return transformed
Expand All @@ -889,6 +947,10 @@ func flattenComputeRegionAutoscalerAutoscalingPolicyMetricName(v interface{}, d
return v
}

func flattenComputeRegionAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeRegionAutoscalerAutoscalingPolicyMetricTarget(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand All @@ -897,6 +959,10 @@ func flattenComputeRegionAutoscalerAutoscalingPolicyMetricType(v interface{}, d
return v
}

func flattenComputeRegionAutoscalerAutoscalingPolicyMetricFilter(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenComputeRegionAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -1202,6 +1268,13 @@ func expandComputeRegionAutoscalerAutoscalingPolicyMetric(v interface{}, d tpgre
transformed["metric"] = transformedName
}

transformedSingleInstanceAssignment, err := expandComputeRegionAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(original["single_instance_assignment"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSingleInstanceAssignment); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["singleInstanceAssignment"] = transformedSingleInstanceAssignment
}

transformedTarget, err := expandComputeRegionAutoscalerAutoscalingPolicyMetricTarget(original["target"], d, config)
if err != nil {
return nil, err
Expand All @@ -1216,6 +1289,13 @@ func expandComputeRegionAutoscalerAutoscalingPolicyMetric(v interface{}, d tpgre
transformed["utilizationTargetType"] = transformedType
}

transformedFilter, err := expandComputeRegionAutoscalerAutoscalingPolicyMetricFilter(original["filter"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["filter"] = transformedFilter
}

req = append(req, transformed)
}
return req, nil
Expand All @@ -1225,6 +1305,10 @@ func expandComputeRegionAutoscalerAutoscalingPolicyMetricName(v interface{}, d t
return v, nil
}

func expandComputeRegionAutoscalerAutoscalingPolicyMetricSingleInstanceAssignment(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeRegionAutoscalerAutoscalingPolicyMetricTarget(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand All @@ -1233,6 +1317,10 @@ func expandComputeRegionAutoscalerAutoscalingPolicyMetricType(v interface{}, d t
return v, nil
}

func expandComputeRegionAutoscalerAutoscalingPolicyMetricFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandComputeRegionAutoscalerAutoscalingPolicyLoadBalancingUtilization(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/compute_region_autoscaler.html.markdown
Expand Up @@ -287,7 +287,7 @@ The following arguments are supported:
The metric must have a value type of INT64 or DOUBLE.

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

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