From c4f5dc18583adee759132b88c98c20d259029771 Mon Sep 17 00:00:00 2001 From: justin-mp Date: Tue, 15 Mar 2022 12:04:09 -0400 Subject: [PATCH] Update EdgeCacheOrigin resources to reflect current API (#5776) --- mmv1/products/networkservices/api.yaml | 49 +++++++++++++++---- mmv1/products/networkservices/terraform.yaml | 4 +- .../network_services_timeout_mirror.go.erb | 24 +++++++-- ...services_edge_cache_origin_advanced.tf.erb | 10 ++-- ...network_services_edge_cache_origin_test.go | 9 +++- 5 files changed, 74 insertions(+), 22 deletions(-) diff --git a/mmv1/products/networkservices/api.yaml b/mmv1/products/networkservices/api.yaml index a895c4aa176b..a8d289827037 100644 --- a/mmv1/products/networkservices/api.yaml +++ b/mmv1/products/networkservices/api.yaml @@ -153,9 +153,9 @@ objects: description: | A fully qualified domain name (FQDN) or IP address reachable over the public Internet, or the address of a Google Cloud Storage bucket. - This address will be used as the origin for cache requests - e.g. FQDN: media-backend.example.com IPv4:35.218.1.1 IPv6:[2607:f8b0:4012:809::200e] Cloud Storage: gs://bucketname + This address will be used as the origin for cache requests - e.g. FQDN: media-backend.example.com, IPv4: 35.218.1.1, IPv6: 2607:f8b0:4012:809::200e, Cloud Storage: gs://bucketname - When providing an FQDN (hostname), it must be publicly resolvable (e.g. via Google public DNS) and IP addresses must be publicly routable. + When providing an FQDN (hostname), it must be publicly resolvable (e.g. via Google public DNS) and IP addresses must be publicly routable. It must not contain a protocol (e.g., https://) and it must not contain any slashes. If a Cloud Storage bucket is provided, it must be in the canonical "gs://bucketname" format. Other forms, such as "storage.googleapis.com", will be rejected. - !ruby/object:Api::Type::Enum name: 'protocol' # default http2 from api @@ -183,8 +183,8 @@ objects: The total number of allowed attempts to cache fill across this and failover origins is limited to four. The total time allowed for cache fill attempts across this and failover origins can be controlled with maxAttemptsTimeout. - The last valid response from an origin will be returned to the client. - If no origin returns a valid response, an HTTP 503 will be returned to the client. + The last valid, non-retried response from all origins will be returned to the client. + If no origin returns a valid response, an HTTP 502 will be returned to the client. Defaults to 1. Must be a value greater than 0 and less than 4. - !ruby/object:Api::Type::String @@ -215,6 +215,7 @@ objects: - GATEWAY_ERROR: Similar to 5xx, but only applies to response codes 502, 503 or 504. - RETRIABLE_4XX: Retry for retriable 4xx response codes, which include HTTP 409 (Conflict) and HTTP 429 (Too Many Requests) - NOT_FOUND: Retry if the origin returns a HTTP 404 (Not Found). This can be useful when generating video content, and the segment is not available yet. + - FORBIDDEN: Retry if the origin returns a HTTP 403 (Forbidden). item_type: !ruby/object:Api::Type::Enum name: 'undefined' description: | @@ -226,6 +227,7 @@ objects: - :GATEWAY_ERROR - :RETRIABLE_4XX - :NOT_FOUND + - :FORBIDDEN - !ruby/object:Api::Type::NestedObject name: 'timeout' description: | @@ -234,33 +236,62 @@ objects: - !ruby/object:Api::Type::String name: 'connectTimeout' description: | - The maximum duration to wait for the origin connection to be established, including DNS lookup, TLS handshake and TCP/QUIC connection establishment. + The maximum duration to wait for a single origin connection to be established, including DNS lookup, TLS handshake and TCP/QUIC connection establishment. Defaults to 5 seconds. The timeout must be a value between 1s and 15s. + + The connectTimeout capped by the deadline set by the request's maxAttemptsTimeout. The last connection attempt may have a smaller connectTimeout in order to adhere to the overall maxAttemptsTimeout. + at_least_one_of: - timeout.0.connect_timeout - timeout.0.max_attempts_timeout - timeout.0.response_timeout + - timeout.0.read_timeout - !ruby/object:Api::Type::String name: 'maxAttemptsTimeout' description: | - The maximum time across all connection attempts to the origin, including failover origins, before returning an error to the client. A HTTP 503 will be returned if the timeout is reached before a response is returned. + The maximum time across all connection attempts to the origin, including failover origins, before returning an error to the client. A HTTP 504 will be returned if the timeout is reached before a response is returned. - Defaults to 5 seconds. The timeout must be a value between 1s and 15s. + Defaults to 15 seconds. The timeout must be a value between 1s and 30s. + + If a failoverOrigin is specified, the maxAttemptsTimeout of the first configured origin sets the deadline for all connection attempts across all failoverOrigins. at_least_one_of: - timeout.0.connect_timeout - timeout.0.max_attempts_timeout - timeout.0.response_timeout + - timeout.0.read_timeout - !ruby/object:Api::Type::String name: 'responseTimeout' description: | - The maximum duration to wait for data to arrive when reading from the HTTP connection/stream. + The maximum duration to wait for the last byte of a response to arrive when reading from the HTTP connection/stream. + + Defaults to 30 seconds. The timeout must be a value between 1s and 120s. + + The responseTimeout starts after the connection has been established. + + This also applies to HTTP Chunked Transfer Encoding responses, and/or when an open-ended Range request is made to the origin. Origins that take longer to write additional bytes to the response than the configured responseTimeout will result in an error being returned to the client. + + If the response headers have already been written to the connection, the response will be truncated and logged. + at_least_one_of: + - timeout.0.connect_timeout + - timeout.0.max_attempts_timeout + - timeout.0.response_timeout + - timeout.0.read_timeout + - !ruby/object:Api::Type::String + name: 'readTimeout' + description: | + The maximum duration to wait between reads of a single HTTP connection/stream. + + Defaults to 15 seconds. The timeout must be a value between 1s and 30s. + + The readTimeout is capped by the responseTimeout. All reads of the HTTP connection/stream must be completed by the deadline set by the responseTimeout. - Defaults to 5 seconds. The timeout must be a value between 1s and 30s. + If the response headers have already been written to the connection, the response will be truncated and logged. at_least_one_of: - timeout.0.connect_timeout - timeout.0.max_attempts_timeout - timeout.0.response_timeout + - timeout.0.read_timeout - !ruby/object:Api::Resource name: 'EdgeCacheService' base_url: 'projects/{{project}}/locations/global/edgeCacheServices' diff --git a/mmv1/products/networkservices/terraform.yaml b/mmv1/products/networkservices/terraform.yaml index aa3bfbed06a3..64d757aaf770 100644 --- a/mmv1/products/networkservices/terraform.yaml +++ b/mmv1/products/networkservices/terraform.yaml @@ -58,8 +58,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides retryConditions: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true timeout: !ruby/object:Overrides::Terraform::PropertyOverride - # We don't support ignore_read on nested fields - ignore_read: true # b/192698242 custom_flatten: "templates/terraform/custom_flatten/network_services_timeout_mirror.go.erb" EdgeCacheService: !ruby/object:Overrides::Terraform::ResourceOverride docs: !ruby/object:Provider::Terraform::Docs # @@ -143,4 +141,4 @@ overrides: !ruby/object:Overrides::ResourceOverrides routing.pathMatchers.routeRules.urlRedirect.stripQuery: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true logConfig.enable: !ruby/object:Overrides::Terraform::PropertyOverride - default_from_api: true \ No newline at end of file + default_from_api: true diff --git a/mmv1/templates/terraform/custom_flatten/network_services_timeout_mirror.go.erb b/mmv1/templates/terraform/custom_flatten/network_services_timeout_mirror.go.erb index 4eaa9eb7d6ca..f3f73b7bc731 100644 --- a/mmv1/templates/terraform/custom_flatten/network_services_timeout_mirror.go.erb +++ b/mmv1/templates/terraform/custom_flatten/network_services_timeout_mirror.go.erb @@ -13,9 +13,25 @@ # limitations under the License. -%> func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { - out := make(map[string]interface{}) - out["connect_timeout"] = d.Get("timeout.0.connect_timeout") - out["max_attempts_timeout"] = d.Get("timeout.0.max_attempts_timeout") - out["responseTimeout"] = d.Get("timeout.0.responseTimeout") + out := make(map[string]string) + + if v == nil { + return nil + } + + in := v.(map[string]interface{}) + if e, ok := in["connectTimeout"]; ok { + out["connect_timeout"] = e.(string) + } + if e, ok := in["maxAttemptsTimeout"]; ok { + out["max_attempts_timeout"] = e.(string) + } + if e, ok := in["responseTimeout"]; ok { + out["response_timeout"] = e.(string) + } + if e, ok := in["readTimeout"]; ok { + out["read_timeout"] = e.(string) + } + return []interface{}{out} } diff --git a/mmv1/templates/terraform/examples/network_services_edge_cache_origin_advanced.tf.erb b/mmv1/templates/terraform/examples/network_services_edge_cache_origin_advanced.tf.erb index ed43cb996b34..dfd630dfc21f 100644 --- a/mmv1/templates/terraform/examples/network_services_edge_cache_origin_advanced.tf.erb +++ b/mmv1/templates/terraform/examples/network_services_edge_cache_origin_advanced.tf.erb @@ -10,12 +10,14 @@ resource "google_network_services_edge_cache_origin" "fallback" { retry_conditions = [ "CONNECT_FAILURE", "NOT_FOUND", - "HTTP_5XX" + "HTTP_5XX", + "FORBIDDEN", ] timeout { connect_timeout = "10s" - max_attempts_timeout = "10s" - response_timeout = "10s" + max_attempts_timeout = "20s" + response_timeout = "60s" + read_timeout = "5s" } } @@ -32,4 +34,4 @@ resource "google_network_services_edge_cache_origin" "<%= ctx[:primary_resource_ timeout { connect_timeout = "10s" } -} \ No newline at end of file +} diff --git a/mmv1/third_party/terraform/tests/resource_network_services_edge_cache_origin_test.go b/mmv1/third_party/terraform/tests/resource_network_services_edge_cache_origin_test.go index 9b9138678f46..9fb6d85cf2f2 100644 --- a/mmv1/third_party/terraform/tests/resource_network_services_edge_cache_origin_test.go +++ b/mmv1/third_party/terraform/tests/resource_network_services_edge_cache_origin_test.go @@ -22,7 +22,7 @@ func TestAccNetworkServicesEdgeCacheOrigin_updateAndImport(t *testing.T) { ResourceName: "google_network_services_edge_cache_origin.instance", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"name", "timeout"}, + ImportStateVerifyIgnore: []string{"name"}, }, { Config: testAccNetworkServicesEdgeCacheOrigin_update_1(name), @@ -31,7 +31,7 @@ func TestAccNetworkServicesEdgeCacheOrigin_updateAndImport(t *testing.T) { ResourceName: "google_network_services_edge_cache_origin.instance", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"name", "timeout"}, + ImportStateVerifyIgnore: []string{"name"}, }, }, }) @@ -46,6 +46,7 @@ func testAccNetworkServicesEdgeCacheOrigin_update_0(name string) string { labels = { a = "b" } + retry_conditions = ["NOT_FOUND"] timeout { connect_timeout = "10s" } @@ -59,8 +60,12 @@ func testAccNetworkServicesEdgeCacheOrigin_update_1(name string) string { origin_address = "gs://media-edge-fallback" description = "The default bucket for media edge test" max_attempts = 3 + retry_conditions = ["FORBIDDEN"] timeout { connect_timeout = "9s" + max_attempts_timeout = "14s" + response_timeout = "29s" + read_timeout = "13s" } } `, name)