Skip to content

Commit

Permalink
Process stats presenter includes cpu_entitlement
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Kocher <[email protected]>
  • Loading branch information
mkocher authored and sethboyles committed Feb 21, 2024
1 parent 3d2bc76 commit 6aa1082
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/presenters/v3/process_stats_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def add_usage_info(presented_stats, stats)
{
time: stats[:stats][:usage][:time],
cpu: stats[:stats][:usage][:cpu],
cpu_entitlement: stats[:stats][:usage][:cpu_entitlement],
mem: stats[:stats][:usage][:mem],
disk: stats[:stats][:usage][:disk],
log_rate: stats[:stats][:usage][:log_rate]
Expand Down
21 changes: 19 additions & 2 deletions spec/request/processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@
fds_quota: process.file_descriptors,
usage: {
time: usage_time,
cpu: 80,
cpu: 0.8,
cpu_entitlement: 0.1,
mem: 128,
disk: 1024,
log_rate: 1024
Expand All @@ -560,7 +561,8 @@
'details' => 'some-details',
'usage' => {
'time' => usage_time,
'cpu' => 80,
'cpu' => 0.8,
'cpu_entitlement' => 0.1,
'mem' => 128,
'disk' => 1024,
'log_rate' => 1024
Expand Down Expand Up @@ -606,6 +608,21 @@
expect(parsed_response).to be_a_response_like(expected_response)
end
end

context 'cpu entitlement usage is not available' do
before do
stats_for_process[0][:stats][:usage][:cpu_entitlement] = nil
end

it 'returns cpu entitlement as null' do
get "/v3/processes/#{process.guid}/stats", nil, developer_headers

parsed_response = MultiJson.load(last_response.body)

expect(last_response.status).to eq(200)
expect(parsed_response['resources'][0]['usage']['cpu_entitlement']).to be_nil
end
end
end

describe 'GET /v3/apps/:guid/processes/:type/stats' do
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/presenters/v3/process_stats_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module VCAP::CloudController::Presenters::V3
usage: {
time: '2015-12-08 16:54:48 -0800',
cpu: 80,
cpu_entitlement: 85,
mem: 128,
disk: 1024,
log_rate: 2048
Expand All @@ -97,6 +98,7 @@ module VCAP::CloudController::Presenters::V3
usage: {
time: '2015-03-13 16:54:48 -0800',
cpu: 70,
cpu_entitlement: 75,
mem: 128,
disk: 1024,
log_rate: 7168
Expand Down Expand Up @@ -133,6 +135,7 @@ module VCAP::CloudController::Presenters::V3
expect(result[0][:fds_quota]).to eq(process.file_descriptors)
expect(result[0][:usage]).to eq({ time: '2015-12-08 16:54:48 -0800',
cpu: 80,
cpu_entitlement: 85,
mem: 128,
disk: 1024,
log_rate: 2048 })
Expand All @@ -148,6 +151,7 @@ module VCAP::CloudController::Presenters::V3
expect(result[1][:uptime]).to eq(42)
expect(result[1][:usage]).to eq({ time: '2015-03-13 16:54:48 -0800',
cpu: 70,
cpu_entitlement: 75,
mem: 128,
disk: 1024,
log_rate: 7168 })
Expand Down Expand Up @@ -183,6 +187,7 @@ module VCAP::CloudController::Presenters::V3
usage: {
time: '2015-12-08 16:54:48 -0800',
cpu: 80,
cpu_entitlement: 85,
mem: 128,
disk: 1024,
log_rate: 2048
Expand Down Expand Up @@ -221,6 +226,7 @@ module VCAP::CloudController::Presenters::V3
usage: {
time: '2015-12-08 16:54:48 -0800',
cpu: 80,
cpu_entitlement: 85,
mem: 128,
disk: 1024,
log_rate: 2048
Expand Down Expand Up @@ -289,6 +295,7 @@ module VCAP::CloudController::Presenters::V3
expect(result[0][:fds_quota]).to eq(process.file_descriptors)
expect(result[0][:usage]).to eq({ time: '2015-12-08 16:54:48 -0800',
cpu: 80,
cpu_entitlement: 85,
mem: 128,
disk: 1024,
log_rate: 2048 })
Expand Down

0 comments on commit 6aa1082

Please sign in to comment.