diff --git a/app/actions/space_quota_update.rb b/app/actions/space_quota_update.rb index d20aee42a21..bbd1dad8cd0 100644 --- a/app/actions/space_quota_update.rb +++ b/app/actions/space_quota_update.rb @@ -14,6 +14,7 @@ def self.update(quota, message) quota.instance_memory_limit = instance_memory_limit(message) if message.apps_limits_message.requested? :per_process_memory_in_mb quota.app_instance_limit = app_instance_limit(message) if message.apps_limits_message.requested? :total_instances quota.app_task_limit = app_task_limit(message) if message.apps_limits_message.requested? :per_app_tasks + quota.log_limit = log_limit(message) if message.apps_limits_message.requested? :log_limit_in_bytes_per_second quota.total_services = total_services(message) if message.services_limits_message.requested? :total_service_instances quota.total_service_keys = total_service_keys(message) if message.services_limits_message.requested? :total_service_keys @@ -55,6 +56,10 @@ def self.app_task_limit(message) default_if_nil(message.per_app_tasks, SpaceQuotaDefinition::UNLIMITED) end + def self.log_limit(message) + default_if_nil(message.log_limit_in_bytes_per_second, SpaceQuotaDefinition::UNLIMITED) + end + def self.total_services(message) default_if_nil(message.total_service_instances, SpaceQuotaDefinition::UNLIMITED) end diff --git a/app/actions/space_quotas_create.rb b/app/actions/space_quotas_create.rb index 5b10fd617fd..019a6eb91e0 100644 --- a/app/actions/space_quotas_create.rb +++ b/app/actions/space_quotas_create.rb @@ -3,6 +3,7 @@ class SpaceQuotasCreate class Error < ::StandardError end + # rubocop:todo Metrics/CyclomaticComplexity def create(message, organization:) space_quota = nil @@ -16,6 +17,7 @@ def create(message, organization:) instance_memory_limit: message.per_process_memory_in_mb || SpaceQuotaDefinition::UNLIMITED, app_instance_limit: message.total_instances || SpaceQuotaDefinition::UNLIMITED, app_task_limit: message.per_app_tasks || SpaceQuotaDefinition::UNLIMITED, + log_limit: message.log_limit_in_bytes_per_second || QuotaDefinition::UNLIMITED, # Services total_services: message.total_service_instances || SpaceQuotaDefinition::DEFAULT_TOTAL_SERVICES, @@ -35,6 +37,7 @@ def create(message, organization:) rescue Sequel::ValidationFailed => e validation_error!(e, message) end + # rubocop:enable Metrics/CyclomaticComplexity private diff --git a/app/messages/space_quota_update_message.rb b/app/messages/space_quota_update_message.rb index dbb6728488d..1e3796322d8 100644 --- a/app/messages/space_quota_update_message.rb +++ b/app/messages/space_quota_update_message.rb @@ -22,7 +22,7 @@ def self.key_requested?(key) validate :services_validator, if: key_requested?(:services) validate :routes_validator, if: key_requested?(:routes) - delegate :total_memory_in_mb, :per_process_memory_in_mb, :total_instances, :per_app_tasks, to: :apps_limits_message + delegate :total_memory_in_mb, :per_process_memory_in_mb, :total_instances, :per_app_tasks, :log_limit_in_bytes_per_second, to: :apps_limits_message delegate :paid_services_allowed, :total_service_instances, :total_service_keys, to: :services_limits_message delegate :total_routes, :total_reserved_ports, to: :routes_limits_message diff --git a/app/models/runtime/space_quota_definition.rb b/app/models/runtime/space_quota_definition.rb index 4be195c6a4d..fea1f78bf9b 100644 --- a/app/models/runtime/space_quota_definition.rb +++ b/app/models/runtime/space_quota_definition.rb @@ -18,13 +18,14 @@ class SpaceQuotaDefinition < Sequel::Model export_attributes :name, :organization_guid, :non_basic_services_allowed, :total_services, :total_routes, :memory_limit, :instance_memory_limit, :app_instance_limit, :app_task_limit, - :total_service_keys, :total_reserved_route_ports + :total_service_keys, :total_reserved_route_ports, :log_limit import_attributes :name, :organization_guid, :non_basic_services_allowed, :total_services, :total_routes, :memory_limit, :instance_memory_limit, :app_instance_limit, :app_task_limit, - :total_service_keys, :total_reserved_route_ports + :total_service_keys, :total_reserved_route_ports, :log_limit add_association_dependencies spaces: :nullify + # rubocop:todo Metrics/CyclomaticComplexity def validate validates_presence :name validates_presence :non_basic_services_allowed @@ -38,9 +39,11 @@ def validate errors.add(:instance_memory_limit, :invalid_instance_memory_limit) if instance_memory_limit && instance_memory_limit < -1 errors.add(:app_instance_limit, :invalid_app_instance_limit) if app_instance_limit && app_instance_limit < UNLIMITED errors.add(:app_task_limit, :invalid_app_task_limit) if app_task_limit && app_task_limit < UNLIMITED + errors.add(:log_limit, :invalid_log_limit) if log_limit && log_limit < UNLIMITED errors.add(:total_service_keys, :invalid_total_service_keys) if total_service_keys && total_service_keys < UNLIMITED validate_total_reserved_ports end + # rubocop:enable Metrics/CyclomaticComplexity def validate_change_organization(new_org) raise CloudController::Errors::ApiError.new_from_details('OrganizationAlreadySet') unless organization.nil? || organization.guid == new_org.guid diff --git a/app/presenters/v3/space_quota_presenter.rb b/app/presenters/v3/space_quota_presenter.rb index 1c1b3ab2a8d..b4a68397604 100644 --- a/app/presenters/v3/space_quota_presenter.rb +++ b/app/presenters/v3/space_quota_presenter.rb @@ -26,6 +26,7 @@ def to_hash per_process_memory_in_mb: unlimited_to_nil(space_quota.instance_memory_limit), total_instances: unlimited_to_nil(space_quota.app_instance_limit), per_app_tasks: unlimited_to_nil(space_quota.app_task_limit), + log_limit_in_bytes_per_second: unlimited_to_nil(space_quota.log_limit), }, services: { paid_services_allowed: space_quota.non_basic_services_allowed, diff --git a/db/migrations/20220607222309_add_log_byte_quota_to_space_quota_definitions.rb b/db/migrations/20220607222309_add_log_byte_quota_to_space_quota_definitions.rb new file mode 100644 index 00000000000..d2bb89fe637 --- /dev/null +++ b/db/migrations/20220607222309_add_log_byte_quota_to_space_quota_definitions.rb @@ -0,0 +1,5 @@ +Sequel.migration do + change do + add_column :space_quota_definitions, :log_limit, :Bignum, null: false, default: -1 + end +end diff --git a/spec/request/space_quotas_spec.rb b/spec/request/space_quotas_spec.rb index 94a4643441e..9f56971ceac 100644 --- a/spec/request/space_quotas_spec.rb +++ b/spec/request/space_quotas_spec.rb @@ -88,7 +88,8 @@ module VCAP::CloudController total_memory_in_mb: 5120, per_process_memory_in_mb: 1024, total_instances: nil, - per_app_tasks: 5 + per_app_tasks: 5, + log_limit_in_bytes_per_second: 2000 }, services: { paid_services_allowed: false, @@ -112,7 +113,8 @@ module VCAP::CloudController total_memory_in_mb: 5120, per_process_memory_in_mb: 1024, total_instances: nil, - per_app_tasks: 5 + per_app_tasks: 5, + log_limit_in_bytes_per_second: 2000 }, services: { paid_services_allowed: false, @@ -208,6 +210,7 @@ module VCAP::CloudController expect(last_response).to have_status_code(200) expect(space_quota_to_update.reload.app_task_limit).to eq(9) expect(space_quota_to_update.reload.memory_limit).to eq(-1) + expect(space_quota_to_update.reload.log_limit).to eq(-1) expect(space_quota_to_update.reload.total_services).to eq(14) expect(space_quota_to_update.reload.non_basic_services_allowed).to be_falsey end @@ -219,6 +222,7 @@ module VCAP::CloudController expect(last_response).to have_status_code(200) expect(space_quota_to_update.reload.app_task_limit).to eq(9) expect(space_quota_to_update.reload.memory_limit).to eq(-1) + expect(space_quota_to_update.reload.log_limit).to eq(-1) expect(space_quota_to_update.reload.total_services).to eq(14) expect(space_quota_to_update.reload.non_basic_services_allowed).to be_falsey end @@ -406,7 +410,8 @@ module VCAP::CloudController total_memory_in_mb: nil, per_process_memory_in_mb: nil, total_instances: nil, - per_app_tasks: nil + per_app_tasks: nil, + log_limit_in_bytes_per_second: nil }, services: { paid_services_allowed: true, @@ -495,7 +500,8 @@ module VCAP::CloudController total_memory_in_mb: nil, per_process_memory_in_mb: nil, total_instances: nil, - per_app_tasks: nil + per_app_tasks: nil, + log_limit_in_bytes_per_second: nil }, services: { paid_services_allowed: true, @@ -555,7 +561,8 @@ module VCAP::CloudController total_memory_in_mb: 5120, per_process_memory_in_mb: 1024, total_instances: 10, - per_app_tasks: 5 + per_app_tasks: 5, + log_limit_in_bytes_per_second: 3000 }, services: { paid_services_allowed: false, @@ -589,7 +596,8 @@ module VCAP::CloudController total_memory_in_mb: 5120, per_process_memory_in_mb: 1024, total_instances: 10, - per_app_tasks: 5 + per_app_tasks: 5, + log_limit_in_bytes_per_second: 3000 }, services: { paid_services_allowed: false, @@ -968,7 +976,8 @@ def make_space_quota_json(space_quota, associated_spaces=space_quota.spaces) total_memory_in_mb: 20480, per_process_memory_in_mb: nil, total_instances: nil, - per_app_tasks: 5 + per_app_tasks: 5, + log_limit_in_bytes_per_second: nil }, services: { paid_services_allowed: true, diff --git a/spec/unit/actions/space_quota_update_spec.rb b/spec/unit/actions/space_quota_update_spec.rb index 86b7feae606..9da553f126e 100644 --- a/spec/unit/actions/space_quota_update_spec.rb +++ b/spec/unit/actions/space_quota_update_spec.rb @@ -23,7 +23,8 @@ module VCAP::CloudController total_memory_in_mb: 5120, per_process_memory_in_mb: 1024, total_instances: 8, - per_app_tasks: nil + per_app_tasks: nil, + log_limit_in_bytes_per_second: 2000, }, services: { paid_services_allowed: false, @@ -50,6 +51,7 @@ module VCAP::CloudController expect(updated_space_quota.instance_memory_limit).to eq(1024) expect(updated_space_quota.app_instance_limit).to eq(8) expect(updated_space_quota.app_task_limit).to eq(-1) + expect(updated_space_quota.log_limit).to eq(2000) expect(updated_space_quota.total_services).to eq(10) expect(updated_space_quota.total_service_keys).to eq(20) @@ -63,6 +65,7 @@ module VCAP::CloudController updated_space_quota = SpaceQuotaUpdate.update(space_quota, minimum_message) expect(updated_space_quota.name).to eq('space_quota_name') + expect(updated_space_quota.log_limit).to eq(-1) end context 'when a model validation fails' do diff --git a/spec/unit/actions/space_quotas_create_spec.rb b/spec/unit/actions/space_quotas_create_spec.rb index aac7774bd0a..705a39e341d 100644 --- a/spec/unit/actions/space_quotas_create_spec.rb +++ b/spec/unit/actions/space_quotas_create_spec.rb @@ -30,6 +30,7 @@ module VCAP::CloudController per_process_memory_in_mb: 6, total_instances: 7, per_app_tasks: 8, + log_limit_in_bytes_per_second: 2000, }, services: { paid_services_allowed: false, @@ -68,6 +69,7 @@ module VCAP::CloudController expect(space_quota.instance_memory_limit).to eq(-1) expect(space_quota.app_instance_limit).to eq(-1) expect(space_quota.app_task_limit).to eq(-1) + expect(space_quota.log_limit).to eq(-1) expect(space_quota.total_services).to eq(-1) expect(space_quota.total_service_keys).to eq(-1) @@ -90,6 +92,7 @@ module VCAP::CloudController expect(space_quota.instance_memory_limit).to eq(6) expect(space_quota.app_instance_limit).to eq(7) expect(space_quota.app_task_limit).to eq(8) + expect(space_quota.log_limit).to eq(2000) expect(space_quota.total_services).to eq(9) expect(space_quota.total_service_keys).to eq(10) diff --git a/spec/unit/messages/space_quota_update_message_spec.rb b/spec/unit/messages/space_quota_update_message_spec.rb index bd0cba290cf..b9b0a17293d 100644 --- a/spec/unit/messages/space_quota_update_message_spec.rb +++ b/spec/unit/messages/space_quota_update_message_spec.rb @@ -20,6 +20,7 @@ module VCAP::CloudController per_process_memory_in_mb: 1024, total_instances: 2, per_app_tasks: 4, + log_limit_in_bytes_per_second: 2000, } end @@ -49,6 +50,7 @@ module VCAP::CloudController expect(subject.per_process_memory_in_mb).to eq(1024) expect(subject.total_instances).to eq(2) expect(subject.per_app_tasks).to eq(4) + expect(subject.log_limit_in_bytes_per_second).to eq(2000) expect(subject.paid_services_allowed).to be_truthy expect(subject.total_service_instances).to eq(17) expect(subject.total_service_keys).to eq(19) diff --git a/spec/unit/models/runtime/space_quota_definition_spec.rb b/spec/unit/models/runtime/space_quota_definition_spec.rb index c5438e62fe2..4d045348d78 100644 --- a/spec/unit/models/runtime/space_quota_definition_spec.rb +++ b/spec/unit/models/runtime/space_quota_definition_spec.rb @@ -68,6 +68,17 @@ module VCAP::CloudController end end + describe 'log_limit' do + it 'cannot be less than -1' do + space_quota_definition.log_limit = -2 + expect(space_quota_definition).not_to be_valid + expect(space_quota_definition.errors.on(:log_limit)).to include(:invalid_log_limit) + + space_quota_definition.log_limit = -1 + expect(space_quota_definition).to be_valid + end + end + describe 'total_reserved_route_ports' do let(:err_msg) do 'Total reserved ports must be -1, 0, or a positive integer, must ' \ @@ -163,13 +174,13 @@ module VCAP::CloudController it do is_expected.to export_attributes :name, :organization_guid, :non_basic_services_allowed, :total_services, :total_routes, :memory_limit, :instance_memory_limit, :app_instance_limit, :app_task_limit, - :total_service_keys, :total_reserved_route_ports + :total_service_keys, :total_reserved_route_ports, :log_limit end it do is_expected.to import_attributes :name, :organization_guid, :non_basic_services_allowed, :total_services, :total_routes, :memory_limit, :instance_memory_limit, :app_instance_limit, :app_task_limit, - :total_service_keys, :total_reserved_route_ports + :total_service_keys, :total_reserved_route_ports, :log_limit end end diff --git a/spec/unit/presenters/v3/space_quota_presenter_spec.rb b/spec/unit/presenters/v3/space_quota_presenter_spec.rb index 20b3cfddac1..070826913d2 100644 --- a/spec/unit/presenters/v3/space_quota_presenter_spec.rb +++ b/spec/unit/presenters/v3/space_quota_presenter_spec.rb @@ -17,6 +17,7 @@ module VCAP::CloudController::Presenters::V3 instance_memory_limit: 3, app_instance_limit: 4, app_task_limit: 5, + log_limit: 2000, non_basic_services_allowed: false, total_services: 6, total_service_keys: 7, @@ -42,6 +43,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[:apps][:per_process_memory_in_mb]).to eq(space_quota.instance_memory_limit) expect(result[:apps][:total_instances]).to eq(space_quota.app_instance_limit) expect(result[:apps][:per_app_tasks]).to eq(space_quota.app_task_limit) + expect(result[:apps][:log_limit_in_bytes_per_second]).to eq(space_quota.log_limit) expect(result[:services][:paid_services_allowed]).to eq(space_quota.non_basic_services_allowed) expect(result[:services][:total_service_instances]).to eq(space_quota.total_services) expect(result[:services][:total_service_keys]).to eq(space_quota.total_service_keys) @@ -67,6 +69,7 @@ module VCAP::CloudController::Presenters::V3 instance_memory_limit: -1, app_instance_limit: -1, app_task_limit: -1, + log_limit: -1, total_services: -1, total_service_keys: -1, total_routes: -1, @@ -79,6 +82,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[:apps][:per_process_memory_in_mb]).to be_nil expect(result[:apps][:total_instances]).to be_nil expect(result[:apps][:per_app_tasks]).to be_nil + expect(result[:apps][:log_limit_in_bytes_per_second]).to be_nil expect(result[:services][:total_service_instances]).to be_nil expect(result[:services][:total_service_keys]).to be_nil expect(result[:routes][:total_routes]).to be_nil