Skip to content

Commit f50766e

Browse files
authored
Add instance_guid field in Process Stats response (#2831)
* Add instance_guid 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
1 parent 04c46ec commit f50766e

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

app/presenters/v3/process_stats_presenter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def found_instance_stats_hash(index, stats)
3434
{
3535
type: @type,
3636
index: index,
37+
instance_guid: stats[:stats][:instance_guid],
3738
state: stats[:state],
3839
routable: stats[:routable],
3940
host: stats[:stats][:host],

docs/v3/source/includes/api_resources/_processes.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
{
205205
"type": "web",
206206
"index": 0,
207+
"instance_guid": "e49f448e-54d2-4c33-61a3-5335",
207208
"state": "RUNNING",
208209
"usage": {
209210
"time": "2016-03-23T23:17:30.476314154Z",

docs/v3/source/includes/resources/processes/_stats_object.md.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Name | Type | Description
1313
---- | ---- | -----------
1414
**type** | _string_ | Process type; a unique identifier for processes belonging to an app
1515
**index** | _integer_ | The zero-based index of running instances
16+
**instance_guid** | _string_ | The unique identifier of the instance
1617
**state** | _string_ | The state of the instance; valid values are `RUNNING`, `CRASHED`, `STARTING`, `STOPPING`, `DOWN`
1718
**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`.
1819
**usage** | _object_ | Object containing actual usage data for the instance; the value is `{}` when usage data is unavailable

lib/cloud_controller/diego/reporters/instances_stats_reporter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def build_info(state, actual_lrp, process, stats, quota_stats, log_cache_errors)
6868
name: process.name,
6969
uris: process.uris,
7070
host: actual_lrp.actual_lrp_net_info.address,
71+
instance_guid: actual_lrp.actual_lrp_instance_key.instance_guid,
7172
port: get_default_port(actual_lrp.actual_lrp_net_info),
7273
net_info: actual_lrp.actual_lrp_net_info.to_h,
7374
uptime: nanoseconds_to_seconds((Time.now.to_f * 1e9) - actual_lrp.since),

spec/request/processes_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@
528528
name: process.name,
529529
uris: process.uris,
530530
host: 'toast',
531+
instance_guid: 'some-diego-instance-id',
531532
net_info: net_info_1,
532533
uptime: 12_345,
533534
mem_quota: process[:memory] * 1024 * 1024,
@@ -556,6 +557,7 @@
556557
'type' => 'worker',
557558
'index' => 0,
558559
'state' => 'RUNNING',
560+
'instance_guid' => 'some-diego-instance-id',
559561
'routable' => true,
560562
'isolation_segment' => 'very-isolated',
561563
'details' => 'some-details',

spec/unit/lib/cloud_controller/diego/reporters/instances_stats_reporter_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
8888
name: process.name,
8989
uris: process.uris,
9090
host: 'lrp-host',
91+
instance_guid: 'instance-a',
9192
port: 2222,
9293
net_info: lrp_1_net_info.to_h,
9394
uptime: two_days_in_seconds,
@@ -159,6 +160,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
159160
name: process.name,
160161
uris: process.uris,
161162
host: 'lrp-host',
163+
instance_guid: 'instance-a',
162164
port: 2222,
163165
net_info: lrp_1_net_info.to_h,
164166
uptime: two_days_in_seconds,
@@ -213,6 +215,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
213215
name: process.name,
214216
uris: process.uris,
215217
host: 'lrp-host',
218+
instance_guid: 'instance-a',
216219
port: 2222,
217220
net_info: lrp_1_net_info.to_h,
218221
uptime: two_days_in_seconds,
@@ -459,6 +462,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
459462
name: process.name,
460463
uris: process.uris,
461464
host: 'lrp-host',
465+
instance_guid: 'instance-a',
462466
port: 2222,
463467
net_info: lrp_1_net_info.to_h,
464468
uptime: two_days_in_seconds,
@@ -592,6 +596,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
592596
name: process.name,
593597
uris: process.uris,
594598
host: 'lrp-host',
599+
instance_guid: 'instance-a',
595600
port: 2222,
596601
net_info: lrp_1_net_info.to_h,
597602
uptime: two_days_in_seconds,

spec/unit/presenters/v3/process_stats_presenter_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module VCAP::CloudController::Presenters::V3
6565
name: process.name,
6666
uris: process.uris,
6767
host: 'myhost',
68+
instance_guid: 'instance-a',
6869
net_info: net_info_1,
6970
uptime: 12_345,
7071
mem_quota: process[:memory] * 1024 * 1024,
@@ -89,6 +90,7 @@ module VCAP::CloudController::Presenters::V3
8990
name: process.name,
9091
uris: process.uris,
9192
host: 'toast',
93+
instance_guid: 'instance-b',
9294
net_info: net_info_2,
9395
uptime: 42,
9496
mem_quota: process[:memory] * 1024 * 1024,
@@ -122,6 +124,7 @@ module VCAP::CloudController::Presenters::V3
122124
expect(result[0][:type]).to eq(process.type)
123125
expect(result[0][:index]).to eq(0)
124126
expect(result[0][:state]).to eq('RUNNING')
127+
expect(result[0][:instance_guid]).to eq('instance-a')
125128
expect(result[0][:routable]).to be(true)
126129
expect(result[0][:details]).to be_nil
127130
expect(result[0][:isolation_segment]).to eq('hecka-compliant')
@@ -143,6 +146,7 @@ module VCAP::CloudController::Presenters::V3
143146
expect(result[1][:type]).to eq(process.type)
144147
expect(result[1][:index]).to eq(1)
145148
expect(result[1][:state]).to eq('CRASHED')
149+
expect(result[1][:instance_guid]).to eq('instance-b')
146150
expect(result[1][:routable]).to be(false)
147151
expect(result[1][:details]).to eq('some-details')
148152
expect(result[1][:isolation_segment]).to be_nil
@@ -178,6 +182,7 @@ module VCAP::CloudController::Presenters::V3
178182
name: process.name,
179183
uris: process.uris,
180184
host: 'myhost',
185+
instance_guid: 'instance-a',
181186
net_info: net_info_1,
182187
uptime: 12_345,
183188
mem_quota: process[:memory] * 1024 * 1024,
@@ -217,6 +222,7 @@ module VCAP::CloudController::Presenters::V3
217222
name: process.name,
218223
uris: process.uris,
219224
host: 'myhost',
225+
instance_guid: 'instance-a',
220226
net_info: net_info_1,
221227
uptime: 12_345,
222228
mem_quota: process[:memory] * 1024 * 1024,
@@ -286,6 +292,7 @@ module VCAP::CloudController::Presenters::V3
286292
expect(result[0][:details]).to be_nil
287293
expect(result[0][:isolation_segment]).to eq('hecka-compliant')
288294
expect(result[0][:host]).to eq('myhost')
295+
expect(result[0][:instance_guid]).to eq('instance-a')
289296
expect(result[0][:instance_internal_ip]).to eq('5.6.7.8')
290297
expect(result[0][:instance_ports]).to eq(instance_ports_1)
291298
expect(result[0][:uptime]).to eq(12_345)
@@ -312,6 +319,7 @@ module VCAP::CloudController::Presenters::V3
312319
name: process.name,
313320
uris: process.uris,
314321
host: 'myhost',
322+
instance_guid: 'instance-a',
315323
net_info: net_info_1,
316324
uptime: 12_345,
317325
fds_quota: process.file_descriptors,
@@ -330,6 +338,7 @@ module VCAP::CloudController::Presenters::V3
330338
expect(result[0][:details]).to be_nil
331339
expect(result[0][:isolation_segment]).to eq('hecka-compliant')
332340
expect(result[0][:host]).to eq('myhost')
341+
expect(result[0][:instance_guid]).to eq('instance-a')
333342
expect(result[0][:instance_internal_ip]).to eq('5.6.7.8')
334343
expect(result[0][:instance_ports]).to eq(instance_ports_1)
335344
expect(result[0][:uptime]).to eq(12_345)

0 commit comments

Comments
 (0)