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 #4542

Merged
19 changes: 17 additions & 2 deletions mmv1/products/monitoring/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ objects:
name: enabled
default_value: true
description: |
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`.
- !ruby/object:Api::Type::NestedObject
name: requestBasedSli
api_name: 'requestBased'
Expand Down Expand Up @@ -1511,9 +1511,11 @@ objects:
item_type: Api::Type::String
- !ruby/object:Api::Type::NestedObject
name: latency
required: true
description: |
Parameters for a latency threshold SLI.
exactly_one_of:
- service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.latency
- service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.availability
properties:
- !ruby/object:Api::Type::String
required: true
Expand All @@ -1522,6 +1524,19 @@ objects:
A duration string, e.g. 10s.
Good service is defined to be the count of requests made to
this service that return in no more than threshold.
- !ruby/object:Api::Type::NestedObject
name: availability
description: |
Availability based SLI, dervied from count of requests made to this service that return successfully.
exactly_one_of:
- service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.latency
- service_level_indicator.0.windows_based_sli.0.good_total_ratio_threshold.0.basic_sli_performance.0.availability
properties:
- !ruby/object:Api::Type::Boolean
name: enabled
default_value: true
description: |
Whether an availability SLI is enabled or not. Must be set to `true. Defaults to `true`.
- !ruby/object:Api::Type::NestedObject
name: metricMeanInRange
exactly_one_of:
Expand Down
5 changes: 5 additions & 0 deletions mmv1/products/monitoring/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides
serviceLevelIndicator.basicSli.availability.enabled: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
function: validateAvailabilitySli
serviceLevelIndicator.windowsBasedSli.goodTotalRatioThreshold.basicSliPerformance.availability: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: 'templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb'
serviceLevelIndicator.windowsBasedSli.goodTotalRatioThreshold.basicSliPerformance.availability.enabled: !ruby/object:Overrides::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
function: validateAvailabilitySli
serviceLevelIndicator.requestBasedSli: !ruby/object:Overrides::Terraform::PropertyOverride
# Force update all nested fields to allow for unsetting values.
update_mask_fields:
Expand Down
14 changes: 14 additions & 0 deletions mmv1/templates/terraform/encoders/monitoring_slo.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,19 @@ if basicSli, ok := Sli["basicSli"].(map[string]interface{}); ok {
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 mmv1/third_party/terraform/tests/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 {
}
}
}
}
}`)
}