Skip to content

Commit

Permalink
Merge pull request #22605 from kbrock/vps_purging
Browse files Browse the repository at this point in the history
VimPerformanceState#purge_timer for old records
  • Loading branch information
Fryguy committed Jul 7, 2023
2 parents 33714b1 + 8e19738 commit 41dc875
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/models/mixins/purging_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
# :miq_report_id
# end
#
# example purge_mode_and_value
# @return [Array<2>] the mode (i.e.: :remaining) and the number of records to keep
# def purge_mode_and_value
# [:remaining, ::Settings.drift_states.history.keep_drift_states]
# end
#
# For purge_by_orphan, the mixee must provide the following methods:
#
# @return [Array<2>] the mode (i.e.: :orphan) and the column_name to check for orphans
# def purge_mode_and_value
# %w[orphan resource]
# end
module PurgingMixin
extend ActiveSupport::Concern

Expand Down
19 changes: 19 additions & 0 deletions app/models/vim_performance_state/purging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ def purge_mode_and_value
%w(orphaned resource)
end

# remove anything where the resource no longer exists AND
# remove anything older than a certain date
def purge_timer
purge_queue(:orphaned, "resource")
purge_queue(:date, purge_date)
end

def purge_window_size
::Settings.vim_performance_states.history.purge_window_size
end

#
# By Date
#

def purge_date
::Settings.vim_performance_states.history.keep_states.to_i_with_method.seconds.ago.utc
end

def purge_scope(older_than)
where(arel_table[:timestamp].lt(older_than))
end
end
end
end
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@
:url:
:vim_performance_states:
:history:
:keep_states: 6.months
:purge_window_size: 1000
:webservices:
:consume_protocol: https
Expand Down
9 changes: 7 additions & 2 deletions spec/models/vim_performance_state/purging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@
describe ".purge_timer" do
it "queues the correct purge method" do
EvmSpecHelper.local_miq_server
stub_settings_merge(:vim_performance_states => {:history => {:keep_states => "6.months"}})
described_class.purge_timer
q = MiqQueue.first
expect(q).to have_attributes(:class_name => described_class.name, :method_name => "purge_by_orphaned", :args => ["resource"])

expect(MiqQueue.count).to eq(2)
q1, q2 = MiqQueue.order(:id).to_a
expect(q1).to have_attributes(:class_name => described_class.name, :method_name => "purge_by_orphaned", :args => ["resource"])
expect(q2).to have_attributes(:class_name => described_class.name, :method_name => "purge_by_date")
expect(q2.args.first).to be_within(2.days).of 6.months.ago.utc
end
end
end
Expand Down

0 comments on commit 41dc875

Please sign in to comment.