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

Convert all the range values to be doubles and add a test that uses a double. #7676

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
3 changes: 3 additions & 0 deletions .changelog/4162.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
monitoring: Fixed type of `google_monitoring_slo`'s `range` values - some `range` values are doubles, others are integers.
```
137 changes: 16 additions & 121 deletions google/resource_monitoring_slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"log"
"reflect"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -212,15 +211,15 @@ just one of min or max.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `max value for the range (inclusive). If not given,
will be set to "infinity", defining an open range
">= range.min"`,
AtLeastOneOf: []string{"request_based_sli.0.distribution_cut.0.range.0.min", "request_based_sli.0.distribution_cut.0.range.0.max"},
},
"min": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `Min value for the range (inclusive). If not given,
will be set to "-infinity", defining an open range
Expand Down Expand Up @@ -440,15 +439,15 @@ just one of min or max.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `max value for the range (inclusive). If not given,
will be set to "infinity", defining an open range
">= range.min"`,
AtLeastOneOf: []string{"windows_based_sli.0.good_total_ratio_threshold.0.performance.0.distribution_cut.0.range.0.min", "windows_based_sli.0.good_total_ratio_threshold.0.performance.0.distribution_cut.0.range.0.max"},
},
"min": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `Min value for the range (inclusive). If not given,
will be set to "-infinity", defining an open range
Expand Down Expand Up @@ -557,15 +556,15 @@ good service.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `max value for the range (inclusive). If not given,
will be set to "infinity", defining an open range
">= range.min"`,
AtLeastOneOf: []string{"windows_based_sli.0.metric_mean_in_range.0.range.0.min", "windows_based_sli.0.metric_mean_in_range.0.range.0.max"},
},
"min": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `Min value for the range (inclusive). If not given,
will be set to "-infinity", defining an open range
Expand Down Expand Up @@ -616,15 +615,15 @@ just one of min or max. Summed value 'X' should satisfy
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `max value for the range (inclusive). If not given,
will be set to "infinity", defining an open range
">= range.min"`,
AtLeastOneOf: []string{"windows_based_sli.0.metric_sum_in_range.0.range.0.min", "windows_based_sli.0.metric_sum_in_range.0.range.0.max"},
},
"min": {
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
Description: `Min value for the range (inclusive). If not given,
will be set to "-infinity", defining an open range
Expand Down Expand Up @@ -1226,37 +1225,11 @@ func flattenMonitoringSloServiceLevelIndicatorRequestBasedSliDistributionCutRang
return []interface{}{transformed}
}
func flattenMonitoringSloServiceLevelIndicatorRequestBasedSliDistributionCutRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloServiceLevelIndicatorRequestBasedSliDistributionCutRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSli(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -1388,37 +1361,11 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThres
return []interface{}{transformed}
}
func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdPerformanceDistributionCutRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdPerformanceDistributionCutRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformance(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -1513,37 +1460,11 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRangeRa
return []interface{}{transformed}
}
func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRangeRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRangeRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRange(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -1581,37 +1502,11 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRangeRan
return []interface{}{transformed}
}
func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRangeRangeMin(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricSumInRangeRangeMax(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
return v
}

func flattenMonitoringSloSloId(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down
15 changes: 5 additions & 10 deletions google/resource_monitoring_slo_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,11 @@ resource "google_monitoring_slo" "request_based_slo" {

request_based_sli {
distribution_cut {
distribution_filter = join(" AND ", [
"metric.type=\"serviceruntime.googleapis.com/api/request_latencies\"",
"resource.type=\"consumed_api\"",
"resource.label.\"project_id\"=\"%{project}\"",
])

range {
max = 10
}
}
distribution_filter = "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\" resource.type=\"api\" "
range {
max = 0.5
}
}
}
}
`, context)
Expand Down
15 changes: 5 additions & 10 deletions website/docs/r/monitoring_slo.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,11 @@ resource "google_monitoring_slo" "request_based_slo" {

request_based_sli {
distribution_cut {
distribution_filter = join(" AND ", [
"metric.type=\"serviceruntime.googleapis.com/api/request_latencies\"",
"resource.type=\"consumed_api\"",
"resource.label.\"project_id\"=\"my-project-name\"",
])

range {
max = 10
}
}
distribution_filter = "metric.type=\"serviceruntime.googleapis.com/api/request_latencies\" resource.type=\"api\" "
range {
max = 0.5
}
}
}
}
```
Expand Down