Skip to content

Commit

Permalink
Make VimPerformanceTagValue no longer backed by a DB table
Browse files Browse the repository at this point in the history
Follow up to ManageIQ#16692
This change removes all the code involved with reading vim_performance_tag_values
data from the table. It no longer necessary because it all generated on demand.
  • Loading branch information
gtanzillo committed Mar 15, 2018
1 parent 9cb13f1 commit 419cd6e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 146 deletions.
1 change: 0 additions & 1 deletion app/models/metric/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Metric::Common
included do
belongs_to :resource, :polymorphic => true
belongs_to :time_profile
has_many :vim_performance_tag_values, :as => :metric, :dependent => :destroy

belongs_to :parent_host, :class_name => "Host"
belongs_to :parent_ems_cluster, :class_name => "EmsCluster"
Expand Down
35 changes: 3 additions & 32 deletions app/models/metric/purging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,6 @@ def self.purge_count(older_than, interval)
purge_scope(older_than, interval).count
end

# Used for MetricRollup (not Metric)
# A list of ids (not a scope) is brought in and associated vimPerformanceTagValue records are deleted
#
# TODO: Would be more efficient to just use the full scope here (not id list)
# - we would then just use the standard purge_in_batches
# - remove the to_a from purge_in_batches
# - possibly use the standard purge_in_batches
# - change the metrics rollups to use truncate instead
def self.purge_associated_records(metric_type, ids)
# Since VimPerformanceTagValues are 6 * number of tags per performance
# record, we need to batch in smaller trips.
count_tag_values = 0
_log.info("Purging associated tag values.")
ids.each_slice(50) do |vp_ids|
tv_count, = Benchmark.realtime_block(:purge_vim_performance_tag_values) do
VimPerformanceTagValue.where(:metric_id => vp_ids, :metric_type => metric_type).delete_all
end
count_tag_values += tv_count
end
_log.info("Purged #{count_tag_values} associated tag values.")
count_tag_values
end

def self.purge_daily(older_than, window = nil, total_limit = nil, &block)
purge_by_date(older_than, "daily", window, total_limit, &block)
end
Expand Down Expand Up @@ -128,15 +105,14 @@ def self.purge_by_date(older_than, interval, window = nil, total_limit = nil, &b
scope = purge_scope(older_than, interval)
window ||= purge_window_size
_log.info("Purging #{total_limit || "all"} #{interval} metrics older than [#{older_than}]...")
total, total_tag_values, timings = purge_in_batches(scope, window, 0, total_limit, &block)
total, timings = purge_in_batches(scope, window, 0, total_limit, &block)
_log.info("Purging #{total_limit || "all"} #{interval} metrics older than [#{older_than}]...Complete - " +
"Deleted #{total} records and #{total_tag_values} associated tag values - Timings: #{timings.inspect}")
"Deleted #{total} records - Timings: #{timings.inspect}")

total
end

def self.purge_in_batches(scope, window, total = 0, total_limit = nil)
total_tag_values = 0
query = scope.select(:id).limit(window)

_, timings = Benchmark.realtime_block(:total_time) do
Expand Down Expand Up @@ -164,16 +140,11 @@ def self.purge_in_batches(scope, window, total = 0, total_limit = nil)
break if count == 0
total += count

if scope.klass == MetricRollup
count_tag_values = purge_associated_records(scope.name, batch_ids)
total_tag_values += count_tag_values
end

yield(count, total) if block_given?
break if count < window || (total_limit && (total_limit <= total))
end
end

[total, total_tag_values, timings]
[total, timings]
end
end
1 change: 0 additions & 1 deletion app/models/vim_performance_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def self.group_by_tags(recs, options)
def self.build_tag_value_recs(rec, options)
tvrecs = VimPerformanceTagValue.build_for_association(rec,
options[:cat_model].pluralize.underscore,
:save => false,
:category => options[:category])
tvrecs = tvrecs.select { |r| r.category == options[:category] }

Expand Down
27 changes: 9 additions & 18 deletions app/models/vim_performance_tag_value.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class VimPerformanceTagValue < ApplicationRecord
belongs_to :metric, :polymorphic => true

serialize :assoc_ids
class VimPerformanceTagValue
attr_accessor :tag_name, :association_type, :category, :column_name, :value, :assoc_ids

TAG_SEP = "|"
TAG_COLS = {
Expand Down Expand Up @@ -42,13 +40,17 @@ class VimPerformanceTagValue < ApplicationRecord
"Service" => [:vms]
}

def self.build_from_performance_record(parent_perf, options = {:save => true})
def initialize(options = {})
options.each { |k, v| public_send("#{k}=", v) }
end

def self.build_from_performance_record(parent_perf, options = {})
RESOURCE_TYPE_TO_ASSOCIATIONS[parent_perf.resource_type].collect { |assoc| build_for_association(parent_perf, assoc, options) }.flatten
end

cache_with_timeout(:eligible_categories, 5.minutes) { Classification.category_names_for_perf_by_tag }

def self.build_for_association(parent_perf, assoc, options = {:save => true})
def self.build_for_association(parent_perf, assoc, options = {})
eligible_cats = eligible_categories
return [] if eligible_cats.empty?

Expand Down Expand Up @@ -116,19 +118,8 @@ def self.build_for_association(parent_perf, assoc, options = {:save => true})
}
attr = col == 'assoc_ids' ? :assoc_ids : :value
new_rec[attr] = result[key]
if options[:save]
parent_perf_tag_value_recs = parent_perf.vim_performance_tag_values.inject({}) do |h, tv|
h.store_path(tv.association_type, tv.category, tv.tag_name, tv.column_name, tv)
h
end

tag_value_rec = parent_perf_tag_value_recs.fetch_path(association_type, category, tag_name, col)
tag_value_rec ||= parent_perf_tag_value_recs.store_path(association_type, category, tag_name, col, parent_perf.vim_performance_tag_values.build)
tag_value_rec.update_attributes(new_rec)
else
tag_value_rec = new(new_rec)
end
a << tag_value_rec
a << new(new_rec)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def write_rows(resources, interval_name, start_time, end_time, data)
samples_inventory_collection = nil

if interval_name == 'hourly'
# TODO(lsmola) pff, it needs AR objects, quite ineffective to batch here
_log.info("#{log_header} Adding missing timestamp intervals...")
resources.each do |resource|
Benchmark.realtime_block(:add_missing_intervals) { Metric::Processing.add_missing_intervals(resource, "hourly", start_time, end_time) }
Expand Down
3 changes: 0 additions & 3 deletions spec/factories/vim_performance_tag_value.rb

This file was deleted.

90 changes: 0 additions & 90 deletions tools/purge_orphaned_tag_values.rb

This file was deleted.

0 comments on commit 419cd6e

Please sign in to comment.