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

[FINE] Fix container groups\images statistics for all entities #16345

Merged
merged 1 commit into from
Nov 13, 2017
Merged
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
8 changes: 8 additions & 0 deletions app/models/manageiq/providers/container_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ class ContainerManager < BaseManager
alias :all_computer_systems :computer_systems
alias :all_computer_system_ids :computer_system_ids

def all_container_groups
ContainerGroup.where(:ems_id => id).or(ContainerGroup.where(:old_ems_id => id))
end

def all_container_images
ContainerImage.where(:ems_id => id).or(ContainerImage.where(:old_ems_id => id))
end

def aggregate_cpu_total_cores(targets = nil)
aggregate_hardware(:computer_systems, :cpu_total_cores, targets)
end
Expand Down
21 changes: 12 additions & 9 deletions app/models/metric/statistic.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module Metric::Statistic
def self.calculate_stat_columns(obj, timestamp)
return {} unless obj.respond_to?(:container_groups)
return {} unless obj.respond_to?(:container_images)

capture_interval = Metric::Helper.get_time_interval(obj, timestamp)
container_groups = ContainerGroup.where(:ems_id => obj.id).or(ContainerGroup.where(:old_ems_id => obj.id))
stats = {}

if obj.respond_to?(:all_container_groups)
container_groups = obj.all_container_groups # Get disconnected entities as well
stats[:stat_container_group_create_rate] = container_groups.where(:ems_created_on => capture_interval).count
stats[:stat_container_group_delete_rate] = container_groups.where(:deleted_on => capture_interval).count
end

if obj.respond_to?(:all_container_images)
stats[:stat_container_image_registration_rate] = obj.all_container_images.where(:registered_on => capture_interval).count
end

{
:stat_container_group_create_rate => container_groups.where(:ems_created_on => capture_interval).count,
:stat_container_group_delete_rate => container_groups.where(:deleted_on => capture_interval).count,
:stat_container_image_registration_rate => obj.container_images.where(:registered_on => capture_interval).count
}
stats
end
end
19 changes: 19 additions & 0 deletions spec/models/metric/statistic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
:zone => Zone.first)
end

let(:project) do
FactoryGirl.create(:container_project,
:name => "project")
end

hour = Time.parse(Metric::Helper.nearest_hourly_timestamp(Time.now)).utc

let(:c1) { FactoryGirl.create(:container_group, :ems_created_on => hour - 10.minutes) }
Expand Down Expand Up @@ -42,5 +47,19 @@

expect(derived_columns[:stat_container_image_registration_rate]).to eq(2)
end

it "count created container groups in a project" do
project.container_groups << [c1, c2, c3, c4, c5, c6, c7, c8]
derived_columns = described_class.calculate_stat_columns(project, hour)

expect(derived_columns[:stat_container_group_create_rate]).to eq(2)
end

it "count deleted container groups in a project" do
project.container_groups << [c1, c2, c3, c4, c5, c6, c7, c8]
derived_columns = described_class.calculate_stat_columns(project, hour)

expect(derived_columns[:stat_container_group_delete_rate]).to eq(2)
end
end
end