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

Commit

Permalink
adds scaling properties to appengine standard version (#3373) (#386)
Browse files Browse the repository at this point in the history
* adds scaling properties to appengine standard version

* use optional scaling properties

as it defaults to automaticScaling

* cover all automatic_scaling properties during test

* update test for standard appengine version

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 23, 2020
1 parent b3e3f87 commit 0c553ce
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 1 deletion.
34 changes: 33 additions & 1 deletion docs/resources/google_appengine_standard_app_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,39 @@ Properties that can be accessed from the `google_appengine_standard_app_version`

* `threadsafe`: Whether multiple requests can be dispatched to this version at once.

* `instance_class`: Instance class that is used to run this version. Valid values are AutomaticScaling F1, F2, F4, F4_1G (Only AutomaticScaling is supported at the moment)
* `instance_class`: Instance class that is used to run this version. Valid values are AutomaticScaling: F1, F2, F4, F4_1G BasicScaling or ManualScaling: B1, B2, B4, B4_1G, B8 Defaults to F1 for AutomaticScaling and B2 for ManualScaling and BasicScaling. If no scaling is specified, AutomaticScaling is chosen.

* `automatic_scaling`: Automatic scaling is based on request rate, response latencies, and other application metrics.

* `max_concurrent_requests`: Number of concurrent requests an automatic scaling instance can accept before the scheduler spawns a new instance. Defaults to a runtime-specific value.

* `max_idle_instances`: Maximum number of idle instances that should be maintained for this version.

* `max_pending_latency`: Maximum amount of time that a request should wait in the pending queue before starting a new instance to handle it. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".

* `min_idle_instances`: Minimum number of idle instances that should be maintained for this version. Only applicable for the default version of a service.

* `min_pending_latency`: Minimum amount of time a request should wait in the pending queue before starting a new instance to handle it. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".

* `standard_scheduler_settings`: Scheduler settings for standard environment.

* `target_cpu_utilization`: Target CPU utilization ratio to maintain when scaling. Should be a value in the range [0.50, 0.95], zero, or a negative value.

* `target_throughput_utilization`: Target throughput utilization ratio to maintain when scaling. Should be a value in the range [0.50, 0.95], zero, or a negative value.

* `min_instances`: Minimum number of instances to run for this version. Set to zero to disable minInstances configuration.

* `max_instances`: Maximum number of instances to run for this version. Set to zero to disable maxInstances configuration.

* `basic_scaling`: Basic scaling creates instances when your application receives requests. Each instance will be shut down when the application becomes idle. Basic scaling is ideal for work that is intermittent or driven by user activity.

* `idle_timeout`: Duration of time after the last request that an instance must wait before the instance is shut down. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s". Defaults to 900s.

* `max_instances`: Maximum number of instances to create for this version. Must be in the range [1.0, 200.0].

* `manual_scaling`: A service with manual scaling runs continuously, allowing you to perform complex initialization and rely on the state of its memory over time.

* `instances`: Number of instances to assign to the service at the start. **Note:** When managing the number of instances at runtime through the App Engine Admin API or the (now deprecated) Python 2 Modules API set_num_instances() you must use `lifecycle.ignore_changes = ["manual_scaling"[0].instances]` to prevent drift detection.


## GCP Permissions
Expand Down
3 changes: 3 additions & 0 deletions docs/resources/google_appengine_standard_app_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ See [google_appengine_standard_app_version.md](google_appengine_standard_app_ver
* `runtimes`: an array of `google_appengine_standard_app_version` runtime
* `threadsaves`: an array of `google_appengine_standard_app_version` threadsafe
* `instance_classes`: an array of `google_appengine_standard_app_version` instance_class
* `automatic_scalings`: an array of `google_appengine_standard_app_version` automatic_scaling
* `basic_scalings`: an array of `google_appengine_standard_app_version` basic_scaling
* `manual_scalings`: an array of `google_appengine_standard_app_version` manual_scaling

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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/appengine/property/standardappversion_automatic_scaling_standard_scheduler_settings'
module GoogleInSpec
module AppEngine
module Property
class StandardAppVersionAutomaticScaling
attr_reader :max_concurrent_requests

attr_reader :max_idle_instances

attr_reader :max_pending_latency

attr_reader :min_idle_instances

attr_reader :min_pending_latency

attr_reader :standard_scheduler_settings

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@max_concurrent_requests = args['maxConcurrentRequests']
@max_idle_instances = args['maxIdleInstances']
@max_pending_latency = args['maxPendingLatency']
@min_idle_instances = args['minIdleInstances']
@min_pending_latency = args['minPendingLatency']
@standard_scheduler_settings = GoogleInSpec::AppEngine::Property::StandardAppVersionAutomaticScalingStandardSchedulerSettings.new(args['standardSchedulerSettings'], to_s)
end

def to_s
"#{@parent_identifier} StandardAppVersionAutomaticScaling"
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 AppEngine
module Property
class StandardAppVersionAutomaticScalingStandardSchedulerSettings
attr_reader :target_cpu_utilization

attr_reader :target_throughput_utilization

attr_reader :min_instances

attr_reader :max_instances

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@target_cpu_utilization = args['targetCpuUtilization']
@target_throughput_utilization = args['targetThroughputUtilization']
@min_instances = args['minInstances']
@max_instances = args['maxInstances']
end

def to_s
"#{@parent_identifier} StandardAppVersionAutomaticScalingStandardSchedulerSettings"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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 AppEngine
module Property
class StandardAppVersionBasicScaling
attr_reader :idle_timeout

attr_reader :max_instances

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@idle_timeout = args['idleTimeout']
@max_instances = args['maxInstances']
end

def to_s
"#{@parent_identifier} StandardAppVersionBasicScaling"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 AppEngine
module Property
class StandardAppVersionManualScaling
attr_reader :instances

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@instances = args['instances']
end

def to_s
"#{@parent_identifier} StandardAppVersionManualScaling"
end
end
end
end
end
10 changes: 10 additions & 0 deletions libraries/google_appengine_standard_app_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
require 'google/appengine/property/standardappversion_automatic_scaling'
require 'google/appengine/property/standardappversion_automatic_scaling_standard_scheduler_settings'
require 'google/appengine/property/standardappversion_basic_scaling'
require 'google/appengine/property/standardappversion_manual_scaling'

# A provider to manage App Engine resources.
class AppEngineStandardAppVersion < GcpResourceBase
Expand All @@ -27,6 +31,9 @@ class AppEngineStandardAppVersion < GcpResourceBase
attr_reader :runtime
attr_reader :threadsafe
attr_reader :instance_class
attr_reader :automatic_scaling
attr_reader :basic_scaling
attr_reader :manual_scaling

def initialize(params)
super(params.merge({ use_http_transport: true }))
Expand All @@ -41,6 +48,9 @@ def parse
@runtime = @fetched['runtime']
@threadsafe = @fetched['threadsafe']
@instance_class = @fetched['instanceClass']
@automatic_scaling = GoogleInSpec::AppEngine::Property::StandardAppVersionAutomaticScaling.new(@fetched['automaticScaling'], to_s)
@basic_scaling = GoogleInSpec::AppEngine::Property::StandardAppVersionBasicScaling.new(@fetched['basicScaling'], to_s)
@manual_scaling = GoogleInSpec::AppEngine::Property::StandardAppVersionManualScaling.new(@fetched['manualScaling'], to_s)
end

def exists?
Expand Down
6 changes: 6 additions & 0 deletions libraries/google_appengine_standard_app_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class AppEngineStandardAppVersions < GcpResourceBase
filter_table_config.add(:runtimes, field: :runtime)
filter_table_config.add(:threadsaves, field: :threadsafe)
filter_table_config.add(:instance_classes, field: :instance_class)
filter_table_config.add(:automatic_scalings, field: :automatic_scaling)
filter_table_config.add(:basic_scalings, field: :basic_scaling)
filter_table_config.add(:manual_scalings, field: :manual_scaling)

filter_table_config.connect(self, :table)

Expand Down Expand Up @@ -72,6 +75,9 @@ def transformers
'runtime' => ->(obj) { return :runtime, obj['runtime'] },
'threadsafe' => ->(obj) { return :threadsafe, obj['threadsafe'] },
'instanceClass' => ->(obj) { return :instance_class, obj['instanceClass'] },
'automaticScaling' => ->(obj) { return :automatic_scaling, GoogleInSpec::AppEngine::Property::StandardAppVersionAutomaticScaling.new(obj['automaticScaling'], to_s) },
'basicScaling' => ->(obj) { return :basic_scaling, GoogleInSpec::AppEngine::Property::StandardAppVersionBasicScaling.new(obj['basicScaling'], to_s) },
'manualScaling' => ->(obj) { return :manual_scaling, GoogleInSpec::AppEngine::Property::StandardAppVersionManualScaling.new(obj['manualScaling'], to_s) },
}
end

Expand Down

0 comments on commit 0c553ce

Please sign in to comment.