From fac51f934f3e44ae35947e2be21904e6446a9b96 Mon Sep 17 00:00:00 2001 From: Tavasya Ganpati Date: Wed, 12 Aug 2026 19:00:15 -0700 Subject: [PATCH 1/4] add resource --- mmv1/products/monitoring/Snooze.yaml | 114 ++++++++++++++++++ .../monitoring_snooze_basic.tf.tmpl | 31 +++++ 2 files changed, 145 insertions(+) create mode 100644 mmv1/products/monitoring/Snooze.yaml create mode 100644 mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_basic.tf.tmpl diff --git a/mmv1/products/monitoring/Snooze.yaml b/mmv1/products/monitoring/Snooze.yaml new file mode 100644 index 000000000000..3995fd7c81f4 --- /dev/null +++ b/mmv1/products/monitoring/Snooze.yaml @@ -0,0 +1,114 @@ +--- +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)' +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 diff --git a/mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_basic.tf.tmpl b/mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_basic.tf.tmpl new file mode 100644 index 000000000000..f7d69570d56d --- /dev/null +++ b/mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_basic.tf.tmpl @@ -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 + ] + } +} From 201c92c875b8c58050d107ff7681d1da4f6d62da Mon Sep 17 00:00:00 2001 From: Tavasya Ganpati Date: Wed, 12 Aug 2026 19:32:36 -0700 Subject: [PATCH 2/4] add test --- .../monitoring_snooze_filter.tf.tmpl | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_filter.tf.tmpl diff --git a/mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_filter.tf.tmpl b/mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_filter.tf.tmpl new file mode 100644 index 000000000000..af5e07c586bb --- /dev/null +++ b/mmv1/templates/terraform/samples/services/monitoring/monitoring_snooze_filter.tf.tmpl @@ -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\"" + } +} From 2a926ac1a5b870563a39bc8d3e3d5a6ed61ca1e5 Mon Sep 17 00:00:00 2001 From: Tavasya Ganpati Date: Thu, 13 Aug 2026 10:56:13 -0700 Subject: [PATCH 3/4] fix --- mmv1/products/monitoring/Snooze.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mmv1/products/monitoring/Snooze.yaml b/mmv1/products/monitoring/Snooze.yaml index 3995fd7c81f4..a71c9cc98f17 100644 --- a/mmv1/products/monitoring/Snooze.yaml +++ b/mmv1/products/monitoring/Snooze.yaml @@ -39,6 +39,19 @@ samples: # 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 From 38e03a6bd04f5f4f868fd5b4c2a4cf89b99a328d Mon Sep 17 00:00:00 2001 From: Tavasya Ganpati Date: Thu, 13 Aug 2026 11:09:28 -0700 Subject: [PATCH 4/4] fix service lable --- tools/issue-labeler/labeler/enrolled_teams.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/issue-labeler/labeler/enrolled_teams.yml b/tools/issue-labeler/labeler/enrolled_teams.yml index f039726bb2a3..8c82192d79c9 100755 --- a/tools/issue-labeler/labeler/enrolled_teams.yml +++ b/tools/issue-labeler/labeler/enrolled_teams.yml @@ -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