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

Support ability to create "non-custom" services #6604

Merged
merged 13 commits into from
Oct 14, 2022
81 changes: 81 additions & 0 deletions mmv1/products/monitoring/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,87 @@ objects:
The full name of the resource that defines this service.
Formatted as described in
https://cloud.google.com/apis/design/resource_names.

- !ruby/object:Api::Resource
name: GenericService
base_url: v3/projects/{{project}}/services
create_url: v3/projects/{{project}}/services?serviceId={{service_id}}
self_link: "v3/{{name}}"
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
update_verb: :PATCH
update_mask: true
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
description: |
A Service is a discrete, autonomous, and network-accessible unit,
designed to solve an individual concern (Wikipedia). In Cloud Monitoring,
a Service acts as the root resource under which operational aspects of
the service are accessible
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Service Monitoring': 'https://cloud.google.com/monitoring/service-monitoring'
'Monitoring API Documentation': 'https://cloud.google.com/monitoring/api/v3/'
api: 'https://cloud.google.com/monitoring/api/ref_v3/rest/v3/services'
parameters:
- !ruby/object:Api::Type::String
name: serviceId
description: |
An optional service ID to use. If not given, the server will generate a
service ID.
input: true
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
properties:
- !ruby/object:Api::Type::String
name: name
description: |
The full resource name for this service. The syntax is:
projects/[PROJECT_ID]/services/[SERVICE_ID].
output: true
- !ruby/object:Api::Type::String
name: displayName
description: |
Name used for UI elements listing this Service.
- !ruby/object:Api::Type::KeyValuePairs
name: 'userLabels'
description: |
Labels which have been used to annotate the service. Label keys must start
with a letter. Label keys and values may contain lowercase letters,
numbers, underscores, and dashes. Label keys and values have a maximum
length of 63 characters, and must be less than 128 bytes in size. Up to 64
label entries may be stored. For labels which do not have a semantic value,
the empty string may be supplied for the label value.
send_empty_value: true
- !ruby/object:Api::Type::NestedObject
name: telemetry
description: |
Configuration for how to query telemetry on a Service.
# Non custom service have non-editable telemetry
output: true
properties:
- !ruby/object:Api::Type::String
name: resourceName
description: |
The full name of the resource that defines this service.
Formatted as described in
https://cloud.google.com/apis/design/resource_names.
- !ruby/object:Api::Type::NestedObject
name: basicService
description: |
A well-known service type, defined by its service type and service labels.
# BasicService info can be set on creation but is then immutable.
input: true
properties:
- !ruby/object:Api::Type::String
name: serviceType
description: |
The type of service that this basic service defines, e.g.
APP_ENGINE service type
# BasicService info can be set on creation but is then immutable.
input: true
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
- !ruby/object:Api::Type::KeyValuePairs
name: serviceLabels
description: |
Labels that specify the resource that emits the monitoring data
which is used for SLO reporting of this `Service`.
# BasicService info can be set on creation but is then immutable.
input: true


- !ruby/object:Api::Resource
name: Slo
Expand Down
22 changes: 22 additions & 0 deletions mmv1/products/monitoring/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_import: templates/terraform/custom_import/self_link_as_name.erb
encoder: templates/terraform/encoders/monitoring_service.go.erb

GenericService: !ruby/object:Overrides::Terraform::ResourceOverride
legacy_name: 'google_monitoring_service'
id_format: "{{name}}"
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
import_format: ["{{name}}"]
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
error_retry_predicates: ["isMonitoringConcurrentEditError"]
properties:
serviceId: !ruby/object:Overrides::Terraform::PropertyOverride
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
api_name: 'name'
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
default_from_api: true
validation: !ruby/object:Provider::Terraform::Validation
regex: '^[a-z0-9\-]+$'
examples:
- !ruby/object:Provider::Terraform::Examples
name: "monitoring_service_example"
primary_resource_id: "my_service"
vars:
service_id: "my-service"
custom_code: !ruby/object:Provider::Terraform::CustomCode
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
custom_import: templates/terraform/custom_import/self_link_as_name.erb
encoder: templates/terraform/encoders/monitoring_service_generic.go.erb

Slo: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{name}}"
import_format: ["{{name}}"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%# The license inside this block applies to this file.
# Copyright 2022 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.
-%>
// query only parameters below
etruong42 marked this conversation as resolved.
Show resolved Hide resolved
delete(obj, "name")
delete(obj, "app_engine")
delete(obj, "cloud_endpoints")
delete(obj, "cluster_istio")
delete(obj, "mesh_istio")
delete(obj, "istio_canonical_service")
delete(obj, "cloud_run")
delete(obj, "gke_namespace")
delete(obj, "gke_workload")
delete(obj, "gke_service")

return obj, nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "google_monitoring_service" "<%= ctx[:primary_resource_id] -%>" {
service_id = "<%= ctx[:vars]['service_id'] -%>"
display_name = "My Service <%= ctx[:vars]['service_id'] -%>"

user_labels = {
my_key = "my_value"
my_other_key = "my_other_value"
}

basic_service {
service_type = "APP_ENGINE"
service_labels = {
module_id = "another-module-id"
}
}
}