Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #102 from modular-magician/target-pools-autoscalers
Browse files Browse the repository at this point in the history
Target pools autoscalers
  • Loading branch information
Stuart Paterson authored Jan 24, 2019
2 parents 410060b + 9d25ef9 commit f79effb
Show file tree
Hide file tree
Showing 29 changed files with 1,069 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Metrics/CyclomaticComplexity:
Metrics/PerceivedComplexity:
Max: 11
Metrics/AbcSize:
Max: 33
Max: 50
Metrics/CyclomaticComplexity:
Max: 15
Metrics/PerceivedComplexity:
Expand Down
54 changes: 54 additions & 0 deletions docs/resources/google_compute_autoscaler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: About the Autoscaler resource
platform: gcp
---


## Syntax
A `google_compute_autoscaler` is used to test a Google Autoscaler resource

## Examples
```
describe google_compute_autoscaler(project: 'chef-gcp-inspec', zone: 'zone', name: 'inspec-gcp-autoscaler') do
it { should exist }
its('target') { should match /\/inspec-gcp-igm$/ }
its('autoscaling_policy.max_num_replicas') { should eq '5' }
its('autoscaling_policy.min_num_replicas') { should eq '1' }
its('autoscaling_policy.cool_down_period_sec') { should eq '60' }
its('autoscaling_policy.cpu_utilization.utilization_target') { should eq '0.5' }
end
describe google_compute_autoscaler(project: 'chef-gcp-inspec', zone: 'zone', name: 'nonexistent') do
it { should_not exist }
end
```

## Properties
Properties that can be accessed from the `google_compute_autoscaler` resource:

* `id`: Unique identifier for the resource.

* `creation_timestamp`: Creation timestamp in RFC3339 text format.

* `name`: Name of the resource. 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.

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

* `autoscaling_policy`: The configuration parameters for the autoscaling algorithm. You can define one or more of the policies for an autoscaler: cpuUtilization, customMetricUtilizations, and loadBalancingUtilization. If none of these are specified, the default will be to autoscale based on cpuUtilization to 0.6 or 60%.

* `minNumReplicas`: The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. If not provided, autoscaler will choose a default value depending on maximum number of instances allowed.

* `maxNumReplicas`: The maximum number of instances that the autoscaler can scale up to. This is required when creating or updating an autoscaler. The maximum number of replicas should not be lower than minimal number of replicas.

* `coolDownPeriodSec`: The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. This prevents the autoscaler from collecting information when the instance is initializing, during which the collected usage would not be reliable. The default time autoscaler waits is 60 seconds. Virtual machine initialization times might vary because of numerous factors. We recommend that you test how long an instance may take to initialize. To do this, create an instance and time the startup process.

* `cpuUtilization`: Defines the CPU utilization policy that allows the autoscaler to scale based on the average CPU utilization of a managed instance group.

* `customMetricUtilizations`: Defines the CPU utilization policy that allows the autoscaler to scale based on the average CPU utilization of a managed instance group.

* `loadBalancingUtilization`: Configuration parameters of autoscaling based on a load balancer.

* `target`: URL of the managed instance group that this autoscaler will scale.

* `zone`: URL of the zone where the instance group resides.
39 changes: 39 additions & 0 deletions docs/resources/google_compute_autoscalers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: About the Autoscaler resource
platform: gcp
---


## Syntax
A `google_compute_autoscalers` is used to test a Google Autoscaler resource

## Examples
```
autoscalers = google_compute_autoscalers(project: 'chef-gcp-inspec', zone: 'zone')
describe.one do
autoscalers.autoscaling_policies.each do |autoscaling_policy|
describe autoscaling_policy do
its('max_num_replicas') { should eq '5' }
its('min_num_replicas') { should eq '1' }
its('cool_down_period_sec') { should eq '60' }
its('cpu_utilization.utilization_target') { should eq '0.5' }
end
end
end
```

## Properties
Properties that can be accessed from the `google_compute_autoscalers` resource:

