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

Merge retirement checks #15645

Merged
merged 7 commits into from
Jul 26, 2017
Merged

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Jul 25, 2017

Tests retirement checks bundled by @isimluk here. Vms, Services, OrchestrationStacks, and LoadBalancers run basically the same code for the regular retirement_checks which is now a single queue job thanks to Šimon. The tests create two of each model, only one of which passes the arel conditions of having a retirement date in the future, not being retired already, and having an ems_id present in the list of ids from MiqServer (with the exception of Service, which isn't attached to a zone). The arel is broken out into a separate method to avoid the issue of expect_any_instance_of running on the wrong instance.

By default we run retirement_check for Vms, Services, LoadBalancers and
OrchestrationStacks every 10 minutes.

Most of the time, retirement_check results into no-op. However, it has
fixed costs attached.
 - it inserts, selects updates, and deletes from MiqQueue
 - it locks miq_queue_lock
 - it synces log messages (they grow)
 - it takes worker's time to process

Every 10 minutes.

Moreover, the code base is very similar -> no point of having it so
many times. Every method defined increases our footprint. Every penny
counts.

Even in cases, your set-up uses retirement dates heavily, each run will
go through really quickly -> so there is not reason for separation. The
work is already too small, to divide into multiple jobs.
@d-m-u
Copy link
Contributor Author

d-m-u commented Jul 25, 2017

@miq-bot add_label performance
@miq-bot add_label retirement

FactoryGirl.create(:vm)
FactoryGirl.create(:service, :retires_on => Time.zone.today + 1.day)
FactoryGirl.create(:service, :retired => true)
allow(MiqServer).to receive(:my_server).and_return(my_server)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why allow rather than expect?

let(:my_server) { FactoryGirl.create(:miq_server, :zone => zone) }

it "check runs" do
allow(MiqServer).to receive(:my_server).and_return(my_server)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why allow rather than expect?

When I read rspec, my brain translates:
allow - This may or may not happen, I'm either not sure or can't find a better way to write this test.
expect - I expect this thing to happen (or not to happen)

describe "#check" do
let(:ems) { FactoryGirl.create(:ext_management_system) }
let(:zone) { FactoryGirl.create(:zone, :name => "api_zone", :ext_management_systems => [ems]) }
let(:my_server) { FactoryGirl.create(:miq_server, :zone => zone) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use EvmSpecHelper.local_miq_server and remove the let(:zone)

FactoryGirl.create(:service, :retired => true)
allow(MiqServer).to receive(:my_server).and_return(my_server)

expect_any_instance_of(LoadBalancer).to receive(:retirement_check).once.and_return(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these checks should expect a specific instance to receive the retirement_check. Also, the other instances should expect not to receive retirement_check, right?

ems_ids = MiqServer.my_server.zone.ext_management_system_ids
[LoadBalancer, OrchestrationStack, Vm, Service].each do |model|
table = model.arel_table
arel = table[:retires_on].not_eq(nil).or(table[:retired].not_eq(true))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use regular ActiveRecord .where and .where.not?

@d-m-u d-m-u force-pushed the merge-retirement-checks branch 3 times, most recently from 8cf5267 to a59fe9c Compare July 26, 2017 12:39
describe RetirementManager do
describe "#check" do
it "with retirement date, runs retirement checks" do
_, _server, zone = EvmSpecHelper.local_guid_miq_server_zone
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistence, use either _guid, _server, zone or _, _, zone


load_balancer = FactoryGirl.create(:load_balancer, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems)
FactoryGirl.create(:load_balancer, :retired => true)
orch_stack = FactoryGirl.create(:orchestration_stack, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you spell it out? 😄

bdunne and others added 2 commits July 26, 2017 11:02
Define the scope in the RetirementMixin
Create a scope for items not scheduled for retirement
Copy link
Member

@bdunne bdunne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

end
end

private_class_method def self.not_retired_with_ems(model, ems_ids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer we use the syntax of placing private_class_method on the line below the method with the method name passed as a symbol to be consistent with the rest of the project.

Example:

private_class_method :perf_target_to_interval_name

@miq-bot
Copy link
Member

miq-bot commented Jul 26, 2017

Checked commits d-m-u/manageiq@17412ff~...9e36f18 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
10 files checked, 1 offense detected

app/models/miq_schedule_worker/runner.rb

@gmcculloug gmcculloug merged commit 0a8c75e into ManageIQ:master Jul 26, 2017
@gmcculloug gmcculloug added this to the Sprint 66 Ending Aug 7, 2017 milestone Jul 26, 2017
@d-m-u d-m-u deleted the merge-retirement-checks branch July 26, 2017 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants