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 windows based availability sli to slo #3013

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
4 changes: 4 additions & 0 deletions .changelog/4542.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
monitoring : added windows based availability sli added to the resource `google_monitoring_slo`

```
78 changes: 76 additions & 2 deletions google-beta/resource_monitoring_slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Exactly one of the following must be set:
Type: schema.TypeBool,
Optional: true,
ValidateFunc: validateAvailabilitySli,
Description: `Whether an availability SLI is enabled or not. Must be set to 'true. Defaults to 'true'.`,
Description: `Whether an availability SLI is enabled or not. Must be set to true. Defaults to 'true'.`,
Default: true,
},
},
Expand Down Expand Up @@ -363,9 +363,27 @@ high enough. One of 'good_bad_metric_filter',
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"availability": {
Type: schema.TypeList,
Optional: true,
Description: `Availability based SLI, dervied from count of requests made to this service that return successfully.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
ValidateFunc: validateAvailabilitySli,
Description: `Whether an availability SLI is enabled or not. Must be set to 'true. Defaults to 'true'.`,
Default: true,
},
},
},
ExactlyOneOf: []string{"windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.latency", "windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.availability"},
},
"latency": {
Type: schema.TypeList,
Required: true,
Optional: true,
Description: `Parameters for a latency threshold SLI.`,
MaxItems: 1,
Elem: &schema.Resource{
Expand All @@ -379,6 +397,7 @@ this service that return in no more than threshold.`,
},
},
},
ExactlyOneOf: []string{"windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.latency", "windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.availability"},
},
"location": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -1423,6 +1442,8 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThres
flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceVersion(original["version"], d, config)
transformed["latency"] =
flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceLatency(original["latency"], d, config)
transformed["availability"] =
flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceAvailability(original["availability"], d, config)
return []interface{}{transformed}
}
func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceMethod(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -1463,6 +1484,15 @@ func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThres
return v
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceAvailability(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
}
transformed := make(map[string]interface{})
transformed["enabled"] = true
return []interface{}{transformed}
}

func flattenMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRange(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -2113,6 +2143,13 @@ func expandMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresh
transformed["latency"] = transformedLatency
}

transformedAvailability, err := expandMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceAvailability(original["availability"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAvailability); val.IsValid() && !isEmptyValue(val) {
transformed["availability"] = transformedAvailability
}

return transformed, nil
}

Expand Down Expand Up @@ -2154,6 +2191,29 @@ func expandMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresh
return v, nil
}

func expandMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceAvailability(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedEnabled, err := expandMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceAvailabilityEnabled(original["enabled"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !isEmptyValue(val) {
transformed["enabled"] = transformedEnabled
}

return transformed, nil
}

func expandMonitoringSloServiceLevelIndicatorWindowsBasedSliGoodTotalRatioThresholdBasicSliPerformanceAvailabilityEnabled(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringSloServiceLevelIndicatorWindowsBasedSliMetricMeanInRange(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -2299,5 +2359,19 @@ func resourceMonitoringSloEncoder(d *schema.ResourceData, meta interface{}, obj
basicSli["availability"] = transAvailability
}
}

if windowBasedSli, ok := Sli["windowsBased"].(map[string]interface{}); ok {
if goodTotalRatioThreshold, ok := windowBasedSli["goodTotalRatioThreshold"].(map[string]interface{}); ok {
if basicSli, ok := goodTotalRatioThreshold["basicSliPerformance"].(map[string]interface{}); ok {
//Removing the dummy `enabled` attribute
if availability, ok := basicSli["availability"]; ok {
transAvailability := availability.(map[string]interface{})
delete(transAvailability, "enabled")
basicSli["availability"] = transAvailability
}
}
}
}

return obj, nil
}
33 changes: 33 additions & 0 deletions google-beta/resource_monitoring_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ func TestAccMonitoringSlo_windowBasedGoodTotalRatioThresholdSlis(t *testing.T) {
// Ignore input-only field for import
ImportStateVerifyIgnore: []string{"service"},
},
{
Config: testAccMonitoringSloSli_windowBasedSliGoodTotalRatioThreshold_basicSli(),
},
{
ResourceName: "google_monitoring_slo.test_slo",
ImportState: true,
ImportStateVerify: true,
// Ignore input-only field for import
ImportStateVerifyIgnore: []string{"service"},
},
},
})
}
Expand Down Expand Up @@ -718,3 +728,26 @@ windows_based_sli {
}
`
}

func testAccMonitoringSloSli_windowBasedSliGoodTotalRatioThreshold_basicSli() string {
return fmt.Sprintf(`
data "google_monitoring_app_engine_service" "ae" {
module_id = "default"
}

resource "google_monitoring_slo" "test_slo" {
service = data.google_monitoring_app_engine_service.ae.service_id
goal = 0.9
rolling_period_days = 30
windows_based_sli {
window_period = "400s"
good_total_ratio_threshold {
threshold = 0.1
basic_sli_performance {
availability {
}
}
}
}
}`)
}
15 changes: 13 additions & 2 deletions website/docs/r/monitoring_slo.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ The `availability` block supports:

* `enabled` -
(Optional)
Whether an availability SLI is enabled or not. Must be set to `true. Defaults to `true`.
Whether an availability SLI is enabled or not. Must be set to true. Defaults to `true`.

The `request_based_sli` block supports:

Expand Down Expand Up @@ -642,10 +642,15 @@ The `basic_sli_performance` block supports:
field will result in an error.

* `latency` -
(Required)
(Optional)
Parameters for a latency threshold SLI.
Structure is documented below.

* `availability` -
(Optional)
Availability based SLI, dervied from count of requests made to this service that return successfully.
Structure is documented below.


The `latency` block supports:

Expand All @@ -655,6 +660,12 @@ The `latency` block supports:
Good service is defined to be the count of requests made to
this service that return in no more than threshold.

The `availability` block supports:

* `enabled` -
(Optional)
Whether an availability SLI is enabled or not. Must be set to `true. Defaults to `true`.

The `metric_mean_in_range` block supports:

* `time_series` -
Expand Down