See [google_compute_autoscaler.md](google_compute_autoscaler.md) for more detailed information
* `ids`: an array of `google_compute_autoscaler` id
* `creation_timestamps`: an array of `google_compute_autoscaler` creation_timestamp
* `names`: an array of `google_compute_autoscaler` name
* `descriptions`: an array of `google_compute_autoscaler` description
* `autoscaling_policies`: an array of `google_compute_autoscaler` autoscaling_policy
* `targets`: an array of `google_compute_autoscaler` target
* `zones`: an array of `google_compute_autoscaler` zone

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
with `where` as a block or a method.
1 change: 0 additions & 1 deletion docs/resources/google_compute_instance_group_managers.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ A `google_compute_instance_group_managers` is used to test a Google InstanceGrou
describe google_compute_instance_group_managers(project: 'chef-gcp-inspec', zone: 'zone') do
its('base_instance_names') { should include 'igm' }
end
```

## Properties
Expand Down
44 changes: 44 additions & 0 deletions docs/resources/google_compute_target_pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: About the TargetPool resource
platform: gcp
---


## Syntax
A `google_compute_target_pool` is used to test a Google TargetPool resource

## Examples
```
describe google_compute_target_pool(project: 'chef-gcp-inspec', region: 'europe-west2', name: 'inspec-gcp-target-pool') do
it { should exist }
its('session_affinity') { should eq 'CLIENT_IP' }
it { should has_target_instance('gcp_ext_vm_name', 'zone') }
end
describe google_compute_target_pool(project: 'chef-gcp-inspec', region: 'europe-west2', name: 'nonexistent') do
it { should_not exist }
end
```

## Properties
Properties that can be accessed from the `google_compute_target_pool` resource:

* `backup_pool`: This field is applicable only when the containing target pool is serving a forwarding rule as the primary pool, and its failoverRatio field is properly set to a value between [0, 1]. backupPool and failoverRatio together define the fallback behavior of the primary target pool: if the ratio of the healthy instances in the primary pool is at or below failoverRatio, traffic arriving at the load-balanced IP will be directed to the backup pool. In case where failoverRatio and backupPool are not set, or all the instances in the backup pool are unhealthy, the traffic will be directed back to the primary pool in the "force" mode, where traffic will be spread to the healthy instances with the best effort, or to all instances when no instance is healthy.

* `creation_timestamp`: Creation timestamp in RFC3339 text format.

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

* `failover_ratio`: This field is applicable only when the containing target pool is serving a forwarding rule as the primary pool (i.e., not as a backup pool to some other target pool). The value of the field must be in [0, 1]. If set, backupPool must also be set. They together define the fallback behavior of the primary target pool: if the ratio of the healthy instances in the primary pool is at or below this number, traffic arriving at the load-balanced IP will be directed to the backup pool. In case where failoverRatio is not set or all the instances in the backup pool are unhealthy, the traffic will be directed back to the primary pool in the "force" mode, where traffic will be spread to the healthy instances with the best effort, or to all instances when no instance is healthy.

* `health_check`: A reference to a HttpHealthCheck resource. A member instance in this pool is considered healthy if and only if the health checks pass. If not specified it means all member instances will be considered healthy at all times.

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

* `instances`: A list of virtual machine instances serving this pool. They must live in zones contained in the same region as this pool.

* `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.

* `session_affinity`: Session affinity option. Must be one of these values: - NONE: Connections from the same client IP may go to any instance in the pool. - CLIENT_IP: Connections from the same client IP will go to the same instance in the pool while that instance remains healthy. - CLIENT_IP_PROTO: Connections from the same client IP with the same IP protocol will go to the same instance in the pool while that instance remains healthy.

* `region`: The region where the target pool resides.
35 changes: 35 additions & 0 deletions docs/resources/google_compute_target_pools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: About the TargetPool resource
platform: gcp
---


## Syntax
A `google_compute_target_pools` is used to test a Google TargetPool resource

## Examples
```
describe google_compute_target_pools(project: 'chef-gcp-inspec', region: 'europe-west2') do
its('names') { should include 'inspec-gcp-target-pool' }
its('session_affinities') { should include 'CLIENT_IP' }
end
```

## Properties
Properties that can be accessed from the `google_compute_target_pools` resource:

