Skip to content

Commit

Permalink
WIP: PERF_ROLLUPS
Browse files Browse the repository at this point in the history
before, the rollups were limited
now, unsure

not sure if clearing associations code is still valid
  • Loading branch information
kbrock committed Mar 9, 2024
1 parent a6a5722 commit 5b45f67
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/models/availability_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def self.available
end

PERF_ROLLUP_CHILDREN = [:vms].freeze
PERF_ROLLUPS = {:vms => :vms_and_templates}.freeze

def perf_rollup_parents(interval_name = nil)
[ext_management_system].compact unless interval_name == 'realtime'
Expand Down
1 change: 1 addition & 0 deletions app/models/container_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ContainerImage < ApplicationRecord
delegate :my_zone, :to => :ext_management_system, :allow_nil => true

PERF_ROLLUP_CHILDREN = [:containers].freeze
PERF_ROLLUPS = {:containers => :containers, :image_tag_names => :image_tag_names}.freeze

def perf_rollup_parents(interval_name = nil)
[] unless interval_name == 'realtime' # we only process rollups
Expand Down
1 change: 1 addition & 0 deletions app/models/container_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ContainerProject < ApplicationRecord
include EventMixin
include Metric::CiMixin

# TODO: should this be stored in VimPerformanceState ps as :container_groups?
PERF_ROLLUP_CHILDREN = [:all_container_groups].freeze

delegate :my_zone, :to => :ext_management_system, :allow_nil => true
Expand Down
2 changes: 2 additions & 0 deletions app/models/ems_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def effective_resource(resource)
#

PERF_ROLLUP_CHILDREN = [:hosts].freeze
# TODO: do we need to collect vms for clusters?
PERF_ROLLUPS = {:hosts => :hosts, :vms => :all_vms_and_templates}.freeze

def perf_rollup_parents(interval_name = nil)
[ext_management_system].compact unless interval_name == 'realtime'
Expand Down
1 change: 1 addition & 0 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ def domain
#

PERF_ROLLUP_CHILDREN = [:vms].freeze
PERF_ROLLUPS = {:vms => :vms_and_templates}.freeze

def perf_rollup_parents(interval_name = nil)
if interval_name == 'realtime'
Expand Down
1 change: 1 addition & 0 deletions app/models/host_aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def remove_host(*_args)
end

PERF_ROLLUP_CHILDREN = [:vms].freeze
PERF_ROLLUPS = {:vms => :vms_and_templates}.freeze

def perf_rollup_parents(_interval_name = nil)
# don't rollup to ext_management_system since that's handled through availability zone
Expand Down
9 changes: 7 additions & 2 deletions app/models/metric/ci_mixin/state_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,22 @@ def vim_performance_state_association(ts, assoc)
end
end

# TODO: do we need to translate vms to proper name / use child_associations hash?
# specifically thinking about vms
if !association(assoc.to_sym).loaded?
MiqPreloader.preload_from_array(self, assoc, vim_performance_state_for_ts(ts).public_send(assoc))
end
public_send(assoc)
end

ASSOCIATIONS = [:vms, :hosts, :ems_clusters, :ext_management_systems, :storages, :container_nodes, :container_groups,
:all_container_groups, :containers]
# @returns Hash<name in VimPerformanceState, (virtual?) association name in model>
def vim_performance_state_child_associations
if defined?(self.class::PERF_ROLLUPS)
if defined?(self.class::PERF_ROLLUPS) && false
self.class::PERF_ROLLUPS
else
VimPerformanceState::ASSOCIATIONS.each_with_object({}) do |assoc, h|
ASSOCIATIONS.each_with_object({}) do |assoc, h|
method = if assoc == :vms
if is_a?(EmsCluster)
:all_vms_and_templates
Expand All @@ -95,6 +99,7 @@ def vim_performance_state_child_associations
end
h[assoc] = method if respond_to?(method)
end
# self.class::PERF_ROLLUP_CHILDREN.each_with_object({}) { |x, h| h[x] = x }
end
end
end
2 changes: 2 additions & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ def queue_chargeback_report_generation(options = {})
#

PERF_ROLLUP_CHILDREN = [:vms].freeze
# this is not needed, but present to show the deviation from the typical vms association
PERF_ROLLUP = {:vms => :vms}.freeze

def perf_rollup_parents(interval_name = nil)
[] unless interval_name == 'realtime'
Expand Down
3 changes: 0 additions & 3 deletions app/models/vim_performance_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ class VimPerformanceState < ApplicationRecord

belongs_to :resource, :polymorphic => true

ASSOCIATIONS = [:vms, :hosts, :ems_clusters, :ext_management_systems, :storages, :container_nodes, :container_groups,
:all_container_groups, :containers]

# Define accessors for state_data information
[
:assoc_ids,
Expand Down
9 changes: 9 additions & 0 deletions spec/models/metric/ci_mixin/state_finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@
end
end

describe "#vim_performance_state_child_associations" do
it "calculates the values" do
expect(AvailabilityZone.new.vim_performance_state_child_associations).to eq(
:vms => :vms_and_templates
)
# TODO: all classes
end
end

private

def create_vps(parent, timestamp, association = {})
Expand Down

0 comments on commit 5b45f67

Please sign in to comment.