From afcc89be4e7c35bd9968c84f87fa635bf11ff05c Mon Sep 17 00:00:00 2001 From: Daniel Koss <66844903+dkoss@users.noreply.github.com> Date: Thu, 24 Aug 2023 19:03:04 -0400 Subject: [PATCH] Adds the synthetic monitor target type as an option for uptime checks. (#8709) * Adds synthetic_monitor type that lives alongside resource_group and monitored_resource * removes requirement for either tcp_check or http_check to be provided, as neither is required when synthetic_monitor is provided * Adds acceptance test, and example. A new test fixutre w/ zip file is provided for these flows. --- .../monitoring/UptimeCheckConfig.yaml | 45 +++++++++++++++--- ...time_check_config_synthetic_monitor.tf.erb | 44 +++++++++++++++++ .../test-fixtures/synthetic-fn-source.zip | Bin 0 -> 2124 bytes 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 mmv1/templates/terraform/examples/uptime_check_config_synthetic_monitor.tf.erb create mode 100644 mmv1/third_party/terraform/services/monitoring/test-fixtures/synthetic-fn-source.zip diff --git a/mmv1/products/monitoring/UptimeCheckConfig.yaml b/mmv1/products/monitoring/UptimeCheckConfig.yaml index 155e522159ba..b1d923680ebc 100644 --- a/mmv1/products/monitoring/UptimeCheckConfig.yaml +++ b/mmv1/products/monitoring/UptimeCheckConfig.yaml @@ -56,6 +56,18 @@ examples: vars: display_name: 'tcp-uptime-check' group_display_name: 'uptime-check-group' + - !ruby/object:Provider::Terraform::Examples + name: 'uptime_check_config_synthetic_monitor' + primary_resource_id: 'synthetic_monitor' + vars: + display_name: 'synthetic_monitor' + function_name: 'synthetic_function' + zip_path: 'synthetic-fn-source.zip' + bucket_name: 'gcf-source' + test_env_vars: + project_id: :PROJECT_NAME + test_vars_overrides: + zip_path: '"./test-fixtures/synthetic-fn-source.zip"' custom_code: !ruby/object:Provider::Terraform::CustomCode constants: templates/terraform/constants/monitoring_uptime_check_config.go.erb custom_import: templates/terraform/custom_import/self_link_as_name.erb @@ -163,9 +175,6 @@ properties: - !ruby/object:Api::Type::NestedObject name: httpCheck description: Contains information needed to make an HTTP or HTTPS check. - exactly_one_of: - - http_check - - tcp_check properties: - !ruby/object:Api::Type::Enum name: requestMethod @@ -324,9 +333,6 @@ properties: - !ruby/object:Api::Type::NestedObject name: tcpCheck description: Contains information needed to make a TCP check. - exactly_one_of: - - http_check - - tcp_check properties: - !ruby/object:Api::Type::Integer name: port @@ -342,6 +348,7 @@ properties: exactly_one_of: - monitored_resource - resource_group + - synthetic_monitor properties: - !ruby/object:Api::Type::Enum name: resourceType @@ -379,6 +386,7 @@ properties: exactly_one_of: - monitored_resource - resource_group + - synthetic_monitor properties: - !ruby/object:Api::Type::String name: type @@ -401,3 +409,28 @@ properties: Values for all of the labels listed in the associated monitored resource descriptor. For example, Compute Engine VM instances use the labels "project_id", "instance_id", and "zone". + - !ruby/object:Api::Type::NestedObject + name: syntheticMonitor + immutable: true + description: + A Synthetic Monitor deployed to a Cloud Functions V2 instance. + exactly_one_of: + - monitored_resource + - resource_group + - synthetic_monitor + properties: + - !ruby/object:Api::Type::NestedObject + name: cloudFunctionV2 + immutable: true + required: true + description: + Target a Synthetic Monitor GCFv2 Instance + exactly_one_of: + - cloud_function_v2 + properties: + - !ruby/object:Api::Type::String + name: name + immutable: true + required: true + description: + The fully qualified name of the cloud function resource. diff --git a/mmv1/templates/terraform/examples/uptime_check_config_synthetic_monitor.tf.erb b/mmv1/templates/terraform/examples/uptime_check_config_synthetic_monitor.tf.erb new file mode 100644 index 000000000000..98b73b74d8c8 --- /dev/null +++ b/mmv1/templates/terraform/examples/uptime_check_config_synthetic_monitor.tf.erb @@ -0,0 +1,44 @@ +resource "google_storage_bucket" "bucket" { + name = "<%= ctx[:test_env_vars]["project_id"] %>-<%= ctx[:vars]['bucket_name'] %>" # Every bucket name must be globally unique + location = "US" + uniform_bucket_level_access = true +} + +resource "google_storage_bucket_object" "object" { + name = "function-source.zip" + bucket = google_storage_bucket.bucket.name + source = "<%= ctx[:vars]['zip_path'] %>" # Add path to the zipped function source code +} + +resource "google_cloudfunctions2_function" "function" { + name = "<%= ctx[:vars]['function_name'] %>" + location = "us-central1" + + build_config { + runtime = "nodejs16" + entry_point = "SyntheticFunction" # Set the entry point + source { + storage_source { + bucket = google_storage_bucket.bucket.name + object = google_storage_bucket_object.object.name + } + } + } + + service_config { + max_instance_count = 1 + available_memory = "256M" + timeout_seconds = 60 + } +} + +resource "google_monitoring_uptime_check_config" "<%= ctx[:primary_resource_id] %>" { + display_name = "<%= ctx[:vars]["display_name"] %>" + timeout = "60s" + + synthetic_monitor { + cloud_function_v2 { + name = google_cloudfunctions2_function.function.id + } + } +} diff --git a/mmv1/third_party/terraform/services/monitoring/test-fixtures/synthetic-fn-source.zip b/mmv1/third_party/terraform/services/monitoring/test-fixtures/synthetic-fn-source.zip new file mode 100644 index 0000000000000000000000000000000000000000..fd79909197ab000a61bb0d6eb283a8b136ff9ccd GIT binary patch literal 2124 zcmai#c{tQ-AI5)UtO;X{Q0P$BEQRc*QPzXTj6*rLnZ_~O7Bw^@~CEJWGxhlJJ zgpe>~!dS=2da^HNiHYHz&iluybKd28{&=46Klk-q_w~K+kBtSGRR{n8PN0u8hBSwG z%=9oP1PB050uq3qtGl-=2Cd?C2j`2h;{w2pqfFFg>?|rMlp6rC7POrJSmDkfz$ZQ%G#CC}DA14bOl*)b+4{u2A8q8F%`!vX-9y%F6anNJ$1ILkPt};~Fb&~~ROj3^& zE65Wglo4ff4=3Csgte-=1JXdQSvOkDzr5bDA|Szv?r!ejikG98(jsda?NKk>$qO<; z7%Gy#BHq;EwM1P#zH{08bAAFlny%}(NA!={;k{pQmMfztVU5S;J2zDG9ZU0B0HBNw z0JxZL+%PeQS(&K#p#GN?DR!IIld2HL#;dvEs0o|=8wOUUnR048L?66MWUkyB?X1qU z@$_h$CeLGC%u61jw5F#wR#xd#Eg_rg@eera_)gd-Gq9Q9^IwQpIe8`bMTm#Li&6u7 z&=~0D5N|8n7bWx0n-<+{WJAG2q>r2|Kf=}XI#K(l>vnoQ6n@Y%CC+Lhp1YJrzI=S} z+T%kCqA6yTzt{z<6R)w}yrjc#p@w`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