Skip to content

Commit

Permalink
Convert instance_id guids to base-36 numbers
Browse files Browse the repository at this point in the history
[cloudfoundry/eirini-release#207]

Co-authored-by: Mario Nitchev <[email protected]>
  • Loading branch information
georgethebeatle and mnitchev committed Apr 23, 2021
1 parent b390e19 commit 485dad0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/cloud_controller/diego/reporters/instances_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
15 changes: 8 additions & 7 deletions lib/cloud_controller/diego/reporters/reporter_mixins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 12 additions & 16 deletions lib/logcache/traffic_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 485dad0

Please sign in to comment.