diff --git a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb index b31d1713610..c4ea6e4eb73 100644 --- a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb +++ b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb @@ -78,7 +78,7 @@ def build_info(state, actual_lrp, process, stats, quota_stats, log_cache_errors) host: actual_lrp.actual_lrp_net_info.address, 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, + net_info: actual_lrp_net_info_to_hash(actual_lrp.actual_lrp_net_info), uptime: nanoseconds_to_seconds((Time.now.to_f * 1e9) - actual_lrp.since), fds_quota: process.file_descriptors }.merge(metrics_data_for_instance(stats, quota_stats, log_cache_errors, Time.now.to_datetime.rfc3339, actual_lrp.actual_lrp_key.index)) @@ -198,6 +198,22 @@ def get_default_port(net_info) 0 end + + def actual_lrp_net_info_to_hash(net_info) + %i[address instance_address ports preferred_address].index_with do |field_name| + if field_name == :ports + net_info.ports.map(&method(:port_mapping_to_hash)) + else + net_info.send(field_name) + end + end + end + + def port_mapping_to_hash(port_mapping) + %i[container_port container_tls_proxy_port host_port host_tls_proxy_port].index_with do |field_name| + port_mapping.send(field_name) + end + end end end end 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 ef393228292..2c702118907 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 @@ -78,6 +78,17 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) [container_metric_batch] end + let(:expected_lrp_1_net_info) do + { + address: 'lrp-host', + instance_address: '', + ports: [ + { container_port: DEFAULT_APP_PORT, container_tls_proxy_port: 0, host_port: 2222, host_tls_proxy_port: 0 }, + { container_port: 1111, container_tls_proxy_port: 0, host_port: 0, host_tls_proxy_port: 0 } + ], + preferred_address: :UNKNOWN + } + end let(:expected_stats_response) do { 0 => { @@ -90,7 +101,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) host: 'lrp-host', instance_guid: 'instance-a', port: 2222, - net_info: lrp_1_net_info.to_h, + net_info: expected_lrp_1_net_info, uptime: two_days_in_seconds, mem_quota: 1234, disk_quota: 10_234, @@ -217,7 +228,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) host: 'lrp-host', instance_guid: 'instance-a', port: 2222, - net_info: lrp_1_net_info.to_h, + net_info: expected_lrp_1_net_info, uptime: two_days_in_seconds, mem_quota: nil, disk_quota: nil, @@ -272,7 +283,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) host: 'lrp-host', instance_guid: 'instance-a', port: 2222, - net_info: lrp_1_net_info.to_h, + net_info: expected_lrp_1_net_info, uptime: two_days_in_seconds, mem_quota: nil, disk_quota: nil, @@ -519,7 +530,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) host: 'lrp-host', instance_guid: 'instance-a', port: 2222, - net_info: lrp_1_net_info.to_h, + net_info: expected_lrp_1_net_info, uptime: two_days_in_seconds, mem_quota: nil, disk_quota: nil, @@ -653,7 +664,7 @@ def make_actual_lrp(instance_guid:, index:, state:, error:, since:) host: 'lrp-host', instance_guid: 'instance-a', port: 2222, - net_info: lrp_1_net_info.to_h, + net_info: expected_lrp_1_net_info, uptime: two_days_in_seconds, mem_quota: nil, disk_quota: nil,