From 725f8648959dde781b7e396f504d7188fd4a0133 Mon Sep 17 00:00:00 2001 From: Andrew Crump Date: Wed, 19 Jun 2024 20:28:00 +0000 Subject: [PATCH] fix: CPU Entitlement is zero when stats are missing - In #3641 we exposed CPU Entitlement in process stats and returned null when stats are not yet available in Log Cache. - Change missing process stats to instead have CPU Entitlement of zero for consistency with other existing metrics. Recent versions of the cf CLI will show zero rather than an empty column for CPU Entitlement. - CPU Entitlement may still be null when the metric is not available on the deployment. Signed-off-by: Andrew Costa --- docs/v3/source/includes/api_resources/_processes.erb | 2 +- .../diego/reporters/instances_stats_reporter.rb | 2 +- .../diego/reporters/instances_stats_reporter_spec.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/v3/source/includes/api_resources/_processes.erb b/docs/v3/source/includes/api_resources/_processes.erb index 2b07611bf86..c59e0953ea6 100644 --- a/docs/v3/source/includes/api_resources/_processes.erb +++ b/docs/v3/source/includes/api_resources/_processes.erb @@ -237,7 +237,7 @@ "state": "STARTING", "usage": { "cpu": 0, - "cpu_entitlement": null, + "cpu_entitlement": 0, "disk": 0, "log_rate": 0, "mem": 0, diff --git a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb index 0dc66010942..0194963d423 100644 --- a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb +++ b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb @@ -88,7 +88,7 @@ def missing_process_stats(formatted_current_time) { time: formatted_current_time, cpu: 0, - cpu_entitlement: nil, + cpu_entitlement: 0, mem: 0, disk: 0, log_rate: 0 diff --git a/spec/unit/lib/cloud_controller/diego/reporters/instances_stats_reporter_spec.rb b/spec/unit/lib/cloud_controller/diego/reporters/instances_stats_reporter_spec.rb index 747cdf35b60..8532e238b7c 100644 --- a/spec/unit/lib/cloud_controller/diego/reporters/instances_stats_reporter_spec.rb +++ b/spec/unit/lib/cloud_controller/diego/reporters/instances_stats_reporter_spec.rb @@ -241,12 +241,12 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) [container_metric_batch] end - it 'sets all the stats to their nullish value' do + it 'sets all the stats to zero' do result, = instances_reporter.stats_for_app(process) expect(result[0][:stats][:usage]).to eq({ time: formatted_current_time, cpu: 0, - cpu_entitlement: nil, + cpu_entitlement: 0, mem: 0, disk: 0, log_rate: 0 @@ -378,7 +378,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) expect(result[0][:stats][:usage]).to eq({ time: formatted_current_time, cpu: 0, - cpu_entitlement: nil, + cpu_entitlement: 0, mem: 0, disk: 0, log_rate: 0