Skip to content

Commit f701464

Browse files
committed
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. - Eirini does not support this in their API at this time, so the OPI variant of the instances stats reporter returns an empty string for this field. In the future, if Eirini is enhanced to provide this we can update that client. - Issue: #2819 Authored-by: Tim Downey <tdowney@vmware.com>
1 parent 7542f1d commit f701464

File tree

9 files changed

+36
-11
lines changed

9 files changed

+36
-11
lines changed

app/presenters/v3/process_stats_presenter.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ def instance_stats_hash(index, stats)
3232

3333
def found_instance_stats_hash(index, stats)
3434
{
35-
type: @type,
36-
index: index,
37-
state: stats[:state],
38-
host: stats[:stats][:host],
39-
uptime: stats[:stats][:uptime],
40-
mem_quota: stats[:stats][:mem_quota],
41-
disk_quota: stats[:stats][:disk_quota],
42-
fds_quota: stats[:stats][:fds_quota],
35+
type: @type,
36+
index: index,
37+
instance_id: stats[:stats][:instance_id],
38+
state: stats[:state],
39+
host: stats[:stats][:host],
40+
uptime: stats[:stats][:uptime],
41+
mem_quota: stats[:stats][:mem_quota],
42+
disk_quota: stats[:stats][:disk_quota],
43+
fds_quota: stats[:stats][:fds_quota],
4344
isolation_segment: stats[:isolation_segment],
4445
details: stats[:details]
4546
}.tap do |presented_stats|

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
{
215215
"type": "web",
216216
"index": 0,
217+
"instance_id": "e49f448e-54d2-4c33-61a3-5335",
217218
"state": "RUNNING",
218219
"usage": {
219220
"time": "2016-03-23T23:17:30.476314154Z",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ Example process stats object
88
```
99

1010
Name | Type | Description
11-
---- | ---- | -----------
11+
---- | -- | -----------
1212
**type** | _string_ | Process type; a unique identifier for processes belonging to an app
1313
**index** | _integer_ | The zero-based index of running instances
14+
**instance_id** | _string_ | The unique identifier of the instance
1415
**state** | _string_ | The state of the instance; valid values are `RUNNING`, `CRASHED`, `STARTING`, `DOWN`
1516
**usage** | _object_ | Object containing actual usage data for the instance; the value is `{}` when usage data is unavailable
1617
**usage.time** | _[timestamp](#timestamps)_ | The time when the usage was requested

lib/cloud_controller/diego/reporters/instances_stats_reporter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def stats_for_app(process)
3535
name: process.name,
3636
uris: process.uris,
3737
host: actual_lrp.actual_lrp_net_info.address,
38+
instance_id: actual_lrp.actual_lrp_instance_key.instance_guid,
3839
port: get_default_port(actual_lrp.actual_lrp_net_info),
3940
net_info: actual_lrp.actual_lrp_net_info.to_h,
4041
uptime: nanoseconds_to_seconds(current_time * 1e9 - actual_lrp.since),

lib/cloud_controller/opi/instances_client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class NotRunningProcessError < StandardError; end
1212

1313
LRP_INSTANCES_RETRIES = 5
1414
ActualLRPKey = Struct.new(:index, :process_guid)
15+
ActualLRPInstanceKey = Struct.new(:instance_guid)
1516
ActualLRPNetInfo = Struct.new(:address, :ports)
1617
PortMapping = Struct.new(:container_port, :host_port)
1718
DesiredLRP = Struct.new(:PlacementTags, :metric_tags)
@@ -23,10 +24,11 @@ def to_hash
2324
end
2425

2526
class ActualLRP
26-
attr_reader :actual_lrp_key, :state, :since, :placement_error, :actual_lrp_net_info
27+
attr_reader :actual_lrp_key, :actual_lrp_instance_key, :state, :since, :placement_error, :actual_lrp_net_info
2728

2829
def initialize(instance, process_guid)
2930
@actual_lrp_key = ActualLRPKey.new(instance['index'], process_guid)
31+
@actual_lrp_instance_key = ActualLRPInstanceKey.new('')
3032
@state = instance['state']
3133
@since = instance['since']
3234
@placement_error = instance['placement_error']

spec/request/processes_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@
490490
name: process.name,
491491
uris: process.uris,
492492
host: 'toast',
493+
instance_id: 'some-diego-instance-id',
493494
net_info: net_info_1,
494495
uptime: 12345,
495496
mem_quota: process[:memory] * 1024 * 1024,
@@ -515,6 +516,7 @@
515516
'type' => 'worker',
516517
'index' => 0,
517518
'state' => 'RUNNING',
519+
'instance_id' => 'some-diego-instance-id',
518520
'isolation_segment' => 'very-isolated',
519521
'details' => 'some-details',
520522
'usage' => {

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

Lines changed: 3 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_id: 'instance-a',
9192
port: 2222,
9293
net_info: lrp_1_net_info.to_h,
9394
uptime: two_days_in_seconds,
@@ -273,6 +274,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
273274
name: process.name,
274275
uris: process.uris,
275276
host: 'lrp-host',
277+
instance_id: 'instance-a',
276278
port: 2222,
277279
net_info: lrp_1_net_info.to_h,
278280
uptime: two_days_in_seconds,
@@ -397,6 +399,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:)
397399
name: process.name,
398400
uris: process.uris,
399401
host: 'lrp-host',
402+
instance_id: 'instance-a',
400403
port: 2222,
401404
net_info: lrp_1_net_info.to_h,
402405
uptime: two_days_in_seconds,

spec/unit/lib/cloud_controller/opi/instances_client_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@
7777
expect(actual_lrp.placement_error).to eq('')
7878
end
7979

80+
# Eirini doesn't currently support ActualLRP instance guids
81+
it 'provides an empty instance_guid value' do
82+
actual_lrp = actual_lrps.first
83+
expect(actual_lrp).to respond_to(:actual_lrp_instance_key)
84+
expect(actual_lrp.actual_lrp_instance_key.instance_guid).to eq('')
85+
end
86+
8087
context 'when having multiple actual LRPs' do
8188
let(:response_body) do
8289
{
@@ -189,7 +196,7 @@
189196
end
190197

191198
context '#desired_lrp_instance' do
192-
it 'should return a DesiredLRP with a placeholder PlacmentTags' do
199+
it 'should return a DesiredLRP with a placeholder PlacementTags' do
193200
desired_lrp = client.desired_lrp_instance(process)
194201
expect(desired_lrp.PlacementTags.first).to eq('placeholder')
195202
end

spec/unit/presenters/v3/process_stats_presenter_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module VCAP::CloudController::Presenters::V3
6262
name: process.name,
6363
uris: process.uris,
6464
host: 'myhost',
65+
instance_id: 'instance-a',
6566
net_info: net_info_1,
6667
uptime: 12345,
6768
mem_quota: process[:memory] * 1024 * 1024,
@@ -82,6 +83,7 @@ module VCAP::CloudController::Presenters::V3
8283
name: process.name,
8384
uris: process.uris,
8485
host: 'toast',
86+
instance_id: 'instance-b',
8587
net_info: net_info_2,
8688
uptime: 42,
8789
mem_quota: process[:memory] * 1024 * 1024,
@@ -109,6 +111,7 @@ module VCAP::CloudController::Presenters::V3
109111
expect(result[0][:type]).to eq(process.type)
110112
expect(result[0][:index]).to eq(0)
111113
expect(result[0][:state]).to eq('RUNNING')
114+
expect(result[0][:instance_id]).to eq('instance-a')
112115
expect(result[0][:details]).to eq(nil)
113116
expect(result[0][:isolation_segment]).to eq('hecka-compliant')
114117
expect(result[0][:host]).to eq('myhost')
@@ -125,6 +128,7 @@ module VCAP::CloudController::Presenters::V3
125128
expect(result[1][:type]).to eq(process.type)
126129
expect(result[1][:index]).to eq(1)
127130
expect(result[1][:state]).to eq('CRASHED')
131+
expect(result[1][:instance_id]).to eq('instance-b')
128132
expect(result[1][:details]).to eq('some-details')
129133
expect(result[1][:isolation_segment]).to eq(nil)
130134
expect(result[1][:host]).to eq('toast')
@@ -183,6 +187,7 @@ module VCAP::CloudController::Presenters::V3
183187
expect(result[0][:type]).to eq(process.type)
184188
expect(result[0][:index]).to eq(0)
185189
expect(result[0][:state]).to eq('RUNNING')
190+
expect(result[0][:instance_id]).to eq('instance-a')
186191
expect(result[0][:details]).to eq(nil)
187192
expect(result[0][:isolation_segment]).to eq('hecka-compliant')
188193
expect(result[0][:host]).to eq('myhost')
@@ -208,6 +213,7 @@ module VCAP::CloudController::Presenters::V3
208213
name: process.name,
209214
uris: process.uris,
210215
host: 'myhost',
216+
instance_id: 'instance-a',
211217
net_info: net_info_1,
212218
uptime: 12345,
213219
fds_quota: process.file_descriptors,
@@ -223,6 +229,7 @@ module VCAP::CloudController::Presenters::V3
223229
expect(result[0][:type]).to eq(process.type)
224230
expect(result[0][:index]).to eq(0)
225231
expect(result[0][:state]).to eq('RUNNING')
232+
expect(result[0][:instance_id]).to eq('instance-a')
226233
expect(result[0][:details]).to eq(nil)
227234
expect(result[0][:isolation_segment]).to eq('hecka-compliant')
228235
expect(result[0][:host]).to eq('myhost')

0 commit comments

Comments
 (0)