Skip to content

Commit 874e72b

Browse files
committed
fix log rate limit quota checking
1 parent c0be516 commit 874e72b

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

app/actions/deployment_create.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def record_audit_event(deployment, droplet, user_audit_info, message)
169169
private
170170

171171
def validate_quota!(message, app)
172-
return if message.web_instances.blank? && message.memory_in_mb.blank?
172+
return if message.web_instances.blank? && message.memory_in_mb.blank? && message.log_rate_limit_in_bytes_per_second.blank?
173173

174174
current_web_process = app.newest_web_process
175175
current_web_process.instances = message.web_instances if message.web_instances
@@ -179,7 +179,6 @@ def validate_quota!(message, app)
179179
# Quotas wont get checked unless the process is started
180180
current_web_process.state = ProcessModel::STARTED
181181
current_web_process.validate
182-
183182
raise Sequel::ValidationFailed.new(current_web_process) unless current_web_process.valid?
184183

185184
current_web_process.reload

app/models/runtime/constraints/max_log_rate_limit_policy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class AppMaxLogRateLimitPolicy < BaseMaxLogRateLimitPolicy
5050

5151
def additional_checks
5252
resource.started? &&
53-
(resource.column_changed?(:state) || resource.column_changed?(:instances))
53+
(resource.column_changed?(:state) || resource.column_changed?(:instances) || resource.column_changed?(:log_rate_limit))
5454
end
5555

5656
def requested_log_rate_limit

docs/v3/source/includes/api_resources/_deployments.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"options" : {
2121
"max_in_flight": 3,
2222
"web_instances": 5,
23+
"memory_in_mb": 1024,
24+
"disk_in_mb": 1024,
25+
"log_rate_limit_in_bytes_per_second": -1,
2326
"canary": {
2427
"steps": [
2528
{

docs/v3/source/includes/resources/deployments/_create.md.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ Name | Type | Description | Default
7979
**strategy** | _string_ | The strategy to use for the deployment | `rolling`
8080
**options.max_in_flight** | _integer_ | The maximum number of new instances to deploy simultaneously | 1
8181
**options.web_instances** | _integer_ | The number of web instances the deployment will scale to | The current web process's instance count
82+
**options.memory_in_mb** | _integer_ | The amount of memory in megabytes to allocate per web process instance. If `null`, the amount allocated will be taken from the previous web process. | `null`
83+
**options.disk_in_mb** | _integer_ | The amount of disk in megabytes to allocate per web process instance. If `null`, the amount allocated will be taken from the previous web process. | `null`
84+
**options.log_rate_limit_in_bytes_per_second** | _integer_ | Log rate limit in bytes per second to allocate per web process instance. If `null`, the amount allocated will be taken from the previous web process. | `null`
8285
**options.canary.steps** | _array of [canary step objects](#canary-steps-object)_ | An array of canary steps to use for the deployment
8386
**metadata.labels** | [_label object_](#labels) | Labels applied to the deployment
8487
**metadata.annotations** | [_annotation object_](#annotations) | Annotations applied to the deployment

docs/v3/source/includes/resources/deployments/_object.md.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Name | Type | Description
2121
**strategy** | _string_ | Strategy used for the deployment; supported strategies are `rolling` and `canary` (experimental)
2222
**options.max_in_flight** | _integer_ | The maximum number of new instances to deploy simultaneously
2323
**options.web_instances** | _integer_ | The number of web instances the deployment will scale to
24+
**options.memory_in_mb** | _integer_ | The amount of memory in megabytes to allocate per web process instance. If `null`, the amount allocated will be taken from the previous web process.
25+
**options.disk_in_mb** | _integer_ | The amount of disk in megabytes to allocate per web process instance. If `null`, the amount allocated will be taken from the previous web process.
26+
**options.log_rate_limit_in_bytes_per_second** | _integer_ | Log rate limit in bytes per second to allocate per web process instance. If `null`, the amount allocated will be taken from the previous web process.
2427
**options.canary.steps** | _array of [canary step objects](#canary-steps-object)_ | Canary steps to use for the deployment. Only available for deployments with strategy 'canary'. (experimental)
2528
**droplet.guid** | _string_ | The droplet guid that the deployment is transitioning the app to
2629
**previous_droplet.guid** | _string_ | The app's [current droplet guid](#get-current-droplet-association-for-an-app) before the deployment was created

spec/unit/actions/deployment_create_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -988,12 +988,12 @@ module VCAP::CloudController
988988
end
989989

990990
context 'when the final state of the resulting web_process does not violate a quota' do
991-
let(:disk_in_mb) { 1023 }
991+
let(:disk_in_mb) { 999 }
992992

993993
it 'does not throw an error' do
994994
deployment = DeploymentCreate.create(app:, message:, user_audit_info:)
995-
expect(deployment.disk_in_mb).to eq(1023)
996-
expect(app.reload.newest_web_process.disk_quota).to eq(1023)
995+
expect(deployment.disk_in_mb).to eq(999)
996+
expect(app.reload.newest_web_process.disk_quota).to eq(999)
997997
end
998998
end
999999
end
@@ -1019,7 +1019,7 @@ module VCAP::CloudController
10191019
end
10201020

10211021
context 'quota validations' do
1022-
let!(:web_process) { ProcessModel.make(app: app, instances: 3, memory: 999, state: process_state) }
1022+
let!(:web_process) { ProcessModel.make(app: app, instances: 3, log_rate_limit: 999, memory: 999, state: process_state) }
10231023

10241024
before do
10251025
app.organization.quota_definition = QuotaDefinition.make(app.organization, log_rate_limit: 10_000)

spec/unit/models/runtime/constraints/max_log_rate_limit_policy_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@
5050
expect(validator).to validate_with_error(process, :log_rate_limit, error_name)
5151
end
5252
end
53+
54+
context 'when the log_rate_limit has changed and would exceed the quota' do
55+
before do
56+
process.log_rate_limit = 500
57+
end
58+
59+
it 'registers an error' do
60+
expect(org_or_space).to receive(:has_remaining_log_rate_limit).with(400).and_return(false)
61+
expect(validator).to validate_with_error(process, :log_rate_limit, error_name)
62+
end
63+
end
5364
end
5465

5566
context 'when the app is being stopped' do

0 commit comments

Comments
 (0)