-
Notifications
You must be signed in to change notification settings - Fork 897
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
Add purge timer for archived entities #14322
Conversation
I expected to see the PurgingMixin somewhere, but I don't see it. How does purge_scope get used? |
app/models/container/purging.rb
Outdated
module Purging | ||
include ArchivedPurgingMixin | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need these layers of indirection. I think you can just include ArchivedPurgingMixin
directly into the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this working out of the box? If so, that is cool.
Thought you'd have to define scope
or something.
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary with ActiveSupport::Concern because it does this for you.
@kbrock can you also take a look? 🙇 |
34a3755
to
f476c39
Compare
config/settings.yml
Outdated
@@ -1363,6 +1367,7 @@ | |||
:poll_method: :normal | |||
:queue_timeout: 120.minutes | |||
:schedule_worker: | |||
:archived_entities_purge_interval: 1.day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simon3z @moolitayer Are these the settings we want for container entities?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:archived_
is not descriptive here. probably want to use container_
@Fryguy i didnt understand purging correctly. I made some changes and mostly borrowed examples from |
Added tests |
@miq-bot remove_label wip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tend to have a Purging
module for each class.
But this seems to do well.
Was hoping ArchivedMixin
would have defined purge
and purge_queue
method for us.
@@ -121,6 +121,14 @@ def miq_report_result_purge_timer | |||
queue_work(:class_name => "MiqReportResult", :method_name => "purge_timer", :zone => nil) | |||
end | |||
|
|||
def archived_entities_purge_timer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrafanie up until now, Job
inserts a single work record and the model's Purge
coordinates multiple records.
But this is nice that it reduces the number of settings timers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@durandom something to add to the pluggable backlog ... how can we allow providers (and separate provider repos) to engage with different timers?
:class_name => name, | ||
:method_name => "purge", | ||
:queue_name => "ems", | ||
:args => [ts] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:args
is not unique, so we need to get it out of here.
MiqQueue.create_with(:args => [ts]).put_unless_exists(
:class_name => name,
:method_name => "purge",
:queue_name => "ems"
)
|
||
alias_method :purge_timer, :purge_queue | ||
|
||
def purge_timer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either use alias_method
OR define purge_timer
if you go with alias_method
, add a ts ||= purge_date
window ||= purge_window_size | ||
|
||
total = where(arel_table[:deleted_on].lteq(older_than)).delete_in_batches(window, limit) do |count, _total| | ||
_log.info("Purging #{count} events.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not deleting events
.
update the name here and 3 lines down
describe ArchivedPurgingMixin do | ||
let(:example_class) { Container } | ||
|
||
context "::Purging" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Remove this line since we do not have a module named ::Purging
@@ -2,6 +2,7 @@ class Container < ApplicationRecord | |||
include SupportsFeatureMixin | |||
include NewWithTypeStiMixin | |||
include ArchivedMixin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove ArchivedMixin
(since that is included by ArchivedMixin
) - (5 changes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kbrock Not sure what you mean here. Do you mean to unify ArchivedMIxin
and ArchivedPurgingMixin
? I think that would work well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zeari well, merging them is one option.
But I was saying that since ArchivedPurgingMixin
includes ArchivedMixin
, there is no reason to keep the include ArchivedMixin
in these files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since ArchivedPurgingMixin includes ArchivedMixin
@kbrock It doesnt though(unless im missing something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zeari Aah, I was referring the https://github.com/ManageIQ/manageiq/pull/14322/files#diff-bfb9598d272bb5d013105604b37dcabaR3
Ok, now that I look at the code, please remove it from ArchivedPurgingMixin
. Do you think a better name would be PurgingContinerMixin
?
expect(q.first).to have_attributes( | ||
:class_name => example_class.name, | ||
:method_name => "purge", | ||
:args => [purge_time] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bonus: this test ensures that the create_with(:args => ...)
works well too.
47318e0
to
92f3e88
Compare
@@ -27,9 +28,6 @@ class ContainerImage < ApplicationRecord | |||
serialize :exposed_ports, Hash | |||
serialize :environment_variables, Hash | |||
|
|||
# Needed for scanning & tagging action | |||
delegate :my_zone, :to => :ext_management_system | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContainerImage
didnt use ArchivedMixin
but definitely should
@zeari Every model used to define different purging methods but we were able to consolidate most of those methods into |
@kbrock
I thought it would apply here too. How about unifying this new purging mixin with the pre-exisisting |
The variable is for running containers. Would like the variable renamed. "Purging anything that has an ems archived" seems a little vague. A majority of the mixin seems like basic pruning functionality. Can we Can you use def purge_timer
purge_queue(*purge_mode_and_value)
end I'm pretty sure we only have 2 different versions of this method. |
) | ||
end | ||
|
||
def purge_timer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see other note, think purge_timer
and purge_queue
and purge
can be removed.
def purge_scope(older_than)
where(arel_table[:deleted_on].lteq(older_than))
end
Sorry, @zeari - I did not forget about you here. This got me looking at all the various purging examples out there. Put in #14676 to make the implementations more consistent. There are 3 examples of purging that I like a lot:
Think the simpler one meets your needs better. It should simplify your implementation greatly. I think of |
Checked commit zeari@88dd01c with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
Straight forward and easy to figure out in the future
Let's hope it will keep these tables from growing too large.
ping @simon3z can you approve the changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@miq-bot add_label fine/yes euwe/yes |
@simon3z Cannot apply the following label because they are not recognized: fine/yes euwe/yes |
@miq-bot add_label fine/yes, euwe/yes |
Add purge timer for archived entities (cherry picked from commit b8b9c81) https://bugzilla.redhat.com/show_bug.cgi?id=1448148
Euwe backport details:
|
Add purge timer for archived entities (cherry picked from commit b8b9c81) https://bugzilla.redhat.com/show_bug.cgi?id=1458333
Fine backport details:
|
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1428595
Periodically purge all archived container entities that were deleted more than 6 months ago.
This change currently applies only to containers but it may be used generically for any other areas of the project similarly to
ArchivedMixin
@simon3z @moolitayer PTAL
@miq-bot add_label providers/containers, wip
Edit: I tested this out locally in the console with: