Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [DEBUG] CONTAINER_INFLATE_FACTOR env var to duplicate most entities #14608

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/ems_refresh/save_inventory_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def save_ems_container_inventory(ems, hashes, target = nil)

# Save and link other subsections
child_keys.each do |k|
send("save_#{k}_inventory", ems, hashes[k], target)
puts "save_#{k}_inventory", Benchmark.measure { send("save_#{k}_inventory", ems, hashes[k], target) }
end

ems.save!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ module ManageIQ::Providers::Kubernetes
class ContainerManager::RefreshParser
include Vmdb::Logging
def self.ems_inv_to_hashes(inventory)
new.ems_inv_to_hashes(inventory)
result, t = Benchmark.realtime_block(:total_ems_inv_to_hashes) do
new.ems_inv_to_hashes(inventory)
end
puts "containers refresh_parser - Timings: #{t.inspect}"
result
end

def initialize
Expand Down Expand Up @@ -129,7 +133,9 @@ def get_additional_attributes(inventory)

def process_collection(collection, key, &block)
@data[key] ||= []
collection.each { |item| process_collection_item(item, key, &block) }
Benchmark.realtime_block(key) do
collection.each { |item| process_collection_item(item, key, &block) }
end
end

def process_collection_item(item, key)
Expand Down Expand Up @@ -351,7 +357,7 @@ def parse_pod(pod)
if createdby.kind_of?(Hash) && !createdby['reference'].nil?
new_result[:container_replicator] = @data_index.fetch_path(
:container_replicators, :by_namespace_and_name,
createdby['reference']['namespace'], createdby['reference']['name'])
pod.metadata["table"][:namespace], createdby['reference']['name'])
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,45 @@ def parse_legacy_inventory(ems)
fetch_entities(openshift_client, OPENSHIFT_ENTITIES)
end
entities = openshift_entities.merge(kube_entities)
_inflate(entities)
entities["additional_attributes"] = fetch_hawk_inv(ems) || {}
EmsRefresh.log_inv_debug_trace(entities, "inv_hash:")
ManageIQ::Providers::Openshift::ContainerManager::RefreshParser.ems_inv_to_hashes(entities)

res = nil
puts "parser:", Benchmark.measure { res = ManageIQ::Providers::Openshift::ContainerManager::RefreshParser.ems_inv_to_hashes(entities) }
res
end

# DEBUGGING
INFLATE_FACTOR = ENV['CONTAINER_INFLATE_FACTOR'] ? ENV['CONTAINER_INFLATE_FACTOR'].to_i : 1

def _inflate(inventory)
return if INFLATE_FACTOR == 1
inventory.each do |k, structs|
orig = structs.dup
orig.each do |s|
(2..INFLATE_FACTOR).each do |i|
copy = s.deep_dup
# Hopefully most cross-refs are by name relative to current namespace?
case k
when "image", "node", "component_status"
# not inflated. TODO?
next
when "project", "namespace"
copy.metadata.name += "_inflate#{i}"
else
byebug unless copy.metadata.namespace
copy.metadata.namespace += "_inflate#{i}"
end
byebug unless copy.metadata.uid
copy.metadata.uid += "_inflate#{i}"
# selfLink doesn't matter.

structs << copy
end
end
puts "CONTAINER_INFLATE_FACTOR=#{INFLATE_FACTOR}: #{k}: \t#{orig.size} -> #{structs.size}"
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe ManageIQ::Providers::Openshift::ContainerManager::Refresher do
let(:inflate_factor) { ManageIQ::Providers::Openshift::ContainerManager::Refresher::INFLATE_FACTOR }

before(:each) do
allow(MiqServer).to receive(:my_zone).and_return("default")
hostname = 'host.example.com'
Expand Down Expand Up @@ -84,17 +86,17 @@
end

def assert_table_counts
expect(ContainerGroup.count).to eq(20)
expect(ContainerGroup.count).to eq(20 * inflate_factor)
expect(ContainerNode.count).to eq(2)
expect(Container.count).to eq(20)
expect(ContainerService.count).to eq(12)
expect(ContainerPortConfig.count).to eq(23)
expect(ContainerDefinition.count).to eq(20)
expect(ContainerRoute.count).to eq(6)
expect(ContainerProject.count).to eq(9)
expect(ContainerBuild.count).to eq(3)
expect(ContainerBuildPod.count).to eq(3)
expect(ContainerTemplate.count).to eq(26)
expect(Container.count).to eq(20 * inflate_factor)
expect(ContainerService.count).to eq(12 * inflate_factor)
expect(ContainerPortConfig.count).to eq(23 * inflate_factor)
expect(ContainerDefinition.count).to eq(20 * inflate_factor)
expect(ContainerRoute.count).to eq(6 * inflate_factor)
expect(ContainerProject.count).to eq(9 * inflate_factor)
expect(ContainerBuild.count).to eq(3 * inflate_factor)
expect(ContainerBuildPod.count).to eq(3 * inflate_factor)
expect(ContainerTemplate.count).to eq(26 * inflate_factor)
expect(ContainerImage.count).to eq(40)
end

Expand Down