diff --git a/lib/cloud_controller/diego/reporters/instances_reporter.rb b/lib/cloud_controller/diego/reporters/instances_reporter.rb index 810852c6e90..bdcd335fc69 100644 --- a/lib/cloud_controller/diego/reporters/instances_reporter.rb +++ b/lib/cloud_controller/diego/reporters/instances_reporter.rb @@ -20,7 +20,7 @@ def self.singleton_workpool def all_instances_for_app(process) instances = {} bbs_instances_client.lrp_instances(process).each do |actual_lrp| - next unless actual_lrp.actual_lrp_key.index < process.instances + # next unless actual_lrp.actual_lrp_key.index < process.instances current_time_ns = Time.now.to_f * 1e9 translated_state = LrpStateTranslator.translate_lrp_state(actual_lrp) diff --git a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb index 264dab5fef6..0ec5005931e 100644 --- a/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb +++ b/lib/cloud_controller/diego/reporters/instances_stats_reporter.rb @@ -39,7 +39,7 @@ def stats_for_app(process) bbs_instances_client.lrp_instances(process).each do |actual_lrp| index = actual_lrp.actual_lrp_key.index - next unless index < process.instances + # next unless index < process.instances info = { state: LrpStateTranslator.translate_lrp_state(actual_lrp), diff --git a/lib/cloud_controller/diego/reporters/reporter_mixins.rb b/lib/cloud_controller/diego/reporters/reporter_mixins.rb index f621af1d276..e79cf875d4e 100644 --- a/lib/cloud_controller/diego/reporters/reporter_mixins.rb +++ b/lib/cloud_controller/diego/reporters/reporter_mixins.rb @@ -8,13 +8,14 @@ def nanoseconds_to_seconds(time) end def fill_unreported_instances_with_down_instances(reported_instances, process) - process.instances.times do |i| - unless reported_instances[i] - reported_instances[i] = { - state: 'DOWN', - uptime: 0, - } - end + down_instances = process.instances - reported_instances.length + return reported_instances unless down_instances > 0 + + for i in (0..down_instances) do + reported_instances[i] = { + state: 'DOWN', + uptime: 0, + } end reported_instances diff --git a/lib/logcache/traffic_controller_decorator.rb b/lib/logcache/traffic_controller_decorator.rb index 497ea3480c8..d3e3fa585e4 100644 --- a/lib/logcache/traffic_controller_decorator.rb +++ b/lib/logcache/traffic_controller_decorator.rb @@ -35,22 +35,19 @@ def container_metrics(auth_token: nil, source_guid:, logcache_filter:) end end - instance_id_to_index = Hash[final_envelopes. - uniq { |e| e.instance_id }. - sort_by { |e| e.instance_id }. - each_with_index. - map { |e, i| [e.instance_id, i] } - ] - final_envelopes. select { |e| has_container_metrics_fields?(e) && logcache_filter.call(e) }. # workaround metric-proxy sending non-numeric instance_id in disk usage metric, see # https://github.com/cloudfoundry/metric-proxy/blob/10ea8430e142910ef949f1f425f2d9eda10b950c/pkg/metrics/proxy.go#L176 - # uniq { |e| e.gauge.metrics.keys << e.instance_id }. - uniq { |e | e.gauge.metrics.keys << instance_id_to_index[e.instance_id] }. - sort_by{ |e| e.instance_id }. - chunk{ |e| e.instance_id }. - map { |envelopes_by_instance| convert_to_traffic_controller_envelope(source_guid, envelopes_by_instance, instance_id_to_index[envelopes_by_instance.first]) } + # uniq { |e| e.gauge.metrics.keys << '0' }. + map { |e| + e.instance_id = e.instance_id.to_i(36).to_s + e + }. + uniq { |e| e.gauge.metrics.keys << e.instance_id }. + sort_by(&:instance_id). + chunk(&:instance_id). + map { |envelopes_by_instance| convert_to_traffic_controller_envelope(source_guid, envelopes_by_instance) } end private @@ -78,18 +75,17 @@ def has_container_metrics_fields?(envelope) # rubocop:enable Style/PreferredHashMethods end - def convert_to_traffic_controller_envelope(source_guid, envelopes_by_instance, index) + def convert_to_traffic_controller_envelope(source_guid, envelopes_by_instance) tc_envelope = TrafficController::Models::Envelope.new( containerMetric: TrafficController::Models::ContainerMetric.new({ applicationId: source_guid, - # instanceIndex: envelopes_by_instance.first, - instanceIndex: index, + instanceIndex: envelopes_by_instance.first, }), ) tags = {} envelopes_by_instance.second.each { |e| - tc_envelope.containerMetric.instanceIndex = index + tc_envelope.containerMetric.instanceIndex = e.instance_id # rubocop seems to think that there is a 'key?' method # on envelope.gauge.metrics - but it does not # rubocop:disable Style/PreferredHashMethods