From f7d8d6ca9dd69fb9d5bd954f9c6b0a7c0c11602c Mon Sep 17 00:00:00 2001 From: Tim Downey Date: Wed, 26 Mar 2025 15:37:29 -0600 Subject: [PATCH 1/2] Add instance_id field in Process Stats response - Display the Diego instance identifier as part of the Process Stats response. This id is unique for each actual LRP instance and can be used as a substitute for the integer index id. - Issue: #2819 --- app/presenters/v3/process_stats_presenter.rb | 1 + docs/v3/source/includes/api_resources/_processes.erb | 1 + .../includes/resources/processes/_stats_object.md.erb | 1 + .../diego/reporters/instances_stats_reporter.rb | 1 + spec/request/processes_spec.rb | 2 ++ .../diego/reporters/instances_stats_reporter_spec.rb | 4 ++++ spec/unit/presenters/v3/process_stats_presenter_spec.rb | 9 +++++++++ 7 files changed, 19 insertions(+) diff --git a/app/presenters/v3/process_stats_presenter.rb b/app/presenters/v3/process_stats_presenter.rb index 574d39c7386..67cd3207e77 100644 --- a/app/presenters/v3/process_stats_presenter.rb +++ b/app/presenters/v3/process_stats_presenter.rb @@ -34,6 +34,7 @@ def found_instance_stats_hash(index, stats) { type: @type, index: index, + instance_id: stats[:stats][:instance_id], state: stats[:state], routable: stats[:routable], host: stats[:stats][:host], diff --git a/docs/v3/source/includes/api_resources/_processes.erb b/docs/v3/source/includes/api_resources/_processes.erb index c59e0953ea6..7fb2a9f6994 100644 --- a/docs/v3/source/includes/api_resources/_processes.erb +++ b/docs/v3/source/includes/api_resources/_processes.erb @@ -204,6 +204,7 @@ { "type": "web", "index": 0, + "instance_id": "e49f448e-54d2-4c33-61a3-5335", "state": "RUNNING", "usage": { "time": "2016-03-23T23:17:30.476314154Z", diff --git a/docs/v3/source/includes/resources/processes/_stats_object.md.erb b/docs/v3/source/includes/resources/processes/_stats_object.md.erb index 6a98ba5c207..51b692c7047 100644 --- a/docs/v3/source/includes/resources/processes/_stats_object.md.erb +++ b/docs/v3/source/includes/resources/processes/_stats_object.md.erb @@ -13,6 +13,7 @@ Name | Type | Description ---- | ---- | ----------- **type** | _string_ | Process type; a unique identifier for processes belonging to an app **index** | _integer_ | The zero-based index of running instances +**instance_id** | _string_ | The unique identifier of the instance **state** | _string_ | The state of the instance; valid values are `RUNNING`, `CRASHED`, `STARTING`, `STOPPING`, `DOWN` **routable** | _boolean_ | Whether or not the instance is routable (determined by the readiness check of the app). If app readiness checks and routability are unsupported by Diego, this will return as `null`. **usage** | _object_ | Object containing actual usage data for the instance; the value is `{}` when usage data is unavailable diff --git a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb index ca45cd3b9c1..e52722a0484 100644 --- a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb +++ b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb @@ -68,6 +68,7 @@ def build_info(state, actual_lrp, process, stats, quota_stats, log_cache_errors) name: process.name, uris: process.uris, host: actual_lrp.actual_lrp_net_info.address, + instance_id: actual_lrp.actual_lrp_instance_key.instance_guid, port: get_default_port(actual_lrp.actual_lrp_net_info), net_info: actual_lrp.actual_lrp_net_info.to_h, uptime: nanoseconds_to_seconds((Time.now.to_f * 1e9) - actual_lrp.since), diff --git a/spec/request/processes_spec.rb b/spec/request/processes_spec.rb index 8b9a0308d77..4d4e93080c8 100644 --- a/spec/request/processes_spec.rb +++ b/spec/request/processes_spec.rb @@ -528,6 +528,7 @@ name: process.name, uris: process.uris, host: 'toast', + instance_id: 'some-diego-instance-id', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -556,6 +557,7 @@ 'type' => 'worker', 'index' => 0, 'state' => 'RUNNING', + 'instance_id' => 'some-diego-instance-id', 'routable' => true, 'isolation_segment' => 'very-isolated', 'details' => 'some-details', 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 ee5d2dbaad0..7b7185ffe1a 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 @@ -88,6 +88,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', + instance_id: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, @@ -159,6 +160,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', + instance_id: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, @@ -459,6 +461,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', + instance_id: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, @@ -592,6 +595,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', + instance_id: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, diff --git a/spec/unit/presenters/v3/process_stats_presenter_spec.rb b/spec/unit/presenters/v3/process_stats_presenter_spec.rb index 66d136774da..122ded0381e 100644 --- a/spec/unit/presenters/v3/process_stats_presenter_spec.rb +++ b/spec/unit/presenters/v3/process_stats_presenter_spec.rb @@ -65,6 +65,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', + instance_id: 'instance-a', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -89,6 +90,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'toast', + instance_id: 'instance-b', net_info: net_info_2, uptime: 42, mem_quota: process[:memory] * 1024 * 1024, @@ -122,6 +124,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[0][:type]).to eq(process.type) expect(result[0][:index]).to eq(0) expect(result[0][:state]).to eq('RUNNING') + expect(result[0][:instance_id]).to eq('instance-a') expect(result[0][:routable]).to be(true) expect(result[0][:details]).to be_nil expect(result[0][:isolation_segment]).to eq('hecka-compliant') @@ -143,6 +146,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[1][:type]).to eq(process.type) expect(result[1][:index]).to eq(1) expect(result[1][:state]).to eq('CRASHED') + expect(result[1][:instance_id]).to eq('instance-b') expect(result[1][:routable]).to be(false) expect(result[1][:details]).to eq('some-details') expect(result[1][:isolation_segment]).to be_nil @@ -178,6 +182,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', + instance_id: 'instance-a', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -217,6 +222,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', + instance_id: 'instance-a', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -286,6 +292,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[0][:details]).to be_nil expect(result[0][:isolation_segment]).to eq('hecka-compliant') expect(result[0][:host]).to eq('myhost') + expect(result[0][:instance_id]).to eq('instance-a') expect(result[0][:instance_internal_ip]).to eq('5.6.7.8') expect(result[0][:instance_ports]).to eq(instance_ports_1) expect(result[0][:uptime]).to eq(12_345) @@ -312,6 +319,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', + instance_id: 'instance-a', net_info: net_info_1, uptime: 12_345, fds_quota: process.file_descriptors, @@ -330,6 +338,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[0][:details]).to be_nil expect(result[0][:isolation_segment]).to eq('hecka-compliant') expect(result[0][:host]).to eq('myhost') + expect(result[0][:instance_id]).to eq('instance-a') expect(result[0][:instance_internal_ip]).to eq('5.6.7.8') expect(result[0][:instance_ports]).to eq(instance_ports_1) expect(result[0][:uptime]).to eq(12_345) From 1a39571d0030b12f5996dad58e21e1ee6cab1661 Mon Sep 17 00:00:00 2001 From: Tim Downey Date: Wed, 26 Mar 2025 15:46:34 -0600 Subject: [PATCH 2/2] Rename Process stats instance_id to instance_guid --- app/presenters/v3/process_stats_presenter.rb | 2 +- .../includes/api_resources/_processes.erb | 2 +- .../resources/processes/_stats_object.md.erb | 2 +- .../reporters/instances_stats_reporter.rb | 2 +- spec/request/processes_spec.rb | 4 ++-- .../reporters/instances_stats_reporter_spec.rb | 9 +++++---- .../v3/process_stats_presenter_spec.rb | 18 +++++++++--------- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/presenters/v3/process_stats_presenter.rb b/app/presenters/v3/process_stats_presenter.rb index 67cd3207e77..e882516bff8 100644 --- a/app/presenters/v3/process_stats_presenter.rb +++ b/app/presenters/v3/process_stats_presenter.rb @@ -34,7 +34,7 @@ def found_instance_stats_hash(index, stats) { type: @type, index: index, - instance_id: stats[:stats][:instance_id], + instance_guid: stats[:stats][:instance_guid], state: stats[:state], routable: stats[:routable], host: stats[:stats][:host], diff --git a/docs/v3/source/includes/api_resources/_processes.erb b/docs/v3/source/includes/api_resources/_processes.erb index 7fb2a9f6994..f730a5bf967 100644 --- a/docs/v3/source/includes/api_resources/_processes.erb +++ b/docs/v3/source/includes/api_resources/_processes.erb @@ -204,7 +204,7 @@ { "type": "web", "index": 0, - "instance_id": "e49f448e-54d2-4c33-61a3-5335", + "instance_guid": "e49f448e-54d2-4c33-61a3-5335", "state": "RUNNING", "usage": { "time": "2016-03-23T23:17:30.476314154Z", diff --git a/docs/v3/source/includes/resources/processes/_stats_object.md.erb b/docs/v3/source/includes/resources/processes/_stats_object.md.erb index 51b692c7047..667b30274d3 100644 --- a/docs/v3/source/includes/resources/processes/_stats_object.md.erb +++ b/docs/v3/source/includes/resources/processes/_stats_object.md.erb @@ -13,7 +13,7 @@ Name | Type | Description ---- | ---- | ----------- **type** | _string_ | Process type; a unique identifier for processes belonging to an app **index** | _integer_ | The zero-based index of running instances -**instance_id** | _string_ | The unique identifier of the instance +**instance_guid** | _string_ | The unique identifier of the instance **state** | _string_ | The state of the instance; valid values are `RUNNING`, `CRASHED`, `STARTING`, `STOPPING`, `DOWN` **routable** | _boolean_ | Whether or not the instance is routable (determined by the readiness check of the app). If app readiness checks and routability are unsupported by Diego, this will return as `null`. **usage** | _object_ | Object containing actual usage data for the instance; the value is `{}` when usage data is unavailable diff --git a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb index e52722a0484..164de7aa749 100644 --- a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb +++ b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb @@ -68,7 +68,7 @@ def build_info(state, actual_lrp, process, stats, quota_stats, log_cache_errors) name: process.name, uris: process.uris, host: actual_lrp.actual_lrp_net_info.address, - instance_id: actual_lrp.actual_lrp_instance_key.instance_guid, + instance_guid: actual_lrp.actual_lrp_instance_key.instance_guid, port: get_default_port(actual_lrp.actual_lrp_net_info), net_info: actual_lrp.actual_lrp_net_info.to_h, uptime: nanoseconds_to_seconds((Time.now.to_f * 1e9) - actual_lrp.since), diff --git a/spec/request/processes_spec.rb b/spec/request/processes_spec.rb index 4d4e93080c8..3bfb6365dbb 100644 --- a/spec/request/processes_spec.rb +++ b/spec/request/processes_spec.rb @@ -528,7 +528,7 @@ name: process.name, uris: process.uris, host: 'toast', - instance_id: 'some-diego-instance-id', + instance_guid: 'some-diego-instance-id', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -557,7 +557,7 @@ 'type' => 'worker', 'index' => 0, 'state' => 'RUNNING', - 'instance_id' => 'some-diego-instance-id', + 'instance_guid' => 'some-diego-instance-id', 'routable' => true, 'isolation_segment' => 'very-isolated', 'details' => 'some-details', 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 7b7185ffe1a..2775cdc094d 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 @@ -88,7 +88,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', - instance_id: 'instance-a', + instance_guid: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, @@ -160,7 +160,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', - instance_id: 'instance-a', + instance_guid: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, @@ -215,6 +215,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', + instance_guid: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, @@ -461,7 +462,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', - instance_id: 'instance-a', + instance_guid: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, @@ -595,7 +596,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) name: process.name, uris: process.uris, host: 'lrp-host', - instance_id: 'instance-a', + instance_guid: 'instance-a', port: 2222, net_info: lrp_1_net_info.to_h, uptime: two_days_in_seconds, diff --git a/spec/unit/presenters/v3/process_stats_presenter_spec.rb b/spec/unit/presenters/v3/process_stats_presenter_spec.rb index 122ded0381e..f35bcd665b5 100644 --- a/spec/unit/presenters/v3/process_stats_presenter_spec.rb +++ b/spec/unit/presenters/v3/process_stats_presenter_spec.rb @@ -65,7 +65,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', - instance_id: 'instance-a', + instance_guid: 'instance-a', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -90,7 +90,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'toast', - instance_id: 'instance-b', + instance_guid: 'instance-b', net_info: net_info_2, uptime: 42, mem_quota: process[:memory] * 1024 * 1024, @@ -124,7 +124,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[0][:type]).to eq(process.type) expect(result[0][:index]).to eq(0) expect(result[0][:state]).to eq('RUNNING') - expect(result[0][:instance_id]).to eq('instance-a') + expect(result[0][:instance_guid]).to eq('instance-a') expect(result[0][:routable]).to be(true) expect(result[0][:details]).to be_nil expect(result[0][:isolation_segment]).to eq('hecka-compliant') @@ -146,7 +146,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[1][:type]).to eq(process.type) expect(result[1][:index]).to eq(1) expect(result[1][:state]).to eq('CRASHED') - expect(result[1][:instance_id]).to eq('instance-b') + expect(result[1][:instance_guid]).to eq('instance-b') expect(result[1][:routable]).to be(false) expect(result[1][:details]).to eq('some-details') expect(result[1][:isolation_segment]).to be_nil @@ -182,7 +182,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', - instance_id: 'instance-a', + instance_guid: 'instance-a', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -222,7 +222,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', - instance_id: 'instance-a', + instance_guid: 'instance-a', net_info: net_info_1, uptime: 12_345, mem_quota: process[:memory] * 1024 * 1024, @@ -292,7 +292,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[0][:details]).to be_nil expect(result[0][:isolation_segment]).to eq('hecka-compliant') expect(result[0][:host]).to eq('myhost') - expect(result[0][:instance_id]).to eq('instance-a') + expect(result[0][:instance_guid]).to eq('instance-a') expect(result[0][:instance_internal_ip]).to eq('5.6.7.8') expect(result[0][:instance_ports]).to eq(instance_ports_1) expect(result[0][:uptime]).to eq(12_345) @@ -319,7 +319,7 @@ module VCAP::CloudController::Presenters::V3 name: process.name, uris: process.uris, host: 'myhost', - instance_id: 'instance-a', + instance_guid: 'instance-a', net_info: net_info_1, uptime: 12_345, fds_quota: process.file_descriptors, @@ -338,7 +338,7 @@ module VCAP::CloudController::Presenters::V3 expect(result[0][:details]).to be_nil expect(result[0][:isolation_segment]).to eq('hecka-compliant') expect(result[0][:host]).to eq('myhost') - expect(result[0][:instance_id]).to eq('instance-a') + expect(result[0][:instance_guid]).to eq('instance-a') expect(result[0][:instance_internal_ip]).to eq('5.6.7.8') expect(result[0][:instance_ports]).to eq(instance_ports_1) expect(result[0][:uptime]).to eq(12_345)