See [google_compute_target_pool.md](google_compute_target_pool.md) for more detailed information
* `backup_pools`: an array of `google_compute_target_pool` backup_pool
* `creation_timestamps`: an array of `google_compute_target_pool` creation_timestamp
* `descriptions`: an array of `google_compute_target_pool` description
* `failover_ratios`: an array of `google_compute_target_pool` failover_ratio
* `health_checks`: an array of `google_compute_target_pool` health_check
* `ids`: an array of `google_compute_target_pool` id
* `instances`: an array of `google_compute_target_pool` instances
* `names`: an array of `google_compute_target_pool` name
* `session_affinities`: an array of `google_compute_target_pool` session_affinity
* `regions`: an array of `google_compute_target_pool` region

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
with `where` as a block or a method.
1 change: 1 addition & 0 deletions docs/resources/google_pubsub_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ end
describe google_pubsub_subscription(project: 'chef-gcp-inspec', name: 'nonexistent') do
it { should_not exist }
end
```

## Properties
Expand Down
1 change: 0 additions & 1 deletion docs/resources/google_pubsub_subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ google_pubsub_subscriptions(project: 'chef-gcp-inspec').names.each do |subscript
it { should exist }
end
end
```

## Properties
Expand Down
1 change: 0 additions & 1 deletion docs/resources/google_pubsub_topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ google_pubsub_topics(project: 'chef-gcp-inspec').names.each do |topic_name|
its('name') { should eq 'inspec-gcp-topic' }
end
end
```

## Properties
Expand Down
47 changes: 47 additions & 0 deletions libraries/google/compute/property/autoscaler_autoscaling_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
require 'google/compute/property/autoscaler_cpu_utilization'
require 'google/compute/property/autoscaler_custom_metric_utilizations'
require 'google/compute/property/autoscaler_load_balancing_utilization'
module GoogleInSpec
module Compute
module Property
class AutoscalerAutoscalingpolicy
attr_reader :min_num_replicas

attr_reader :max_num_replicas

attr_reader :cool_down_period_sec

attr_reader :cpu_utilization

attr_reader :custom_metric_utilizations

attr_reader :load_balancing_utilization

def initialize(args = nil)
return if args.nil?
@min_num_replicas = args['minNumReplicas']
@max_num_replicas = args['maxNumReplicas']
@cool_down_period_sec = args['coolDownPeriodSec']
@cpu_utilization = GoogleInSpec::Compute::Property::AutoscalerCpuutilization.new(args['cpuUtilization'])
@custom_metric_utilizations = GoogleInSpec::Compute::Property::AutoscalerCustommetricutilizationsArray.parse(args['customMetricUtilizations'])
@load_balancing_utilization = GoogleInSpec::Compute::Property::AutoscalerLoadbalancingutilization.new(args['loadBalancingUtilization'])
end
end
end
end
end
29 changes: 29 additions & 0 deletions libraries/google/compute/property/autoscaler_cpu_utilization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
module GoogleInSpec
module Compute
module Property
class AutoscalerCpuutilization
attr_reader :utilization_target

def initialize(args = nil)
return if args.nil?
@utilization_target = args['utilizationTarget']
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
module GoogleInSpec
module Compute
module Property
class AutoscalerCustommetricutilizations
attr_reader :metric

attr_reader :utilization_target

attr_reader :utilization_target_type

def initialize(args = nil)
return if args.nil?
@metric = args['metric']
@utilization_target = args['utilizationTarget']
@utilization_target_type = args['utilizationTargetType']
end
end

class AutoscalerCustommetricutilizationsArray
def self.parse(value)
return if value.nil?
return AutoscalerCustommetricutilizations.new(value) unless value.is_a?(::Array)
value.map { |v| AutoscalerCustommetricutilizations.new(v) }
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------
module GoogleInSpec
module Compute
module Property
class AutoscalerLoadbalancingutilization
attr_reader :utilization_target

def initialize(args = nil)
return if args.nil?
@utilization_target = args['utilizationTarget']
end
end
end
end
end
Loading

0 comments on commit f79effb

Please sign in to comment.