Skip to content

Commit

Permalink
Adds the synthetic monitor target type as an option for uptime checks. (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
dkoss authored Aug 24, 2023
1 parent fbc3156 commit afcc89b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
45 changes: 39 additions & 6 deletions mmv1/products/monitoring/UptimeCheckConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -342,6 +348,7 @@ properties:
exactly_one_of:
- monitored_resource
- resource_group
- synthetic_monitor
properties:
- !ruby/object:Api::Type::Enum
name: resourceType
Expand Down Expand Up @@ -379,6 +386,7 @@ properties:
exactly_one_of:
- monitored_resource
- resource_group
- synthetic_monitor
properties:
- !ruby/object:Api::Type::String
name: type
Expand All @@ -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.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Binary file not shown.

0 comments on commit afcc89b

Please sign in to comment.