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

[V2V] Allow active InfraConversionJob to be throttled #19277

Conversation

ghost
Copy link

@ghost ghost commented Sep 9, 2019

The JobProxyDispatcher.dispatch is called only if JobProxyDispatcher.waiting? returns true. With existing implementation, it means that there is a Job in state waiting_to_start. However, the dispatch method calls the InfraConversionThrottler.apply_limits method that we need to run every 15 seconds as long as at least 1 InfraConversionJob is active, i.e. not in finished or waiting_to_start state.

This PR extends the check to include verification that active InfraConversionJob exists.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1690851

@ghost
Copy link
Author

ghost commented Sep 9, 2019

@miq-bot add-label transformation, bug, ivanchuk/yes
@miq-bot add-reviewer @agrare
@miq-bot add-reviewer @djberg96

@djberg96
Copy link
Contributor

I feel like there should be a way for other classes to hook into this and define their own method that the JobProxyDispatcher then uses, but it doesn't look like there's a way.

Hypothetically, I'm thinking of something like this:

def self.waiting?(job_class = Job)
  job_class.waiting_jobs?
end

And then each subclass of Job would define its own waiting_jobs? method.

Copy link
Contributor

@djberg96 djberg96 left a comment

Choose a reason for hiding this comment

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

Would like to see this refactored in general down the road, but this is good for now.

@@ -202,7 +202,7 @@ def assign_proxy_to_job(proxy, job)
end

def self.waiting?
Job.where(:state => 'waiting_to_start').exists?
Job.where(:state => 'waiting_to_start').exists? || InfraConversionJob.where.not(:state => ['finished', 'waiting_to_start']).exists?
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that this does two queries given how often this runs.

Instead of || can you use .or() something like this?

>> Job.where(:state => "waiting_to_start").or(Job.where(:type => "InfraConversionJob").where.not(:state => ["finished", "waiting_to_start"]))
  Job Load (0.9ms)  SELECT  "jobs".* FROM "jobs" WHERE ("jobs"."state" = $1 OR "jobs"."type" = $2 AND "jobs"."state" = 'running') LIMIT $3  [["state", "waiting_to_start"], ["type", "InfraConversionJob"], ["LIMIT", 11]]
  Job Inst Including Associations (0.0ms - 0rows)
=> #<ActiveRecord::Relation []

Copy link
Author

Choose a reason for hiding this comment

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

Changed the query and added specs. Thanks @agrare

@agrare
Copy link
Member

agrare commented Sep 11, 2019

I agree this isn't great but might be the best we can do for now. @fdupont-redhat in addition to the query change can you add a test covering this case?

@miq-bot
Copy link
Member

miq-bot commented Sep 11, 2019

Checked commits fabiendupont/manageiq@ea17a7b~...5d483da with ruby 2.4.6, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍪

@agrare agrare self-assigned this Sep 12, 2019
Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

👍 thanks @fdupont-redhat

agrare added a commit that referenced this pull request Sep 12, 2019
…unning_infraconversionjob

[V2V] Allow active InfraConversionJob to be throttled
@agrare agrare merged commit 5d483da into ManageIQ:master Sep 12, 2019
@agrare agrare added this to the Sprint 120 Ending Sep 16, 2019 milestone Sep 12, 2019
simaishi pushed a commit that referenced this pull request Nov 4, 2019
…unning_infraconversionjob

[V2V] Allow active InfraConversionJob to be throttled

(cherry picked from commit 1ec27c3)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1768518
@simaishi
Copy link
Contributor

simaishi commented Nov 4, 2019

Ivanchuk backport details:

$ git log -1
commit eb6b2d647937029237c88f448e42459b955fbc8c
Author: Adam Grare <agrare@redhat.com>
Date:   Thu Sep 12 08:21:56 2019 -0400

    Merge pull request #19277 from fdupont-redhat/v2v_allow_dispatching_running_infraconversionjob
    
    [V2V] Allow active InfraConversionJob to be throttled
    
    (cherry picked from commit 1ec27c37b21eb91013e20bfd437f608481c876d7)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1768518

@simaishi
Copy link
Contributor

simaishi commented Nov 5, 2019

@fdupont-redhat Travis is failing in ivanchuk branch. Are we missing some PR(s) in ivanchuk branch or do the specs added in this PR need to be modified in ivanchuk?

  1) JobProxyDispatcher.waiting? returns true if VmScan state is fake_state and InfraConversionJob state is restoring_vm_attributes
     Failure/Error:
       def self.create_job(process_type, options = {})
         klass = Object.const_get(process_type)
         ar_options = options.dup.delete_if { |k, _v| !Job.column_names.include?(k.to_s) }
         job = klass.new(ar_options)
         job.options = options
         job.initialize_attributes
         job.save
         job.create_miq_task(job.attributes_for_task)
         $log.info("Job created: #{job.attributes_log}")
         job.signal(:initializing)
     ArgumentError:
       wrong number of arguments (given 0, expected 1..2)
     # ./app/models/job.rb:19:in `create_job'
     # ./spec/models/job_proxy_dispatcher_spec.rb:22:in `block (3 levels) in <top (required)>'
     # ./spec/models/job_proxy_dispatcher_spec.rb:38:in `block (3 levels) in <top (required)>'

@djberg96
Copy link
Contributor

djberg96 commented Nov 5, 2019

#19461

@simaishi
Copy link
Contributor

simaishi commented Nov 5, 2019

Thanks Dan!

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