From 6b1645282d3d7f23c209a9a8509b61c55798a2b3 Mon Sep 17 00:00:00 2001 From: megan07 Date: Tue, 3 Sep 2019 16:58:56 -0500 Subject: [PATCH] update explicit buckets name and make item_type of bounds integers (#2258) Merged PR #2258. --- api/type.rb | 7 +++ build/terraform | 2 +- build/terraform-beta | 2 +- build/terraform-mapper | 2 +- products/logging/api.yaml | 4 +- templates/terraform/schema_property.erb | 2 +- .../tests/resource_logging_metric_test.go | 44 +++++++++++++++++++ 7 files changed, 57 insertions(+), 6 deletions(-) diff --git a/api/type.rb b/api/type.rb index ec91d33b906f..9b67c2c530c0 100644 --- a/api/type.rb +++ b/api/type.rb @@ -361,6 +361,13 @@ def nested_properties super end + + def item_type_class + return @item_type \ + if @item_type.class == Class + + Object.const_get(@item_type) + end end # Represents an enum, and store is valid values diff --git a/build/terraform b/build/terraform index 37dc50f49e02..e98e87b81742 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 37dc50f49e021f6eb949b03e8affafeb71fc0d09 +Subproject commit e98e87b81742a7ff5118dc0b6906b748249dd54f diff --git a/build/terraform-beta b/build/terraform-beta index d2287e995725..a15637de8c3f 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit d2287e99572546e3df416d214770fb527cf123e2 +Subproject commit a15637de8c3f5a32921393e32f4520441141c8f1 diff --git a/build/terraform-mapper b/build/terraform-mapper index 0e796d77d3ff..82d0cc1041b0 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit 0e796d77d3ffcf51d3bdc1be4e4b220f8e151f9f +Subproject commit 82d0cc1041b0bb0087b93872322ee174c5c156e4 diff --git a/products/logging/api.yaml b/products/logging/api.yaml index 6f76f7cc22dc..480e9414d316 100644 --- a/products/logging/api.yaml +++ b/products/logging/api.yaml @@ -181,13 +181,13 @@ objects: description: | Must be greater than 0. - !ruby/object:Api::Type::NestedObject - name: explicit + name: explicitBuckets description: | Specifies a set of buckets with arbitrary widths. properties: - !ruby/object:Api::Type::Array name: bounds - item_type: Api::Type::String + item_type: Api::Type::Double description: | The values must be monotonically increasing. - !ruby/object:Api::Resource diff --git a/templates/terraform/schema_property.erb b/templates/terraform/schema_property.erb index f9c52a3fa3ba..b4e6c13eff6e 100644 --- a/templates/terraform/schema_property.erb +++ b/templates/terraform/schema_property.erb @@ -94,7 +94,7 @@ <% end -%> <% elsif property.item_type.is_a?(String) # Basic type like Api::Type::String -%> Elem: &schema.Schema{ - Type: <%= tf_types[property.item_type] -%>, + Type: <%= tf_types[property.item_type_class] -%>, }, <% else # array of basic types -%> Elem: &schema.Schema{ diff --git a/third_party/terraform/tests/resource_logging_metric_test.go b/third_party/terraform/tests/resource_logging_metric_test.go index f1585e1e9554..b8c3c546ef6f 100644 --- a/third_party/terraform/tests/resource_logging_metric_test.go +++ b/third_party/terraform/tests/resource_logging_metric_test.go @@ -40,6 +40,29 @@ func TestAccLoggingMetric_update(t *testing.T) { }) } +func TestAccLoggingMetric_explicitBucket(t *testing.T) { + t.Parallel() + + suffix := acctest.RandString(10) + filter := "resource.type=gae_app AND severity>=ERROR" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckLoggingMetricDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLoggingMetric_explicitBucket(suffix, filter), + }, + { + ResourceName: "google_logging_metric.logging_metric", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccLoggingMetric_update(suffix string, filter string) string { return fmt.Sprintf(` resource "google_logging_metric" "logging_metric" { @@ -51,3 +74,24 @@ resource "google_logging_metric" "logging_metric" { } }`, suffix, filter) } + +func testAccLoggingMetric_explicitBucket(suffix string, filter string) string { + return fmt.Sprintf(` +resource "google_logging_metric" "logging_metric" { + name = "my-custom-metric-%s" + filter = "%s" + + metric_descriptor { + metric_kind = "DELTA" + value_type = "DISTRIBUTION" + } + + value_extractor = "EXTRACT(jsonPayload.metrics.running_jobs)" + + bucket_options { + explicit_buckets { + bounds = [0,1,2,3,4.2] + } + } +}`, suffix, filter) +}