Skip to content

Commit

Permalink
Add L7 ILB fields to RegionBackendService (#244)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and Stuart Paterson committed Nov 6, 2019
1 parent f73175a commit 5b35a02
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/resources/google_compute_backend_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Properties that can be accessed from the `google_compute_backend_service` resour

* `description`: An optional description of this resource. Provide this property when you create the resource.

* `group`: The fully-qualified URL of an Instance Group or Network Endpoint Group resource. In case of instance group this defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. For Network Endpoint Groups this defines list of endpoints. All endpoints of Network Endpoint Group must be hosted on instances located in the same zone as the Network Endpoint Group. Backend service can not contain mix of Instance Group and Network Endpoint Group backends. Note that you must specify an Instance Group or Network Endpoint Group resource using the fully-qualified URL, rather than a partial URL.
* `group`: The fully-qualified URL of an Instance Group or Network Endpoint Group resource. In case of instance group this defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. For Network Endpoint Groups this defines list of endpoints. All endpoints of Network Endpoint Group must be hosted on instances located in the same zone as the Network Endpoint Group. Backend services cannot mix Instance Group and Network Endpoint Group backends. Note that you must specify an Instance Group or Network Endpoint Group resource using the fully-qualified URL, rather than a partial URL.

* `max_connections`: The max number of simultaneous connections for the group. Can be used with either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or one of maxConnectionsPerInstance or maxConnectionsPerEndpoint, as appropriate for group type, must be set.

Expand Down
44 changes: 33 additions & 11 deletions docs/resources/google_compute_region_backend_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,55 @@ end
Properties that can be accessed from the `google_compute_region_backend_service` resource:


* `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.
* `backends`: The set of backends that serve this RegionBackendService.

* `health_checks`: The list of HealthChecks for checking the health of the backend service. Currently at most one health check can be specified, and a health check is required.
* `balancing_mode`: Specifies the balancing mode for this backend. Defaults to CONNECTION.

* `backends`: The list of backends that serve this RegionBackendService.
* `capacity_scaler`: A multiplier applied to the group's maximum servicing capacity (based on UTILIZATION, RATE or CONNECTION). A setting of 0 means the group is completely drained, offering 0% of its available Capacity. Valid range is [0.0,1.0].

* `description`: An optional description of this resource. Provide this property when you create the resource.

* `group`: The fully-qualified URL of an Instance Group. This defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. Note that you must specify an Instance Group resource using the fully-qualified URL, rather than a partial URL. The instance group must be within the same region as the BackendService.
* `group`: The fully-qualified URL of an Instance Group or Network Endpoint Group resource. In case of instance group this defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. For Network Endpoint Groups this defines list of endpoints. All endpoints of Network Endpoint Group must be hosted on instances located in the same zone as the Network Endpoint Group. Backend services cannot mix Instance Group and Network Endpoint Group backends. When the `load_balancing_scheme` is INTERNAL, only instance groups are supported. Note that you must specify an Instance Group or Network Endpoint Group resource using the fully-qualified URL, rather than a partial URL.

* `description`: An optional description of this resource.
* `max_connections`: The max number of simultaneous connections for the group. Can be used with either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or one of maxConnectionsPerInstance or maxConnectionsPerEndpoint, as appropriate for group type, must be set.

* `fingerprint`: Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking.
* `max_connections_per_instance`: The max number of simultaneous connections that a single backend instance can handle. This is used to calculate the capacity of the group. Can be used in either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or maxConnectionsPerInstance must be set.

* `protocol`: The protocol this BackendService uses to communicate with backends. The possible values are TCP and UDP, and the default is TCP.
* `max_connections_per_endpoint`: The max number of simultaneous connections that a single backend network endpoint can handle. This is used to calculate the capacity of the group. Can be used in either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or maxConnectionsPerEndpoint must be set.

* `session_affinity`: Type of session affinity to use. The default is NONE. Can be NONE, CLIENT_IP, CLIENT_IP_PROTO, or CLIENT_IP_PORT_PROTO. When the protocol is UDP, this field is not used.
* `max_rate`: The max requests per second (RPS) of the group. Can be used with either RATE or UTILIZATION balancing modes, but required if RATE mode. Either maxRate or one of maxRatePerInstance or maxRatePerEndpoint, as appropriate for group type, must be set.

* `region`: The region where the regional backend service resides.
* `max_rate_per_instance`: The max requests per second (RPS) that a single backend instance can handle. This is used to calculate the capacity of the group. Can be used in either balancing mode. For RATE mode, either maxRate or maxRatePerInstance must be set.

* `timeout_sec`: How many seconds to wait for the backend before considering it a failed request. Default is 30 seconds. Valid range is [1, 86400].
* `max_rate_per_endpoint`: The max requests per second (RPS) that a single backend network endpoint can handle. This is used to calculate the capacity of the group. Can be used in either balancing mode. For RATE mode, either maxRate or maxRatePerEndpoint must be set.

* `max_utilization`: Used when balancingMode is UTILIZATION. This ratio defines the CPU utilization target for the group. Valid range is [0.0, 1.0].

* `connection_draining`: Settings for connection draining

* `draining_timeout_sec`: Time for which instance will be drained (not accept new connections, but still work to finish started).

* `load_balancing_scheme`: This signifies what the ForwardingRule will be used for and can only be INTERNAL for RegionBackendServices
* `creation_timestamp`: Creation timestamp in RFC3339 text format.

* `description`: An optional description of this resource.

* `fingerprint`: Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking.

* `health_checks`: The set of URLs to HealthCheck resources for health checking this RegionBackendService. Currently at most one health check can be specified, and a health check is required.

* `id`: The unique identifier for the resource.

* `load_balancing_scheme`: Indicates what kind of load balancing this regional backend service will be used for. A backend service created for one type of load balancing cannot be used with the other(s). Must be `INTERNAL` or `INTERNAL_MANAGED`. Defaults to `INTERNAL`.

* `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

* `protocol`: The protocol this RegionBackendService uses to communicate with backends. Possible values are HTTP, HTTPS, HTTP2, SSL, TCP, and UDP. The default is HTTP. **NOTE**: HTTP2 is only valid for beta HTTP/2 load balancer types and may result in errors if used with the GA API.

* `session_affinity`: Type of session affinity to use. The default is NONE. Session affinity is not applicable if the protocol is UDP.

* `timeout_sec`: How many seconds to wait for the backend before considering it a failed request. Default is 30 seconds. Valid range is [1, 86400].

* `region`: A reference to the region where the regional backend service resides.


## GCP Permissions
Expand Down
12 changes: 7 additions & 5 deletions docs/resources/google_compute_region_backend_services.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ end
Properties that can be accessed from the `google_compute_region_backend_services` resource:

See [google_compute_region_backend_service.md](google_compute_region_backend_service.md) for more detailed information
* `names`: an array of `google_compute_region_backend_service` name
* `health_checks`: an array of `google_compute_region_backend_service` health_checks
* `backends`: an array of `google_compute_region_backend_service` backends
* `connection_drainings`: an array of `google_compute_region_backend_service` connection_draining
* `creation_timestamps`: an array of `google_compute_region_backend_service` creation_timestamp
* `descriptions`: an array of `google_compute_region_backend_service` description
* `fingerprints`: an array of `google_compute_region_backend_service` fingerprint
* `health_checks`: an array of `google_compute_region_backend_service` health_checks
* `ids`: an array of `google_compute_region_backend_service` id
* `load_balancing_schemes`: an array of `google_compute_region_backend_service` load_balancing_scheme
* `names`: an array of `google_compute_region_backend_service` name
* `protocols`: an array of `google_compute_region_backend_service` protocol
* `session_affinities`: an array of `google_compute_region_backend_service` session_affinity
* `regions`: an array of `google_compute_region_backend_service` region
* `timeout_secs`: an array of `google_compute_region_backend_service` timeout_sec
* `connection_drainings`: an array of `google_compute_region_backend_service` connection_draining
* `load_balancing_schemes`: an array of `google_compute_region_backend_service` load_balancing_scheme
* `regions`: an array of `google_compute_region_backend_service` region

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
Expand Down
27 changes: 27 additions & 0 deletions libraries/google/compute/property/regionbackendservice_backends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,42 @@ module GoogleInSpec
module Compute
module Property
class RegionBackendServiceBackends
attr_reader :balancing_mode

attr_reader :capacity_scaler

attr_reader :description

attr_reader :group

attr_reader :max_connections

attr_reader :max_connections_per_instance

attr_reader :max_connections_per_endpoint

attr_reader :max_rate

attr_reader :max_rate_per_instance

attr_reader :max_rate_per_endpoint

attr_reader :max_utilization

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@balancing_mode = args['balancingMode']
@capacity_scaler = args['capacityScaler']
@description = args['description']
@group = args['group']
@max_connections = args['maxConnections']
@max_connections_per_instance = args['maxConnectionsPerInstance']
@max_connections_per_endpoint = args['maxConnectionsPerEndpoint']
@max_rate = args['maxRate']
@max_rate_per_instance = args['maxRatePerInstance']
@max_rate_per_endpoint = args['maxRatePerEndpoint']
@max_utilization = args['maxUtilization']
end

def to_s
Expand Down
24 changes: 14 additions & 10 deletions libraries/google_compute_region_backend_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ class ComputeRegionBackendService < GcpResourceBase
supports platform: 'gcp'

attr_reader :params
attr_reader :name
attr_reader :health_checks
attr_reader :backends
attr_reader :connection_draining
attr_reader :creation_timestamp
attr_reader :description
attr_reader :fingerprint
attr_reader :health_checks
attr_reader :id
attr_reader :load_balancing_scheme
attr_reader :name
attr_reader :protocol
attr_reader :session_affinity
attr_reader :region
attr_reader :timeout_sec
attr_reader :connection_draining
attr_reader :load_balancing_scheme
attr_reader :region

def initialize(params)
super(params.merge({ use_http_transport: true }))
Expand All @@ -44,17 +46,19 @@ def initialize(params)
end

def parse
@name = @fetched['name']
@health_checks = @fetched['healthChecks']
@backends = GoogleInSpec::Compute::Property::RegionBackendServiceBackendsArray.parse(@fetched['backends'], to_s)
@connection_draining = GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(@fetched['connectionDraining'], to_s)
@creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
@description = @fetched['description']
@fingerprint = @fetched['fingerprint']
@health_checks = @fetched['healthChecks']
@id = @fetched['id']
@load_balancing_scheme = @fetched['loadBalancingScheme']
@name = @fetched['name']
@protocol = @fetched['protocol']
@session_affinity = @fetched['sessionAffinity']
@region = @fetched['region']
@timeout_sec = @fetched['timeoutSec']
@connection_draining = GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(@fetched['connectionDraining'], to_s)
@load_balancing_scheme = @fetched['loadBalancingScheme']
@region = @fetched['region']
end

# Handles parsing RFC3339 time string
Expand Down
24 changes: 14 additions & 10 deletions libraries/google_compute_region_backend_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ class ComputeRegionBackendServices < GcpResourceBase

filter_table_config = FilterTable.create

filter_table_config.add(:names, field: :name)
filter_table_config.add(:health_checks, field: :health_checks)
filter_table_config.add(:backends, field: :backends)
filter_table_config.add(:connection_drainings, field: :connection_draining)
filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:fingerprints, field: :fingerprint)
filter_table_config.add(:health_checks, field: :health_checks)
filter_table_config.add(:ids, field: :id)
filter_table_config.add(:load_balancing_schemes, field: :load_balancing_scheme)
filter_table_config.add(:names, field: :name)
filter_table_config.add(:protocols, field: :protocol)
filter_table_config.add(:session_affinities, field: :session_affinity)
filter_table_config.add(:regions, field: :region)
filter_table_config.add(:timeout_secs, field: :timeout_sec)
filter_table_config.add(:connection_drainings, field: :connection_draining)
filter_table_config.add(:load_balancing_schemes, field: :load_balancing_scheme)
filter_table_config.add(:regions, field: :region)

