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

availability sli for SLO monitoring resource #4344

17 changes: 16 additions & 1 deletion products/monitoring/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,9 @@ objects:
name: latency
description: |
Parameters for a latency threshold SLI.
required: true
exactly_one_of:
- service_level_indicator.0.basic_sli.0.latency
- service_level_indicator.0.basic_sli.0.availability
properties:
- !ruby/object:Api::Type::String
required: true
Expand All @@ -1153,6 +1155,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.basic_sli.0.latency
- service_level_indicator.0.basic_sli.0.availability
properties:
- !ruby/object:Api::Type::Boolean
name: enabled
venkykuberan marked this conversation as resolved.
Show resolved Hide resolved
default_value: true
description: |
Enable availability sli
venkykuberan marked this conversation as resolved.
Show resolved Hide resolved
- !ruby/object:Api::Type::NestedObject
name: requestBasedSli
api_name: 'requestBased'
Expand Down
3 changes: 3 additions & 0 deletions products/monitoring/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides
is_set: true
serviceLevelIndicator.basicSli.version: !ruby/object:Overrides::Terraform::PropertyOverride
is_set: true
serviceLevelIndicator.basicSli.availability: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/monitoring_slo_availability_sli.go.erb'
venkykuberan marked this conversation as resolved.
Show resolved Hide resolved
custom_flatten: 'templates/terraform/custom_flatten/monitoring_slo_availability_sli.go.erb'
serviceLevelIndicator.requestBasedSli: !ruby/object:Overrides::Terraform::PropertyOverride
# Force update all nested fields to allow for unsetting values.
update_mask_fields:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%- # the license inside this block applies to this file
# Copyright 2020 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 {
return nil, nil
}

return struct{}{}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%# The license inside this block applies to this file.
# Copyright 2020 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
venkykuberan marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
original := v.(map[string]interface{})
transformed := make(map[string]interface{})
transformed["enabled"] =
venkykuberan marked this conversation as resolved.
Show resolved Hide resolved
flattenMonitoringSloServiceLevelIndicatorBasicSliAvailabilityEnabled(original["enabled"], d, config)
return []interface{}{transformed}
}


func flattenMonitoringSloServiceLevelIndicatorBasicSliAvailabilityEnabled(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil || isEmptyValue(reflect.ValueOf(v)) {
return true
}

return v
}
42 changes: 42 additions & 0 deletions third_party/terraform/tests/resource_monitoring_slo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ func TestAccMonitoringSlo_basic(t *testing.T) {
})
}

func TestAccMonitoringSlo_availabilitySli(t *testing.T) {
t.Parallel()

var generatedId string
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMonitoringSloDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccMonitoringSlo_availabilitySli(),
venkykuberan marked this conversation as resolved.
Show resolved Hide resolved
Check: setTestCheckMonitoringSloId("google_monitoring_slo.primary", &generatedId),
},
{
ResourceName: "google_monitoring_slo.primary",
ImportState: true,
ImportStateVerify: true,
// Ignore input-only field for import
ImportStateVerifyIgnore: []string{"service"},
},
},
})
}
func TestAccMonitoringSlo_requestBased(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -409,6 +432,25 @@ resource "google_monitoring_slo" "primary" {
`
}

func testAccMonitoringSlo_availabilitySli() string {
return `
data "google_monitoring_app_engine_service" "ae" {
module_id = "default"
}

resource "google_monitoring_slo" "primary" {
service = data.google_monitoring_app_engine_service.ae.service_id

goal = 0.9
rolling_period_days = 1

basic_sli {
availability {
}
}
}
`
}
func testAccMonitoringSloForSli(randSuffix, sliConfig string) string {
return fmt.Sprintf(`
resource "google_monitoring_custom_service" "srv" {
Expand Down