Skip to content
Open
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
127 changes: 127 additions & 0 deletions mmv1/products/monitoring/Snooze.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
name: 'Snooze'
description: |
A Snooze will prevent any alerts from being opened, and close any that are already open.
The Snooze will work on alerts that match the criteria defined in the Snooze.
The Snooze will be active from interval.start_time through interval.end_time.

~> **Note:** Monitoring Snoozes cannot be deleted from the Google Cloud Platform.
Destroying a Terraform-managed Snooze will cancel the snooze and remove it from state but
*will not delete the resource from the project.*
references:
guides:
'Official Documentation': 'https://cloud.google.com/monitoring/alerts/snooze'
api: 'https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.snoozes'
docs:
base_url: 'v3/projects/{{project}}/snoozes'
self_link: 'v3/{{name}}'
update_verb: 'PATCH'
update_mask: true
id_format: '{{name}}'
import_format:
- 'projects/{{project}}/snoozes/{{name}}'
exclude_delete: true
deletion_policy_exclude: true
custom_code:
custom_import: 'templates/terraform/custom_import/self_link_as_name_set_project.go.tmpl'
post_create: 'templates/terraform/post_create/set_computed_name.tmpl'
samples:
- name: 'monitoring_snooze_basic'
primary_resource_id: 'snooze'
steps:
- name: 'monitoring_snooze_basic'
resource_id_vars:
alert_policy_display_name: 'My Alert Policy'
snooze_display_name: 'My Snooze'
snooze_start_time: '2024-02-03T07:44:12Z'
snooze_end_time: '2024-02-05T07:44:12Z'
test_vars_overrides:
# anchored to a fixed day-of-year in UTC so recorded VCR fixtures stay valid for months, not one day
snooze_start_time: 'time.Date(time.Now().Year(), 12, 31, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1).Format(time.RFC3339)'
snooze_end_time: 'time.Date(time.Now().Year(), 12, 31, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 2).Format(time.RFC3339)'
- name: 'monitoring_snooze_filter'
primary_resource_id: 'snooze'
steps:
- name: 'monitoring_snooze_filter'
resource_id_vars:
alert_policy_display_name: 'My Alert Policy'
snooze_display_name: 'My Snooze'
snooze_start_time: '2024-02-03T07:44:12Z'
snooze_end_time: '2024-02-05T07:44:12Z'
test_vars_overrides:
# anchored to a fixed day-of-year in UTC so recorded VCR fixtures stay valid for months, not one day
snooze_start_time: 'time.Date(time.Now().Year(), 12, 31, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1).Format(time.RFC3339)'
snooze_end_time: 'time.Date(time.Now().Year(), 12, 31, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 2).Format(time.RFC3339)'
properties:
- name: 'name'
type: String
description: |
Identifier. The name of the Snooze. The format is:
projects/[PROJECT_ID_OR_NUMBER]/snoozes/[SNOOZE_ID]
The ID of the Snooze will be generated by the system.
output: true
- name: 'displayName'
type: String
description: |
A display name for the Snooze. This can be, at most, 512 unicode characters.
required: true
- name: 'criteria'
type: NestedObject
description: |
This defines the criteria for applying the Snooze.
required: true
properties:
- name: 'policies'
type: Array
description: |
The specific AlertPolicy names for the alert that should be snoozed.
The format is: projects/[PROJECT_ID_OR_NUMBER]/alertPolicies/[POLICY_ID]
There is a limit of 16 policies per snooze. This limit is checked during
snooze creation. Exactly 1 alert policy is required if filter is specified
at the same time.
item_type:
type: String
- name: 'filter'
type: String
description: |
When you define a snooze, you can also define a filter for that snooze.
The filter is a string containing one or more key-value pairs. The string
uses the standard https://google.aip.dev/160 filter syntax. If you define
a filter for a snooze, then the snooze can only apply to one alert policy.
When the snooze is active, incidents won't be created when the incident
would have key-value pairs (labels) that match those specified by the
filter in the snooze.

Snooze filters support resource, metric, and metadata labels. If multiple
labels are used, then they must be connected with an AND operator. For
example, the following filter applies the snooze to incidents that have a
resource label with an instance ID of 1234567890, a metric label with an
instance name of test_group, a metadata user label with a key of foo and a
value of bar, and a metadata system label with a key of region and a value
of us-central1:

"filter": "resource.labels.instance_id=\"1234567890\" AND metric.labels.instance_name=\"test_group\" AND metadata.user_labels.foo=\"bar\" AND metadata.system_labels.region=\"us-central1\""
- name: 'interval'
type: NestedObject
description: |
The Snooze will be active from interval.start_time through interval.end_time.
interval.start_time cannot be in the past. There is a 15 second clock skew to
account for the time it takes for a request to reach the API from the UI.
required: true
properties:
- name: 'startTime'
type: String
description: |
The beginning of the time interval. The default value for the start time
is the end time. The start time must not be later than the end time.
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and
up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and
"2014-10-02T15:01:23.045123456Z".
- name: 'endTime'
type: String
description: |
The end of the time interval.
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and
up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and
"2014-10-02T15:01:23.045123456Z".
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "{{index $.ResourceIdVars "alert_policy_display_name"}}"
combiner = "OR"
conditions {
display_name = "test condition"
condition_threshold {
filter = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""
duration = "60s"
comparison = "COMPARISON_GT"
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_RATE"
}
}
}
}

resource "google_monitoring_snooze" "{{$.PrimaryResourceId}}" {
display_name = "{{index $.ResourceIdVars "snooze_display_name"}}"

interval {
start_time = "{{index $.ResourceIdVars "snooze_start_time"}}"
end_time = "{{index $.ResourceIdVars "snooze_end_time"}}"
}

criteria {
policies = [
google_monitoring_alert_policy.alert_policy.id
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource "google_monitoring_alert_policy" "alert_policy" {
display_name = "{{index $.ResourceIdVars "alert_policy_display_name"}}"
combiner = "OR"
conditions {
display_name = "test condition"
condition_threshold {
filter = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""
duration = "60s"
comparison = "COMPARISON_GT"
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_RATE"
}
}
}
}

resource "google_monitoring_snooze" "{{$.PrimaryResourceId}}" {
display_name = "{{index $.ResourceIdVars "snooze_display_name"}}"

interval {
start_time = "{{index $.ResourceIdVars "snooze_start_time"}}"
end_time = "{{index $.ResourceIdVars "snooze_end_time"}}"
}

criteria {
policies = [
google_monitoring_alert_policy.alert_policy.id
]
filter = "resource.labels.instance_id=\"1234567890\""
}
}
1 change: 1 addition & 0 deletions tools/issue-labeler/labeler/enrolled_teams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ service/monitoring-alerting:
resources:
- google_monitoring_notification_channel
- google_monitoring_alert_policy
- google_monitoring_snooze
service/monitoring-metrics:
resources:
- google_monitoring_metric_descriptor
Expand Down
Loading