Skip to content

Commit

Permalink
[API] client can see memory and disk quota used for builds
Browse files Browse the repository at this point in the history
#2204

Co-authored-by: Sarah Weinstein <sweinstein@pivotal.io>
Co-authored-by: Teal Stannard <tstannard@pivotal.io>
  • Loading branch information
sweinstein22 and Teal Stannard committed Jun 9, 2021
1 parent 9591e85 commit de64aaf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/actions/build_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def create_and_stage(package:, lifecycle:, metadata: nil, start_after_staging: f
state: BuildModel::STAGING_STATE,
package_guid: package.guid,
app: package.app,
staging_memory_in_mb: staging_details.staging_memory_in_mb,
staging_disk_in_mb: staging_details.staging_disk_in_mb,
created_by_user_guid: @user_audit_info.user_guid,
created_by_user_name: @user_audit_info.user_name,
created_by_user_email: @user_audit_info.user_email
Expand Down
2 changes: 2 additions & 0 deletions app/presenters/v3/build_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def to_hash
created_at: build.created_at,
updated_at: build.updated_at,
state: build.state,
staging_memory_in_mb: build.staging_memory_in_mb,
staging_disk_in_mb: build.staging_disk_in_mb,
error: error,
lifecycle: {
type: build.lifecycle_type,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Sequel.migration do
change do
alter_table :builds do
add_column :staging_memory_in_mb, Integer, default: nil
add_column :staging_disk_in_mb, Integer, default: nil
end
end
end
18 changes: 16 additions & 2 deletions spec/request/builds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
'created_at' => iso8601,
'updated_at' => iso8601,
'state' => 'STAGING',
'staging_memory_in_mb' => 42,
'staging_disk_in_mb' => 42,
'metadata' => { 'labels' => { 'release' => 'stable', 'seriouseats.com/potato' => 'mashed' }, 'annotations' => { 'potato' => 'idaho' } },
'error' => nil,
'lifecycle' => {
Expand Down Expand Up @@ -292,7 +294,9 @@
app: app_model,
created_by_user_name: 'bob the builder',
created_by_user_guid: developer.guid,
created_by_user_email: 'bob@loblaw.com'
created_by_user_email: 'bob@loblaw.com',
staging_memory_in_mb: 123,
staging_disk_in_mb: 456,
)
end
let!(:second_build) do
Expand All @@ -302,7 +306,9 @@
created_at: build.created_at - 1.day,
created_by_user_name: 'bob the builder',
created_by_user_guid: developer.guid,
created_by_user_email: 'bob@loblaw.com'
created_by_user_email: 'bob@loblaw.com',
staging_memory_in_mb: 789,
staging_disk_in_mb: 12
)
end
let(:package) { VCAP::CloudController::PackageModel.make(app_guid: app_model.guid) }
Expand Down Expand Up @@ -391,6 +397,8 @@
'created_at' => iso8601,
'updated_at' => iso8601,
'state' => 'STAGED',
'staging_memory_in_mb' => 123,
'staging_disk_in_mb' => 456,
'error' => nil,
'lifecycle' => {
'type' => 'buildpack',
Expand All @@ -417,6 +425,8 @@
'created_at' => iso8601,
'updated_at' => iso8601,
'state' => 'STAGED',
'staging_memory_in_mb' => 789,
'staging_disk_in_mb' => 12,
'error' => nil,
'lifecycle' => {
'type' => 'buildpack',
Expand Down Expand Up @@ -476,6 +486,8 @@
VCAP::CloudController::BuildModel.make(
package: package,
app: app_model,
staging_memory_in_mb: 123,
staging_disk_in_mb: 456,
created_by_user_name: 'bob the builder',
created_by_user_guid: developer.guid,
created_by_user_email: 'bob@loblaw.com'
Expand Down Expand Up @@ -510,6 +522,8 @@
'created_at' => iso8601,
'updated_at' => iso8601,
'state' => 'STAGED',
'staging_memory_in_mb' => 123,
'staging_disk_in_mb' => 456,
'error' => nil,
'lifecycle' => {
'type' => 'buildpack',
Expand Down
16 changes: 13 additions & 3 deletions spec/unit/actions/build_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ module VCAP::CloudController
expect(build.state).to eq(BuildModel::STAGING_STATE)
expect(build.app_guid).to eq(app.guid)
expect(build.package_guid).to eq(package.guid)
expect(build.staging_memory_in_mb).to eq(calculated_mem_limit)
expect(build.staging_disk_in_mb).to eq(calculated_staging_disk_in_mb)
expect(build.lifecycle_data.to_hash).to eq(lifecycle_data)
expect(build.created_by_user_guid).to eq('1234')
expect(build.created_by_user_name).to eq('charles')
Expand Down Expand Up @@ -181,22 +183,30 @@ module VCAP::CloudController
end

context 'when staging memory is not specified in the message' do
before do
allow(memory_limit_calculator).to receive(:get_limit).with(process.memory, space, org).and_return(process.memory)
end
let(:staging_memory_in_mb) { nil }

it 'uses the app web process memory for staging memory' do
expect(memory_limit_calculator).to receive(:get_limit).with(process.memory, space, org)

action.create_and_stage(package: package, lifecycle: lifecycle)
build = action.create_and_stage(package: package, lifecycle: lifecycle)
expect(build.staging_memory_in_mb).to eq(process.memory)
end
end

context 'when staging disk is not specified in the message' do
let(:staging_disk_in_mb) { nil }

before do
allow(disk_limit_calculator).to receive(:get_limit).with(process.disk_quota).and_return(process.disk_quota)
end

it 'uses the app web process disk for staging disk' do
expect(disk_limit_calculator).to receive(:get_limit).with(process.disk_quota)

action.create_and_stage(package: package, lifecycle: lifecycle)
build = action.create_and_stage(package: package, lifecycle: lifecycle)
expect(build.staging_disk_in_mb).to eq(process.disk_quota)
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/unit/presenters/v3/build_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module VCAP::CloudController::Presenters::V3
state: VCAP::CloudController::BuildModel::STAGING_STATE,
package: package,
app: app,
staging_memory_in_mb: 1024,
staging_disk_in_mb: 1024,
created_by_user_guid: 'happy user guid',
created_by_user_name: 'happier user name',
created_by_user_email: 'this user emailed in'
Expand Down Expand Up @@ -42,6 +44,9 @@ module VCAP::CloudController::Presenters::V3
expect(result[:package][:guid]).to eq(package.guid)
expect(result[:droplet]).to eq(nil)

expect(result[:staging_memory_in_mb]).to eq(1024)
expect(result[:staging_disk_in_mb]).to eq(1024)

expect(result[:created_at]).to be_a(Time)
expect(result[:updated_at]).to be_a(Time)
expect(result[:relationships][:app][:data][:guid]).to eq(app.guid)
Expand Down

0 comments on commit de64aaf

Please sign in to comment.