filter_table_config.connect(self, :table)

Expand Down Expand Up @@ -73,17 +75,19 @@ def transform(key, value)

def transformers
{
'name' => ->(obj) { return :name, obj['name'] },
'healthChecks' => ->(obj) { return :health_checks, obj['healthChecks'] },
'backends' => ->(obj) { return :backends, GoogleInSpec::Compute::Property::RegionBackendServiceBackendsArray.parse(obj['backends'], to_s) },
'connectionDraining' => ->(obj) { return :connection_draining, GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(obj['connectionDraining'], to_s) },
'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) },
'description' => ->(obj) { return :description, obj['description'] },
'fingerprint' => ->(obj) { return :fingerprint, obj['fingerprint'] },
'healthChecks' => ->(obj) { return :health_checks, obj['healthChecks'] },
'id' => ->(obj) { return :id, obj['id'] },
'loadBalancingScheme' => ->(obj) { return :load_balancing_scheme, obj['loadBalancingScheme'] },
'name' => ->(obj) { return :name, obj['name'] },
'protocol' => ->(obj) { return :protocol, obj['protocol'] },
'sessionAffinity' => ->(obj) { return :session_affinity, obj['sessionAffinity'] },
'region' => ->(obj) { return :region, obj['region'] },
'timeoutSec' => ->(obj) { return :timeout_sec, obj['timeoutSec'] },
'connectionDraining' => ->(obj) { return :connection_draining, GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(obj['connectionDraining'], to_s) },
'loadBalancingScheme' => ->(obj) { return :load_balancing_scheme, obj['loadBalancingScheme'] },
'region' => ->(obj) { return :region, obj['region'] },
}
end

Expand Down

0 comments on commit 5b35a02

Please sign in to comment.